scoring module

This module contains classes for scoring (and sorting) search results.

Scoring algorithm classes

class whoosh.scoring.Weighting

This class provides backwards-compatibility with the old weighting class architecture, so any existing custom scorers don’t need to be rewritten.

It may also be useful for quick experimentation since you only need to override the score() method to try a scoring algorithm, without having to create an inner Scorer class:

class MyWeighting(Weighting):
    def score(searcher, fieldname, text, docnum, weight):
        # Return the docnum as the score, for some reason
        return docnum
        
mysearcher = myindex.searcher(weighting=MyWeighting)
class whoosh.scoring.BM25F(B=0.75, K1=1.2, **kwargs)

Implements the BM25F scoring algorithm.

>>> from whoosh import scoring
>>> # Set a custom B value for the "content" field
>>> w = scoring.BM25F(B=0.75, content_B=1.0, K1=1.5)
Parameters:
  • B – free parameter, see the BM25 literature. Keyword arguments of the form fieldname_B (for example, body_B) set field- specific values for B.
  • K1 – free parameter, see the BM25 literature.
class whoosh.scoring.TF_IDF
class whoosh.scoring.Frequency

Scoring utility classes

class whoosh.scoring.MultiWeighting(default, **weightings)

Chooses from multiple scoring algorithms based on the field.

The only non-keyword argument specifies the default Weighting instance to use. Keyword arguments specify Weighting instances for specific fields.

For example, to use BM25 for most fields, but Frequency for the id field and TF_IDF for the keys field:

mw = MultiWeighting(BM25(), id=Frequency(), keys=TF_IDF())
Parameters:
  • default – the Weighting instance to use for fields not specified in the keyword arguments.
class whoosh.scoring.ReverseWeighting(weighting)

Wraps a weighting object and subtracts the wrapped model’s scores from 0, essentially reversing the weighting model.

Table Of Contents

Previous topic

reading module

Next topic

searching module

This Page