输入:测试
分词:(测试)
Array
(
[error] =>
[warning] =>
[status] => 0
[fields] => Array
(
[0] => menu_id
[1] => menu_name
[2] => goods_number
[3] => goods_name
[4] => goods_desc
[5] => goods_price
[6] => goods_sale_price
[7] => goods_hot
[8] => inventory_num
[9] => goods_status
[10] => goods_unit
[11] => goods_volume
[12] => goods_volume_num
[13] => brand
[14] => manufacturer
[15] => sale_company
)
[attrs] => Array
(
[gid] => 1
[menu_name] => 7
[goods_name] => 7
)
[matches] => Array
(
[0] => Array
(
[id] => 2
[weight] => 5274
[attrs] => Array
(
[gid] => 2
[menu_name] => 测试
[goods_name] => 阿斯蒂芬测阿斯蒂芬试阿沙文
)
)
[1] => Array
(
[id] => 1
[weight] => 4302
[attrs] => Array
(
[gid] => 1
[menu_name] => 测试
[goods_name] => 测试
)
)
)
[total] => 2
[total_found] => 2
[time] => 0.13
[words] => Array
(
[测] => Array
(
[docs] => 2
[hits] => 5
)
[试] => Array
(
[docs] => 2
[hits] => 5
)
)
)
以上是sphinx搜索后的结果。
<?php
header("Content-type: text/html; charset=utf-8");
$b_time = microtime(true);
$key = "测试";
$index = "TGoods";
//========================================分词
$so = scws_new();
$so->set_charset('utf-8');
//默认词库
$so->add_dict(ini_get('scws.default.fpath') . '/dict.utf8.xdb');
//自定义词库
// $so->add_dict('./dd.txt',SCWS_XDICT_TXT);
//默认规则
$so->set_rule(ini_get('scws.default.fpath') . '/rules.utf8.ini');
//设定分词返回结果时是否去除一些特殊的标点符号
$so->set_ignore(true);
//设定分词返回结果时是否复式分割,如“中国人”返回“中国+人+中国人”三个词。
// 按位异或的 1 | 2 | 4 | 8 分别表示: 短词 | 二元 | 主要单字 | 所有单字
//1,2,4,8 分别对应常量 SCWS_MULTI_SHORT SCWS_MULTI_DUALITY SCWS_MULTI_ZMAIN SCWS_MULTI_ZALL
$so->set_multi(false);
//设定是否将闲散文字自动以二字分词法聚合
$so->set_duality(false);
//设定搜索词
$so->send_text($key);
$words_array = $so->get_result();
$words = "";
foreach($words_array as $v)
{
$words = $words.'|('.$v['word'].')';
}
//加入全词
#$words = '('.$key.')'.$words;
$words = trim($words,'|');
$so->close();
echo '<p>输入:'.$key.'</p>'."\r\n";
echo '<p>分词:'.$words.'</p>'."\r\n";
//========================================搜索
$sc = new SphinxClient();
$sc->SetServer('127.0.0.1',9312);
#$sc->SetMatchMode(SPH_MATCH_ALL);
$sc->SetMatchMode(SPH_MATCH_EXTENDED);
$sc->SetArrayResult(TRUE);
$res = $sc->Query($words,$index);
print_r($res);
$e_time = microtime(true);
$time = $e_time - $b_time;
exit;
?>
以上是代码,搜索结果不应该是“测试”这个排在前面吗?还是说需要设置什么参数之类的,求大神帮忙,感谢!