shyamupa
shyamupa

Reputation: 1628

Get document scores in lucene with version > 4.3?

Earlier you could specify to obtain scores by setting

searcher.setDefaultFieldSortScoring(true, true);

as written in this answer.

Now the api suggest to use the following function,

public TopFieldDocs search(Query query,
                  Filter filter,
                  int n,
                  Sort sort,
                  boolean doDocScores,
                  boolean doMaxScore)
                    throws IOException

I simply want to get the results sorted by score, and I do not understand how to use this. Can anyone give an example?

Upvotes: 0

Views: 122

Answers (1)

femtoRgon
femtoRgon

Reputation: 33341

Just don't pass in the sorting parameters, and it will sort by score, using IndexSearcher.search(Query, Filter, int)

You could also pass in a sort instance that sorts on relevance, using the Sort.RELEVANCE constant, if you prefer. There is slightly more overhead to this than just omitting the sort, apparently, but I doubt it's all that significant.

Upvotes: 1

Related Questions