1
votes

Lucene supports a setting of fixed relative field weights during query creation. This means that for all matching documents, the similarity of the content of all searchable fields to the query is weighted (and summed) based on those fixed pre-defiend weights. My question is whether it is possible to set the document field weights dynamically during the search, based on each document's attributes. For example, if all indexed documents have a numeric field, I would like to set the relative weights of each document textual fields based on its numeric filed value.

Thanks David

1

1 Answers

0
votes

Yes, it's possible. In order to do that you can use the CustomScoreQuery. You can find a good example in the book Lucene In Action, where the CustomScoreQuery is extended to get the recency boosting (boosting of documents based on custom calculation made on date). In particular, you want to override the CustomScoreProvider with yours implementing the calculation that you need.