您好,欢迎访问一九零五行业门户网

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第一列id需为整数 #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();
?
其它类似信息

推荐信息