开发者

Document score effecting the sort order of results, Lucene

开发者 https://www.devze.com 2022-12-21 07:23 出处:网络
Even after passing a sortfield, score of the document is effecting the sort order of the search results. Is there a way to make lucene to ignore the document score when a specific sort field is passed

Even after passing a sortfield, score of the document is effecting the sort order of the search results. Is there a way to make lucene to ignore the document score when a specific sort field is passed?

For ex:

DocId    Score        SortFieldA        SortFieldB
  1      23.0041      200906030800      Test
  2      32.2774      200906020800      Test
  3      21.0632      200906030800      Apple

I want the results to be sorted by SortFieldA first and then by SortFieldB. So in the above case the results should be and returned as doc2, doc3 and doc1. But because of the Score, the sort order is getting disturbed.

I noticed that the results are getting sorted properly if the documents have same score.

Code that sets the sort fields:

public override Sort GetSort()
    {
      List<SortField> sortFields = new List<SortField>();      
开发者_Python百科      sortFields.Add(new SortField(StartDateTime.ToString(), SortField.STRING, ReverseSort));
      sortFields.Add(new SortField(TitleSort.ToString(), SortField.STRING, ReverseSort));
      return new Sort(sortFields.ToArray());
    }


Edit: as you do not care for the original score, I believe you need to use a ConstantScoreQuery to get the hits first, and then pass them to the sorter.

Try looking at this question.

0

精彩评论

暂无评论...
验证码 换一张
取 消