使用sphinx对结果进行排序

时间:2012-09-04 14:28:17

标签: php sphinx

我正在使用Sphinx 2.0.5。

sphinx.config:

index test
{
    type      = mysql
    sql_host  = host
    sql_user  = user
    sql_pass  = pass
    sql_db    = db

    sql_query = SELECT id, string \
                FROM table
}

sphinx.php:

$sphinx = new SphinxClient();

$sphinx->SetServer('localhost', 3312);
$sphinx->SetConnectTimeout(1);

$sphinx->SetLimits(0, 15);

$sphinx->SetMatchMode(SPH_MATCH_ALL);
$ret = $sphinx->query($query, 'index');

在“string”中有像

这样的行
"mouse, screen, keyboard, green house"
"green house, computer, keyboard, green house"

我想按顺序排序:
1-在行中找到的不同关键字的数量
2-在行中找到的关键字总数

例如,如果我搜索“温室”,我想首先得到“温室,电脑,键盘,温室”。但如果我搜索“温室屏幕”,首先应该是“鼠标,屏幕,键盘,温室”。

你知道我应该使用什么样的排序吗?

感谢。

1 个答案:

答案 0 :(得分:1)

就个人而言,我会将其放入phrase_boundary http://sphinxsearch.com/docs/current.html#conf-phrase-boundary

将短语分隔成单独的边界。现在可以使用primoxy来影响结果。

然后会写一些类似

的搜索
$cl->setMatchMode(SPH_MATCH_EXTENDED);
$cl->setRankingMode(SPH_RANK_WORDCOUNT);
$cl->Query('"green house"~10 | "green house" | (green house)',$index);

可以准确选择您喜欢的因素,以影响结果。使用3个(或更多!)单词查询变得更复杂,因为必须将所有组合扩展到查询中。

(我不确定这是否会产生您的确切规格 - 说实话它们并不清楚 - 但这是针对此类情况的一般解决方案 - 匹配标签列表)

相关问题