3

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?

Ajit Barik
  • 33
  • 1
  • 6

2 Answers2

4

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

for r in results:
    print r, r.score
Truong-Son
  • 106
  • 1
  • 1
0

You can get the different scoring alog or retrieval.

For an example Tf-IDF, Frequency, BM25.

If you want score then here is the method.

results = searcher.search(query)

for hit in results:
  print("the Score", hit.score)
  print("the rank", hit.rank)
  print("the document number", hit.docnum) 
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Abhishek Kaushik
  • 93
  • 1
  • 2
  • 12