Changing similarity implementation used during indexing
Part of the norms calculation at the index time on is similarity. Lucene has already implemented a complex model called TFIDFSimilarity as a default calculation for norms; you can read more about it on Lucene's website. In this section, we will talk about how we can tune similarity to suit our needs.
We will go through a similar scenario as we used in our example in norms. Instead of using boost to influence relevancy, we will leverage a NumericDocValuesField called ranking that will act as our boost. We will show you how to pull NumericDocValues at a query time within a Similarity class and how we can use it to influence score. This exercise will give you an idea of what you can do with similarity customization.
Getting ready
To start writing your own Similarity class, you can begin by extending Similarity. Then, you can register your new class by simply calling IndexWriterConfig.setSimilarity(Similarity
) in indexing and IndexSearcher...