Home  >  Article  >  Backend Development  >  【求助】php + sphinx 配置后 无法使用!返回空!sphinx.conf是否配置正确

【求助】php + sphinx 配置后 无法使用!返回空!sphinx.conf是否配置正确

WBOY
WBOYOriginal
2016-06-23 14:21:36891browse

本帖最后由 default7 于 2013-09-09 12:48:15 编辑

sphinx 配置

使用sphinx,也不知道安装是否成功。但是结果是PHP程序搜索不到任何内容。
1)sphinx安装目录:F:\sphinx\,配置文件:F:\sphinx\sphinx.conf
2)数据库:tbdb.ratedat,sphinx来自  sphinx-for-chinese-2.1.0-dev-r3361-win32.zip 
3)Apache/2.4.4 (Win32) PHP/5.4.16,服务器版本: 5.6.12-log - MySQL Community Server (GPL)


F:\sphinx\sphinx.conf 全部内容
source srcDB{	type			= mysql	sql_host		= localhost	sql_user		= root	sql_pass		= zbphp.com~$	sql_db			= tbdb	sql_port		= 3306	sql_query_pre   = SET NAMES utf8	#sql_query_pre   = SET SESSION query_cache_type=OFF #很奇怪,加这一句会报错!	sql_query		= \	    SELECT trade_id,trade_time,goods_title,goods_price,uid_buy,uid_sell \	    FROM ratedat	sql_attr_bigint		= trade_id	sql_attr_bigint		= uid_buy	sql_attr_bigint		= uid_sell	sql_attr_timestamp	= trade_time	sql_query_info		= SELECT * FROM ratedat WHERE trade_id=$id}index goods_title{    source  =   srcDB    path    =   F:/sphinx/data/ratedat.goods_title    charset_type    =   utf-8    html_strip      = 1}indexer{	mem_limit		= 128M}searchd{	listen			= 9312	listen			= 9306:mysql41	log			= F:/sphinx/log/searchd.log	query_log		= F:/sphinx/log/query.log	read_timeout		= 5	max_children		= 30	pid_file		= F:/sphinx/log/searchd.pid	max_matches		= 1000	seamless_rotate		= 1	preopen_indexes		= 1	unlink_old		= 1	workers			= threads # for RT to work	binlog_path		= F:/sphinx/data}



安装文件 F:/sphinx/Install.bat
net stop SphinxSearchsc delete SphinxSearchdel /s/q %cd%\log\*.*del /s/q %cd%\data\*.*%cd%\bin\searchd --install --config %cd%\sphinx.conf --servicename SphinxSearch%cd%\bin\indexer -c %cd%\sphinx.conf --allnet start SphinxSearchpause



bat脚本安装过程提示:
F:\sphinx>net stop SphinxSearchSphinxSearch 服务正在停止..SphinxSearch 服务已成功停止。F:\sphinx>sc delete SphinxSearch[SC] DeleteService SUCCESSF:\sphinx>del /s/q F:\sphinx\log\*.*删除文件 - F:\sphinx\log\query.log删除文件 - F:\sphinx\log\searchd.logF:\sphinx>del /s/q F:\sphinx\data\*.*删除文件 - F:\sphinx\data\binlog.001删除文件 - F:\sphinx\data\binlog.meta删除文件 - F:\sphinx\data\ratedat.goods_title.spa删除文件 - F:\sphinx\data\ratedat.goods_title.spd删除文件 - F:\sphinx\data\ratedat.goods_title.spe删除文件 - F:\sphinx\data\ratedat.goods_title.sph删除文件 - F:\sphinx\data\ratedat.goods_title.spi删除文件 - F:\sphinx\data\ratedat.goods_title.spk删除文件 - F:\sphinx\data\ratedat.goods_title.spm删除文件 - F:\sphinx\data\ratedat.goods_title.spp删除文件 - F:\sphinx\data\ratedat.goods_title.spsF:\sphinx>F:\sphinx\bin\searchd --install --config F:\sphinx\sphinx.conf --servicename SphinxSearchsphinx-for-chinese 2.1.0-dev (r3361)Copyright (c) 2008-2012, sphinx-search.comInstalling service...Service 'SphinxSearch' installed succesfully.F:\sphinx>F:\sphinx\bin\indexer -c F:\sphinx\sphinx.conf --allsphinx-for-chinese 2.1.0-dev (r3361)Copyright (c) 2008-2012, sphinx-search.comusing config file 'F:\sphinx\sphinx.conf'...indexing index 'goods_title'...WARNING: attribute 'trade_id' not found - IGNORINGWARNING: source srcDB: skipped 10378355 document(s) with DOCID_MAX idscollected 176464 docs, 12.1 MBsorted 0.7 Mhits, 100.0% donetotal 176464 docs, 12144715 bytestotal 37.745 sec, 321754 bytes/sec, 4675.12 docs/sectotal 2 reads, 0.007 sec, 4604.6 kb/call avg, 3.9 msec/call avgtotal 19 writes, 0.360 sec, 950.7 kb/call avg, 18.9 msec/call avgF:\sphinx>net start SphinxSearchSphinxSearch 服务正在启动 .SphinxSearch 服务已经启动成功。F:\sphinx>pause请按任意键继续. . .




PHP文件内容:
<?phprequire ( "sphinxapi.php" );$s = new SphinxClient();$s->SetServer('localhost');$rst = $s->Query('电脑');print_r($s);print_r($rst);/*SphinxClient Object(    [_host] => localhost    [_port] => 9312    [_offset] => 0    [_limit] => 20    [_mode] => 0    [_weights] => Array        (        )    [_sort] => 0    [_sortby] =>     [_min_id] => 0    [_max_id] => 0    [_filters] => Array        (        )    [_groupby] =>     [_groupfunc] => 0    [_groupsort] => @group desc    [_groupdistinct] =>     [_maxmatches] => 1000    [_cutoff] => 0    [_retrycount] => 0    [_retrydelay] => 0    [_anchor] => Array        (        )    [_indexweights] => Array        (        )    [_ranker] => 0    [_rankexpr] =>     [_maxquerytime] => 0    [_fieldweights] => Array        (        )    [_overrides] => Array        (        )    [_select] => *    [_error] =>     [_warning] =>     [_connerror] =>     [_reqs] => Array        (        )    [_mbenc] =>     [_arrayresult] =>     [_timeout] => 0    [_path] =>     [_socket] => )Array(    [error] =>     [warning] =>     [status] => 0    [fields] => Array        (            [0] => goods_title            [1] => goods_price        )    [attrs] => Array        (            [trade_time] => 2            [uid_buy] => 6            [uid_sell] => 6        )    [total] => 0    [total_found] => 0    [time] => 0.000)*/


sphinx日志内容:F:\sphinx\log\query.log
[Mon Sep  9 12:40:43.311 2013] 0.035 sec [all/0/rel 0 (0,20)] [*] 电脑[Mon Sep  9 12:40:48.751 2013] 0.000 sec [all/0/rel 0 (0,20)] [*] 电脑





回复讨论(解决方案)

现在,看起来我应该终于安装把sphinx安装成功了。
不过我发现如果我把下面这几个的注释去掉,就没有任何结果。为什么?
有几个疑问,搜索的关键字,到底是针对的那几个字段?
sphinx似乎不能指定某个字段内的搜索? ?如何指定在某几个字段内搜索?

F:\sphinx\sphinx.conf

source srcDB{	type			= mysql	sql_host		= localhost	sql_user		= root	sql_pass		= zbphp.com~	sql_db			= tbdb	sql_port		= 3306	sql_query_pre   = SET NAMES utf8	sql_query		= \	    SELECT trade_id,trade_time,goods_title,goods_price,uid_buy,uid_sell,rate_txt \	    FROM ratedat	#sql_attr_uint		= trade_id 	#sql_attr_timestamp  = trade_time	#sql_attr_float      = goods_price	#sql_attr_string     = rate_txt	sql_attr_uint		= uid_buy	sql_attr_string     = goods_title	sql_query_info		= SELECT * FROM ratedat WHERE trade_id=$id}







 SELECT trade_id,trade_time,goods_title,goods_price,uid_buy,uid_sell,rate_txt \
        FROM ratedat

很明显 已经指定字段了啊,他会搜索trade_id,trade_time,goods_title,goods_price,uid_buy,uid_sell,rate_txt
这几个字段

你把哪几个注释掉了?没明白

你把哪几个注释掉了?没明白

#1楼代码中的这几个注释后可以查询到:

    #sql_attr_uint        = trade_id     #sql_attr_timestamp  = trade_time    #sql_attr_float      = goods_price    #sql_attr_string     = rate_txt


你把哪几个注释掉了?没明白

#1楼代码中的这几个注释后可以查询到:

    #sql_attr_uint        = trade_id     #sql_attr_timestamp  = trade_time    #sql_attr_float      = goods_price    #sql_attr_string     = rate_txt


sphinx 支持的属性如下:
无符号整数(1-32位宽)
UNIX 时间戳(timestamps)
浮点值(32位,IEEE 754单精度)
字符串叙述 (尤其是计算出的整数值);
多值属性 MVA (multi-value attributes)

#sql_attr_uint        = trade_id 
#sql_attr_string     = rate_txt
没有这种设置啊,会报错的



你把哪几个注释掉了?没明白

#1楼代码中的这几个注释后可以查询到:

    #sql_attr_uint        = trade_id     #sql_attr_timestamp  = trade_time    #sql_attr_float      = goods_price    #sql_attr_string     = rate_txt


sphinx 支持的属性如下:
无符号整数(1-32位宽)
UNIX 时间戳(timestamps)
浮点值(32位,IEEE 754单精度)
字符串叙述 (尤其是计算出的整数值);
多值属性 MVA (multi-value attributes)

#sql_attr_uint        = trade_id 
#sql_attr_string     = rate_txt
没有这种设置啊,会报错的

我发现 这里放在soure部分的 sql_attr_uint,sql_attr_string 就是会显示到搜索结果的$rst[matches][xxxx][attr]中,如果在souce中没有定义这些字段,那么搜索返回数据就没有附带这些字段内容。我写进去是想得到这些数据,但是发现写了之后,就运行出错或者无任何返回值。









 SELECT trade_id,trade_time,goods_title,goods_price,uid_buy,uid_sell,rate_txt \
        FROM ratedat

很明显 已经指定字段了啊,他会搜索trade_id,trade_time,goods_title,goods_price,uid_buy,uid_sell,rate_txt
这几个字段

但是假如我输入的是文字字符串的关键字,那么他岂不同样会检索 trade_id,trade_time,uid_buy,uid_sell的内容了?我看到网上有这样的写法,指定某个字段的搜索,代码如下:

<?php    require ( 'sphinxapi.php' );    $s = new SphinxClient();    $s->setMatchMode(SPH_MATCH_EXTENDED2);    $rst = $s->Query('@goods_title '.$kw);    print_r($rst);    print_r($s);    exit();/*SphinxClient Object(    [_host] => localhost    [_port] => 9312    [_offset] => 0    [_limit] => 20    [_mode] => 6    [_weights] => Array        (        )    [_sort] => 0    [_sortby] =>     [_min_id] => 0    [_max_id] => 0    [_filters] => Array        (        )    [_groupby] =>     [_groupfunc] => 0    [_groupsort] => @group desc    [_groupdistinct] =>     [_maxmatches] => 1000    [_cutoff] => 0    [_retrycount] => 0    [_retrydelay] => 0    [_anchor] => Array        (        )    [_indexweights] => Array        (        )    [_ranker] => 0    [_rankexpr] =>     [_maxquerytime] => 0    [_fieldweights] => Array        (        )    [_overrides] => Array        (        )    [_select] => *    [_error] => query error: no field 'goods_title' found in schema    [_warning] =>     [_connerror] =>     [_reqs] => Array        (        )    [_mbenc] =>     [_arrayresult] =>     [_timeout] => 0    [_path] =>     [_socket] => )*/


提示:    [_error] => query error: no field 'goods_title' found in schema
但是假如我 去掉 “ @goods_title”可以搜索到结果,sphinx如何才可以指定在某个文字数据串中搜索结果

现在我整个配置文件的内容如下,文件 f:/sphinx/sphinx.conf

source DB{	type			= mysql	sql_host		= localhost	sql_user		= root	sql_pass		= zbphp.com~$	sql_db			= zbphp_com	sql_port		= 3306	sql_query_pre   = SET NAMES utf8}source Buyer : DB{    sql_query = \        SELECT trade_id,trade_time,goods_price,goods_title,uid_buy,uid_sell,rate_txt \        FROM ratedat    sql_attr_uint       = uid_buy	sql_attr_string     = goods_title	sql_attr_float      = goods_price	sql_attr_timestamp  = trade_time    sql_query_info		= SELECT * FROM ratedat WHERE trade_id=$id}index buyerlist{    type    =   plain    source  =   Buyer    path    =   F:/sphinx/data/buyerlist    docinfo         = extern    mlock           = 0    morphology      = none    stopwords       =    min_word_len    = 1    charset_type    = utf-8    html_strip      = 1    min_prefix_len  = 0    min_infix_len   = 1    ngram_len       = 1    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_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}index rt{    type = rt    path = f:/sphinx/data/rt    rt_field = goods_title    rt_field = rate_txt    rt_attr_uint = uid_buy}indexer{	mem_limit		= 128M}searchd{	listen			= 9312	listen			= 9306:mysql41	log             = F:/sphinx/log/searchd.log	query_log		= F:/sphinx/log/query.log	read_timeout    = 5	max_children    = 30	pid_file		= F:/sphinx/log/searchd.pid	max_matches		= 1000	seamless_rotate = 1	preopen_indexes = 1	unlink_old		= 1	workers			= threads	binlog_path		= F:/sphinx/data}




1) 里面的 index rt {} 我不知道怎么来用,不是 type = mysql吗,为什么index rt 这个的type=rt ? 如果不加 index rt这一段 也是可以安装成功的
2) 这个sphinx.conf安装是安装成功的,但是如上一楼#6那样指定在某个字段中进行搜索“@goods_title $kw”返回的报错error是  query error: no field 'goods_title' found in schema。
3)如何才可以实现交表查询?我想得到的是这样的数据,三个表 ratedat,rate_buyer,userdat:

