Sphinx忽略排名,始终按相同顺序排序 [英] Sphinx ignores ranking, always sorts in the same order

查看:158
本文介绍了Sphinx忽略排名,始终按相同顺序排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在schools上有狮身人面像索引,当我执行查询时,我总是以相同的顺序收到相同的结果.我尝试了排名,排序和匹配的所有可想象的组合,并且总是得到相同的排序.

I have sphinx index on schools, and when I do a query I always receive the same results, in the same order. I've tried every imaginable combination of ranking, sorting, and matching, and always get the same sorting.

下面是我得到的不良数据的示例:

A sample of the bad data I'm getting is below:

"albany high"

Albany Junior High School | Auckland, NZ | 2001 (shouldn't be first)
Albany High School        | Albany, NY   | 2001
South Albany High School  | Albany, OR   | 2001
Albany High School        | Albany, CA   | 1001 (shouldn't be last)

如您所见,排名最高的学校不在名为"Albany"的城市中,应该排名较低,而排名最低的"Albany High School"则应该排名更高.此问题已在许多搜索字词中重复出现.

As you can see, the highest-ranked school is not in a city named "Albany", and should be lower, while the lowest-ranked "Albany High School" should be ranked higher than it is. This problem is replicated across many search terms.

Sphinx索引如下:

The Sphinx index looks like this:

source schools : root
{
    sql_query = \
        SELECT schools.id, schools.name, schools.state, schools.country, schools.city, \
        (select COUNT(*) from user2school WHERE school_id = schools.id) as user_count \
        FROM schools

    sql_attr_uint       = user_count
}

index schools
{
    source                  = schools
    path                    = /var/db/sphinx/data/schools
    min_infix_len           = 3
    infix_fields            = name
}

生成结果的代码如下:

$sphinx->SetMatchMode(SPH_MATCH_EXTENDED);
$sphinx->SetRankingMode(SPH_RANK_WORDCOUNT);
$sphinx->SetSortMode(SPH_SORT_RELEVANCE);

$sphinx->SetFieldWeights(array(
    'id' => 0,
    'name' => 1000,
    'city' => 0,
    'state' => 0,
    'user_count' => 0
));

如何让Sphinx识别我的自定义砝码?我尝试过的每种组合似乎都失败了.

How can I get Sphinx to recognize my custom weights? Every combination I've tried seems to fail.

这是另一个具有相同顺序但设置完全不同的示例.我在这里打开的唯一选项是:

Here is another example with the same ordering, but totally different settings. The only option I have turned on here is:

$sphinx->SetRankingMode(SPH_RANK_SPH04);

结果:

"albany high"

Albany Junior High School | Auckland, NZ | 3 (still shouldn't be first)
Albany High School        | Albany, NY   | 3
South Albany High School  | Albany, OR   | 2
Albany High School        | Albany, CA   | 1 (still shouldn't be last)

如您所见,顺序是相同的.我尝试过的排名,排序和权重的每种组合都是相同的.有什么我可以尝试调试的问题吗?

As you can see, the ordering is identical. It is identical in every combination of ranking, sorting, and weighting I have tried. Is there anything I can try to debug this problem?

推荐答案

在您的应用程序中可能是逻辑错误. Sphinx为您提供了ID列表,然后您将使用这些ID从原始数据库检索数据.也许您没有将这些行正确排序.

Perhaps its a logic error in your application. Sphinx gives you a list of IDs, which you would then use to retreive data from the original database. Maybe you arent sorting those rows right.

我只是尝试将您的数据插入测试RT索引(包括字符串属性,因此可以看到数据)

I just tried inserting your data into a test RT index (including a string attribute, so could see the data)

mysql> insert into rttest values (1,'Albany Junior High School','Auckland','NZ','Albany Junior High School, Auckland, NZ');
   ... etc ...

mysql> select * from rttest where match('albany high');
+------+--------+-----------------------------------------+
| id   | weight | value                                   |
+------+--------+-----------------------------------------+
|    2 |   3267 | Albany High School, Albany, NY          |
|    3 |   3267 | South Albany High School, Albany, OR    |
|    4 |   3267 | Albany High School, Albany, CA          |
|    1 |   1304 | Albany Junior High School, Auckland, NZ |
+------+--------+-----------------------------------------+
4 rows in set (0.15 sec)

mysql> select * from rttest where match('albany high') option ranker=sph04;
+------+--------+-----------------------------------------+
| id   | weight | value                                   |
+------+--------+-----------------------------------------+
|    2 |  12267 | Albany High School, Albany, NY          |
|    4 |  12267 | Albany High School, Albany, CA          |
|    3 |  10267 | South Albany High School, Albany, OR    |
|    1 |   6304 | Albany Junior High School, Auckland, NZ |
+------+--------+-----------------------------------------+
4 rows in set (0.00 sec)

mysql> select * from rttest where match('albany high') option ranker=wordcount;
+------+--------+-----------------------------------------+
| id   | weight | value                                   |
+------+--------+-----------------------------------------+
|    2 |      3 | Albany High School, Albany, NY          |
|    3 |      3 | South Albany High School, Albany, OR    |
|    4 |      3 | Albany High School, Albany, CA          |
|    1 |      2 | Albany Junior High School, Auckland, NZ |
+------+--------+-----------------------------------------+
4 rows in set (0.00 sec)

更改排名模式确实有效.

Changing the ranking mode does work.

这篇关于Sphinx忽略排名,始终按相同顺序排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