Search code examples
pythonsearchelasticsearchwhoosh

Can I get the scores calculated by whoosh for each document while searching?


I am trying to implement Okapi BM25 to search documents by query using python whoosh library.

My understanding is that whoosh calculates the scores for each documents using BM25 according to the query and then sorts it to give the best result.

I use

results = searcher.search(query)

to get the document best matched to the query.

How can I get the scores for each document? Is there any other way to get scores for BM25 ranking?


Solution

  • You can get the computed score by using the score attribute:

    for r in results:
        print r, r.score