简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM