搜尋
首頁後端開發php教程php sphinx搜寻分词 windows7

php sphinx搜索分词 windows7

本地开发环境

1.下载coreseek词库,下载地址:http://www.coreseek.cn/products-install/install_on_windows/

coreseek3.2.14通用版php 5.4.3

?

2.下载好后,再环境变量里配置:

打开cmd#->CD c:\usr\local\coreseek-3.2.14-win32#->SET PATH=%CD%\bin;%PATH%

?

3.在项目录目下添加一个sphinx.conf文件(名字随自己定),关联查询product与product_type表

#MySQL数据源配置,详情请查看:http://www.coreseek.cn/products-install/mysql/#请先将var/test/documents.sql导入数据库,并配置好以下的MySQL用户密码数据库#源定义#sql_attr_uint#sql_attr_bool    #sql_attr_bigint     #sql_attr_timestamp   时间行#sql_attr_str2ordinal  字符串行#sql_attr_float   浮点型#sql_attr_multi  source mysql{    type                     = mysql    sql_host                 = 192.168.8.229    sql_user                 = feiyang    sql_pass                 = 123456    sql_db                   = feiyang_prd    sql_port                 = 3306    sql_query_pre            = SET NAMES utf8    sql_query                = SELECT SQL_NO_CACHE `product`.`ID` * CAST(1 AS SIGNED) + 0 AS `ID`, `product`.`MinPrice` AS `MinPrice`, `product`.`ProductTypeid` AS `product_type_id`, UNIX_TIMESTAMP(`product`.`ShowStartTime`) AS date_added , `product`.`WebTitle` AS `WebTitle`, `product`.`SubTitle` AS `SubTitle`, `product`.`AddressNames` AS `AddressNames`, `product_type`.`Title` AS `product_type_title` FROM `product` LEFT OUTER JOIN `product_type` ON `product_type`.`ID` = `product`.`ProductTypeid` where `product`.`ShowStatus` = 1 GROUP BY `product`.`ID` ORDER BY NULL         #sql_query第一列<span style="font-size: 1em; line-height: 1.5;">ID</span><span style="font-size: 1em; line-height: 1.5;">需为整数</span>         #WebTitle、SubTitle, ProductType表中title作为字符串/文本字段,被全文索引    sql_attr_uint            = sphinx_internal_id           #从SQL读取到的值必须为整数    sql_attr_uint            = class_crc    sql_attr_uint            = Sort    sql_attr_uint            = ShowStatus    sql_attr_float           = MinPrice    sql_attr_timestamp       = date_added #从SQL读取到的值必须为整数,作为时间属性    sql_attr_str2ordinal     = WebTitle_sort    sql_attr_str2ordinal     = SubTitle_sort    sql_attr_str2ordinal     = AddressNames_sort    sql_attr_str2ordinal     = StartCity_sort    sql_attr_str2ordinal     = ToTraffic_sort    sql_attr_str2ordinal     = BackTraffic_sort    sql_attr_str2ordinal     = Notes_sort        sql_query_info_pre       = SET NAMES utf8                                        #命令行查询时,设置正确的字符集    sql_query_info           = SELECT * FROM product WHERE `ID` = (($id - 0) / 1) #命令行查询时,从数据库读取原始数据信息}#index定义index mysql{    source            = mysql             #对应的source名称    path              = E:/projects/test_php/data/product #索引路径,请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...    docinfo           = extern    mlock             = 0    morphology        = none    min_word_len      = 1    ngram_len         = 1   #1为搜索中文    html_strip        = 0    #charset_dictpath = /usr/local/mmseg3/etc/ #BSD、Linux环境下设置,/符号结尾    charset_dictpath  = D:/coreseek/etc/                             #Windows环境下设置,/符号结尾,最好给出绝对路径,例如:C:/usr/local/coreseek/etc/...    charset_type      = utf-8    charset_table     = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F    ngram_chars      = U+3000..U+2FA1F}#全局index定义indexer{    mem_limit            = 128M}#searchd服务定义searchd{    listen              = 9312    read_timeout        = 5    max_children        = 30    max_matches         = 1000   # seamless_rotate    = 0  #windows下启动必须注释掉这行    preopen_indexes     = 0    unlink_old          = 1    pid_file            = ../log/searchd_mysql.pid  #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...    log                 = ../log/searchd_mysql.log        #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...    query_log           = ../log/query_mysql.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...}

?

4.生成索引,启动搜索

cmd下面运行下面代码:#-> indexer --config  config/sphinx.conf --all  #生成索引#-> searchd --config config/sphinx.conf  启动搜索

?

?

5.php里的配置

$cl = new SphinxClient ();$cl->SetServer ( '127.0.0.1', 9312);$cl->SetMatchMode ( SPH_MATCH_ANY );  //SPH_MATCH_ALL, 匹配所有查询词(默认模式); SPH_MATCH_ANY, 匹配查询词中的任意一个; SPH_MATCH_EXTENDED2, 支持特殊运算符查询  $cl->SetConnectTimeout ( 3 );$cl->SetArrayResult ( true );$weights = array('WebTitle'=>10, 'SubTitle'=>9, 'AddressNames'=>8, 'product_type_title'=>7);$cl->SetFieldWeights($weights);$cl->SetMaxQueryTime(10);   //最大搜索时间$res = $cl->Query ( $_GET['keyword'], "*" );  //"*"全部索引, 在conf文件中,会配置多个索引文件// 从名称为index的sphinx索引查询“电影票”$sp->SetGroupBy('item_id',SPH_GROUP_ATTR,'s_order desc');$sp->SetFilter('city_id','1');$sp->SetFilter('cat_id',array(1));$sp->SetLimit(0,10,1000);$sp->AddQuery('电影票','index');$sp->ResetFilters();//重置筛选条件$sp->SetGroupBy('item_id', SPH_GROUPBY_ATTR, 's_order desc');$sp->setFilter('city_id', '2');$sp->setFilter('cat_id', array(2));$sp->setLimits(0, 20, 1000);$sp->AddQuery('温泉', 'index');$sp->ResetFilters();// 重置筛选条件$sp->ResetGroupBy();//重置分组$results = $sp->RunQuries();

?

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
高流量網站的PHP性能調整高流量網站的PHP性能調整May 14, 2025 am 12:13 AM

TheSecretTokeEpingAphp-PowerEdwebSiterUnningSmoothlyShyunderHeavyLoadInVolvOLVOLVOLDEVERSALKEYSTRATICES:1)emplactopCodeCachingWithOpcachingWithOpCacheToreCescriptexecution Time,2)使用atabasequercachingCachingCachingWithRedataBasEndataBaseLeSendataBaseLoad,3)

PHP中的依賴注入:初學者的代碼示例PHP中的依賴注入:初學者的代碼示例May 14, 2025 am 12:08 AM

你應該關心DependencyInjection(DI),因為它能讓你的代碼更清晰、更易維護。 1)DI通過解耦類,使其更模塊化,2)提高了測試的便捷性和代碼的靈活性,3)使用DI容器可以管理複雜的依賴關係,但要注意性能影響和循環依賴問題,4)最佳實踐是依賴於抽象接口,實現鬆散耦合。

PHP性能:是否可以優化應用程序?PHP性能:是否可以優化應用程序?May 14, 2025 am 12:04 AM

是的,優化papplicationispossibleandessential.1)empartcachingingcachingusedapcutorediucedsatabaseload.2)優化的atabaseswithexing,高效Quereteries,and ConconnectionPooling.3)EnhanceCodeWithBuilt-unctions,避免使用,避免使用ingglobalalairaiables,並避免使用

PHP性能優化:最終指南PHP性能優化:最終指南May 14, 2025 am 12:02 AM

theKeyStrategiestosigantificallyBoostPhpaPplicationPerformenCeare:1)UseOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)優化AtabaseInteractionswithPreparedStateTementStatementStatementAndProperIndexing,3)配置

PHP依賴注入容器:快速啟動PHP依賴注入容器:快速啟動May 13, 2025 am 12:11 AM

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增強codemodocultion,可驗證性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

PHP中的依賴注入與服務定位器PHP中的依賴注入與服務定位器May 13, 2025 am 12:10 AM

選擇DependencyInjection(DI)用於大型應用,ServiceLocator適合小型項目或原型。 1)DI通過構造函數注入依賴,提高代碼的測試性和模塊化。 2)ServiceLocator通過中心註冊獲取服務,方便但可能導致代碼耦合度增加。

PHP性能優化策略。PHP性能優化策略。May 13, 2025 am 12:06 AM

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)啟用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替換loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

PHP電子郵件驗證:確保正確發送電子郵件PHP電子郵件驗證:確保正確發送電子郵件May 13, 2025 am 12:06 AM

phpemailvalidation invoLvesthreesteps:1)格式化進行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。