首先以下是配置文件:
source cv{
type=mysql
sql_host=localhost
sql_user=root
sql_pass=passwod
sql_db=database
sql_query_pre= set names utf8
sql_query=\
select id, title, introtext,unix_timestamp(created) as addtime \
from jos_content
sql_attr_timestamp=addtime
sql_ranged_throttle=0
}
index cv{
source=cv
path=/usr/local/sphinx/var/data/joomlainx
docinfo=extern
mlock=0
stopwords=
min_prefix_len=0
min_infix_len=0
min_word_len=2
charset_type=utf-8
charset_table=u+ff10..u+ff19->0..9, 0..9, u+ff41..u+ff5a->a..z, u+ff21..u+ff3a->a..z,\
a..z->a..z, a..z, u+0149, u+017f, u+0138, u+00df, u+00ff, u+00c0..u+00d6->u+00e0..u+00f6,\
u+00e0..u+00f6, u+00d8..u+00de->u+00f8..u+00fe, u+00f8..u+00fe, u+0100->u+0101, u+0101,\
u+0102->u+0103, u+0103, u+0104->u+0105, u+0105, u+0106->u+0107, u+0107, u+0108->u+0109,\
u+0109, u+010a->u+010b, u+010b, u+010c->u+010d, u+010d, u+010e->u+010f, u+010f,\
u+0110->u+0111, u+0111, u+0112->u+0113, u+0113, u+0114->u+0115, u+0115, u+0116->u+0117,\
u+0117, u+0118->u+0119, u+0119, u+011a->u+011b, u+011b, u+011c->u+011d, u+011d,\
u+011e->u+011f, u+011f, u+0130->u+0131, u+0131, u+0132->u+0133, u+0133, u+0134->u+0135,\
u+0135, u+0136->u+0137, u+0137, u+0139->u+013a, u+013a, u+013b->u+013c, u+013c,\
u+013d->u+013e, u+013e, u+013f->u+0140, u+0140, u+0141->u+0142, u+0142, u+0143->u+0144,\
u+0144, u+0145->u+0146, u+0146, u+0147->u+0148, u+0148, u+014a->u+014b, u+014b,\
u+014c->u+014d, u+014d, u+014e->u+014f, u+014f, u+0150->u+0151, u+0151, u+0152->u+0153,\
u+0153, u+0154->u+0155, u+0155, u+0156->u+0157, u+0157, u+0158->u+0159, u+0159,\
u+015a->u+015b, u+015b, u+015c->u+015d, u+015d, u+015e->u+015f, u+015f, u+0160->u+0161,\
u+0161, u+0162->u+0163, u+0163, u+0164->u+0165, u+0165, u+0166->u+0167, u+0167,\
u+0168->u+0169, u+0169, u+016a->u+016b, u+016b, u+016c->u+016d, u+016d, u+016e->u+016f,\
u+016f, u+0170->u+0171, u+0171, u+0172->u+0173, u+0173, u+0174->u+0175, u+0175,\
u+0176->u+0177, u+0177, u+0178->u+00ff, u+00ff, u+0179->u+017a, u+017a, u+017b->u+017c,\
u+017c, u+017d->u+017e, u+017e, u+0410..u+042f->u+0430..u+044f, u+0430..u+044f,\
u+05d0..u+05ea, u+0531..u+0556->u+0561..u+0586, u+0561..u+0587, u+0621..u+063a, u+01b9,\
u+01bf, u+0640..u+064a, u+0660..u+0669, u+066e, u+066f, u+0671..u+06d3, u+06f0..u+06ff,\
u+0904..u+0939, u+0958..u+095f, u+0960..u+0963, u+0966..u+096f, u+097b..u+097f,\
u+0985..u+09b9, u+09ce, u+09dc..u+09e3, u+09e6..u+09ef, u+0a05..u+0a39, u+0a59..u+0a5e,\
u+0a66..u+0a6f, u+0a85..u+0ab9, u+0ae0..u+0ae3, u+0ae6..u+0aef, u+0b05..u+0b39,\
u+0b5c..u+0b61, u+0b66..u+0b6f, u+0b71, u+0b85..u+0bb9, u+0be6..u+0bf2, u+0c05..u+0c39,\
u+0c66..u+0c6f, u+0c85..u+0cb9, u+0cde..u+0ce3, u+0ce6..u+0cef, u+0d05..u+0d39, u+0d60,\
u+0d61, u+0d66..u+0d6f, u+0d85..u+0dc6, u+1900..u+1938, u+1946..u+194f, u+a800..u+a805,\
u+a807..u+a822, u+0386->u+03b1, u+03ac->u+03b1, u+0388->u+03b5, u+03ad->u+03b5,\
u+0389->u+03b7, u+03ae->u+03b7, u+038a->u+03b9, u+0390->u+03b9, u+03aa->u+03b9,\
u+03af->u+03b9, u+03ca->u+03b9, u+038c->u+03bf, u+03cc->u+03bf, u+038e->u+03c5,\
u+03ab->u+03c5, u+03b0->u+03c5, u+03cb->u+03c5, u+03cd->u+03c5, u+038f->u+03c9,\
u+03ce->u+03c9, u+03c2->u+03c3, u+0391..u+03a1->u+03b1..u+03c1,\
u+03a3..u+03a9->u+03c3..u+03c9, u+03b1..u+03c1, u+03c3..u+03c9, u+0e01..u+0e2e,\
u+0e30..u+0e3a, u+0e40..u+0e45, u+0e47, u+0e50..u+0e59, u+a000..u+a48f, u+4e00..u+9fbf,\
u+3400..u+4dbf, u+20000..u+2a6df, u+f900..u+faff, u+2f800..u+2fa1f, u+2e80..u+2eff,\
u+2f00..u+2fdf, u+3100..u+312f, u+31a0..u+31bf, u+3040..u+309f, u+30a0..u+30ff,\
u+31f0..u+31ff, u+ac00..u+d7af, u+1100..u+11ff, u+3130..u+318f, u+a000..u+a48f,\
u+a490..u+a4cf
ngram_len=1
ngram_chars=u+4e00..u+9fbf, u+3400..u+4dbf, u+20000..u+2a6df, u+f900..u+faff,\
u+2f800..u+2fa1f, u+2e80..u+2eff, u+2f00..u+2fdf, u+3100..u+312f, u+31a0..u+31bf,\
u+3040..u+309f, u+30a0..u+30ff, u+31f0..u+31ff, u+ac00..u+d7af, u+1100..u+11ff,\
u+3130..u+318f, u+a000..u+a48f, u+a490..u+a4cf
}
indexer{
mem_limit=32m
}
searchd{
port=3312
log=/usr/local/sphinx/var/log/searchd.log
query_log=/usr/local/sphinx/var/log/query.log
read_timeout=5
max_children=30
pid_file=/usr/local/sphinx/var/log/searchd.pid
max_matches=1000
seamless_rotate=1
}
你可以参考一下,使用这个配置文件需要修改用户,密码保存目录等,来符合你自己mysql的要求。sphinx的官网的配置有一些问题,最关键的就是 morphology=none 这段在中文情况下不能使用,否则会导致无法启动searchd服务。
配置完成后,就可以进行索引:
/usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf --all
然后可以启动searchd
/usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf
我们来用php api进行搜索,将安装目录的api文件都 copy 到 网站的根目录下,最重要的是sphinxapi.php
新建一个test.php文件,代码如下:
'', 'after_match'=>'', 'chunk_separator'=>' ... ', 'limit'=>60, 'around'=>3); $ranker=sph_rank_proximity_bm25;$cl=new sphinxclient(); $cl->setserver($host,$port); $cl->setweights(array(100,1)); $cl->setmatchmode($mode); if(count($filtervals))$cl->setfilter($filter,$filtervals); if($groupby)$cl->setgroupby($groupby,sph_groupby_attr,$groupsort); if($sortby)$cl->setsortmode(sph_sort_extended,$sortby); if($sortexpr)$cl->setsortmode(sph_sort_expr,$sortexpr); if($distinct)$cl->setgroupdistinct($distinct); if($limit)$cl->setlimits(0,$limit,($limit>1000)?$limit:1000); $cl->setrankingmode($ranker); $cl->setarrayresult(true); $res=$cl->query($q,$index); ?>
这是一个最简单的测试实例,注意保存的charset是 utf-8 ,无bom,现在可以通过 http://www.phpernote.com/test.php 来测试,结果会返回一个数组,sphinx不会返回title和content等内容,因此要根据id在mysql检索以显示文章标题和正文。
目前 sphinx 生成的索引文件不能大于2g
您可能感兴趣的文章sphinx在windows下安装使用[支持中文全文检索]php.ini 中文英文对照详细配置手册php判断上传文件类型最安全,最真实的解决办法php smarty中文截取插件开发示例thinkphp截取中文字符串的方法在php中分别使用curl的post提交数据的方法和get获取网页数据的方法总结php如何将html中的br换行符转换为文本输入中的换行符php中关于抽象(abstract)类和抽象方法的问题解析
http://www.bkjia.com/phpjc/764164.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/764164.htmltecharticle首先以下是配置文件: source cv{ type=mysql sql_host=localhost sql_user=root sql_pass=passwod sql_db=database sql_query_pre= set names utf8 sql_query=\ select id, title, i...