sphinx分域搜索【不】需要在conf文件中使用sql_field_string

时间:2014-03-15 15:21:17   收藏:0   阅读:507

请看sql_field_string的文档说明:

bubuko.com,布布扣
    # combined field plus attribute declaration (from a single column)
    # stores column as an attribute, but also indexes it as a full-text field
    #
    # sql_field_string    = author
bubuko.com,布布扣

我们不需要attribute属性,不用管。只要在sql_query中选出相应的column就行了,就可以在php中使用extended_query_mode来进行query了,相应的域名就是列的名字。请看如下的conf文件:

bubuko.com,布布扣
    sql_query        =         SELECT bid, review_count, stars, name, full_address, categories         FROM busi_info
    
    sql_attr_uint   = review_count
    sql_attr_uint    = stars
bubuko.com,布布扣

在php中搜索的时候,php文件如下:

bubuko.com,布布扣
<?php
ini_set(‘memory_limit‘, ‘-1‘);
ini_set(‘max_execution_time‘, ‘100‘);
include ‘sphinxapi.php‘;

$sc= new SphinxClient();
$sc->setServer(‘localhost‘, 9312);
$sc->setRankingMode(SPH_RANK_NONE);
$sc->SetLimits(0,73180000,1000000);

$sc->SetMatchMode(SPH_MATCH_EXTENDED2);
$res = $sc->query(‘@categories Travel‘, ‘idx_busi‘);
$ids    = array_keys($res[‘matches‘]);
print_r($ids);

?>
bubuko.com,布布扣

这样就行啦!只要用“@域名 query”这种格式就好了。

sphinx分域搜索【不】需要在conf文件中使用sql_field_string,布布扣,bubuko.com

原文:http://www.cnblogs.com/miaoz/p/3601631.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!