【发布时间】:2011-09-28 20:07:20
【问题描述】:
我为我的 Solr 数据库中的每个文档分配了一个自定义的“受欢迎程度”分数。我希望搜索结果按此自定义“分数”字段排序,而不是默认的内置相关性分数。
首先我定义我的分数字段:
<fieldType name="sint" class="solr.SortableIntField" sortMissingLast="true" omitNorms="true"/>
<field name="score" type="sint" stored="true" multiValued="false" />
然后我重建索引,为每个文档插入一个分数。 要运行查询,我使用如下内容:
(text:hello)+_val_:"score"
现在我希望文档返回按“分数”字段排序,但我得到的是:
<doc>
<int name="score">566</int>
<str name="text">SF - You lost me at hello...</str>
</doc>
<doc>
<int name="score">41</int>
<str name="text">hello</str>
</doc>
<doc>
<int name="score">77</int>
<str name="text">
CAGE PAGE-SAY HELLO (MIKE GOLDEN's Life Is Bass Remix)-VIM
</str>
</doc>
<doc>
<int name="score">0</int>
<str name="text">Hello Hello Hello</str>
</doc>
请注意,分数是乱序返回的:566、41、77、0。奇怪的是,它只对某些查询进行这种排序。我不确定模式是什么,但到目前为止,我只在搜索结果中返回“0”分数时看到排序错误。
我尝试使用 IntField 而不是 SortableIntField,并且尝试将“sort=score desc”作为查询参数,但行为没有任何变化。
我是不是做错了什么,或者只是误解了在我的查询中使用 val:"score" 的含义?
编辑:我尝试将“score”字段重命名为“popularity”并得到相同的结果。
【问题讨论】: