Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Search Solr中按自定义分数排序不一致_Search_Sorting_Solr - Fatal编程技术网

Search Solr中按自定义分数排序不一致

Search Solr中按自定义分数排序不一致,search,sorting,solr,Search,Sorting,Solr,我为Solr数据库中的每个文档分配一个自定义的“流行度”分数。我希望搜索结果按此自定义“分数”字段排序,而不是按默认的内置相关性分数排序 首先,我定义我的分数字段: <fieldType name="sint" class="solr.SortableIntField" sortMissingLast="true" omitNorms="true"/> <field name="score" type="sint" stored="true" multiValued="fals

我为Solr数据库中的每个文档分配一个自定义的“流行度”分数。我希望搜索结果按此自定义“分数”字段排序,而不是按默认的内置相关性分数排序

首先,我定义我的分数字段:

<fieldType name="sint" class="solr.SortableIntField" sortMissingLast="true" omitNorms="true"/>
<field name="score" type="sint" stored="true" multiValued="false" />
现在我希望文档按“分数”字段排序返回,但我得到的是:

<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
SF-你好的时候你把我弄丢了。。。
41
你好
77
CAGE PAGE-SAY HELLO(MIKE GOLDEN的生活是低音混音)-VIM
0
你好你好
请注意,分数的顺序是: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"/>
结果:-

<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>

1007粮食计划署
566
3007粮食计划署
77
2007年粮食计划署
41
4007粮食计划署
0

黑客实际上将“流行度”字段添加到通常计算的solr分数中

因此,如果文档A中的流行度=41,文档B中的流行度=77,但文档A在关键字“hello”上的得分比B高36分以上,那么它们将在B之前按A排序

使用“排序”字段(正如您所做的那样)完全覆盖按分数进行的正常排序


另一种方法是使用过滤查询(参数fq而不是q),过滤匹配文档而不计算任何分数,然后使用_val_uu)定义评分公式。由于使用筛选查询时,所有检索到的文档的分数都为零,_val_uuuuuuuuuu将不会受到影响,并按照您最初的预期进行操作。

很抱歉,我尝试将字段重命名为“流行度”,重建索引,并得到相同的结果。此外,没有看到字段被标记为索引为true,这将不允许对字段进行排序,并且还会引发错误。我使用index=“true”和index=“false”尝试了这两种方法,但没有效果。我没有收到带有index=“false”的错误消息。我尝试了这个示例,在Solr 3.3中效果很好。编辑了答案你能试试吗。将我的查询改为使用“sort=popularity desc”,并将“score”重命名为“popularity”,现在排序正确了。
<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>