views:

268

answers:

1

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>();      
      sortFields.Add(new SortField(StartDateTime.ToString(), SortField.STRING, ReverseSort));
      sortFields.Add(new SortField(TitleSort.ToString(), SortField.STRING, ReverseSort));
      return new Sort(sortFields.ToArray());
    }
A: 

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.

Yuval F
I am passing the sortobject to the overloaded search method and no problem with the index. Sorting works perfectly in normal cases. Only in case of documents where the sort score is different, the SortField is being used properly. It tries to sort the results and the results with high sort score are getting misplaced.
TR