笨小迪 2016-12-19 09:09 采纳率: 33.3%
浏览 1243

sphinx搜索结果排序问题

输入:测试

分词:(测试)

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;

?>

以上是代码,搜索结果不应该是“测试”这个排在前面吗?还是说需要设置什么参数之类的,求大神帮忙,感谢!

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2016-12-19 16:57
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条