SELECT a.*,b.*,c.nick FROM rate_buyer a LEFT JOIN ratedat b ON a.uid=b.uid_buyLEFT JOIN userdat c ON a.uid=c.uid WHERE 1GROUP BY a.uid ORDER BY b.costsum DESC LIMIT $startnum , $perpage ;


我在sphinx.conf中按照这样来写,安装成功了,但是每次只能得到一个结果:
source Buyer : DB{    sql_query = \        SELECT a.uid,a.costsum,a.costmax,a.costmin,a.costavg,a.costcount \        ,b.goods_price,b.goods_title,b.trade_id,b.trade_time,b.uid_buy \        ,c.nick \        FROM rate_buyer a \        LEFT JOIN ratedat b ON a.uid=b.uid_buy \        LEFT JOIN userdat c ON a.uid=c.uid \        GROUP BY a.uid \        ORDER BY a.costsum DESC \    sql_attr_uint       = uid_buy	sql_attr_string     = goods_title	sql_attr_float      = goods_price	sql_attr_timestamp  = trade_time    sql_query_info		= SELECT * FROM ratedat WHERE trade_id=$id}



安装过程bat提示记录:
SphinxSearch 服务正在停止..SphinxSearch 服务已成功停止。[SC] DeleteService SUCCESS删除文件 - F:\sphinx\data\binlog.meta删除文件 - F:\sphinx\data\rt.kill删除文件 - F:\sphinx\data\rt.lock删除文件 - F:\sphinx\data\rt.meta删除文件 - F:\sphinx\data\rt.ramsphinx-for-chinese 2.1.0-dev (r3361)Copyright (c) 2008-2012, sphinx-search.comInstalling service...Service 'SphinxSearch' installed succesfully.sphinx-for-chinese 2.1.0-dev (r3361)Copyright (c) 2008-2012, sphinx-search.comusing config file 'F:\sphinx\sphinx.conf'...indexing index 'buyerlist'...collected 136 docs, 0.0 MBsorted 0.0 Mhits, 100.0% donetotal 136 docs, 6577 bytestotal 0.305 sec, 21558 bytes/sec, 445.78 docs/secskipping non-plain index 'rt'...total 2 reads, 0.000 sec, 145.0 kb/call avg, 0.0 msec/call avgtotal 10 writes, 0.028 sec, 61.5 kb/call avg, 2.8 msec/call avgsphinx-for-chinese 2.1.0-dev (r3361)Copyright (c) 2008-2012, sphinx-search.comusing config file 'F:\sphinx\sphinx.conf'...index 'buyerlist': query 'iPhone ': returned 0 matches of 0 total in 0.000 secwords:1. 'iphone': 0 documents, 0 hitsindex 'rt': search error: failed to open f:/sphinx/data/rt.sph: No such file ordirectory.SphinxSearch 服务正在启动 .SphinxSearch 服务已经启动成功。请按任意键继续. . .


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn