search - Solr 中按自定义分数排序的排序不一致

标签 search sorting solr

我为 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"的含义?

编辑:我尝试将“分数”字段重命名为“流行度”并得到相同的结果。

最佳答案

分数字段由 Solr 内部使用,因此定义具有相同字段名称的字段可能不是一个好习惯。
您可以尝试使用不同的字段名称定义一个字段,并且您提到的两个选项都可以正常工作。

编辑 - 这是我所拥有的并且工作正常(Solr 3.3)

架构 -

字段类型 -

<fieldType name="sint" class="solr.SortableIntField" sortMissingLast="true" omitNorms="true"/>

field -
<field name="popularity" type="int" indexed="true" stored="true" />

数据 -
<add>
    <doc>
      <field name="id">1007WFP</field>
      <field name="popularity">566</field>
      <field name="text">SF - You lost me at hello...</field>
    </doc>
    <doc>
      <field name="id">2007WFP</field>
      <field name="popularity">41</field>
      <field name="text">hello</field>
    </doc>
    <doc>
      <field name="id">3007WFP</field>
      <field name="popularity">77</field>
      <field name="text">
        CAGE PAGE-SAY HELLO (MIKE GOLDEN's Life Is Bass Remix)-VIM
      </field>
    </doc>
    <doc>
      <field name="id">4007WFP</field>
      <field name="popularity">0</field>
      <field name="text">Hello Hello Hello</field>
    </doc>
</add>

询问 -
http://localhost:8983/solr/select?q=*:*&sort=popularity%20desc

结果 :-
<result name="response" numFound="4" start="0">
  <doc>
    <str name="id">1007WFP</str>
    <int name="popularity">566</int>
  </doc>

  <doc>
    <str name="id">3007WFP</str>
    <int name="popularity">77</int>
  </doc>
  <doc>
    <str name="id">2007WFP</str>
    <int name="popularity">41</int>

  </doc>
  <doc>
    <str name="id">4007WFP</str>
    <int name="popularity">0</int>
  </doc>
</result>

关于search - Solr 中按自定义分数排序的排序不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7588971/

相关文章:

php - 异常写入文档id

Mysql搜索多个连接结果

java - 仅当列表的第一个元素相等时,Stream 才返回对象

java - 我需要对可租借的电影列表进行排序

java - SOLR入门,帮助不大

python-2.7 - pysolr 中的文档总数

database - 考虑拼写错误和部分结果的数据搜索基础

c++ - 在二进制文件中搜索字符串的代码

java - 重量排序(克、毫克、升、毫升。)

php - 拖放排序到 MySQL 中的 INSERT