possible to ignore lucene document boost?

2019-09-04 15:07发布

I am looking for a way to tell the lucene searcher to ignore document boosting on certain queries?

In our search results we usually work with a dominant boost-factor calculated by the age of a document while indexing (the index is rebuild nightly).

Now, I am looking for a way offer search-functionality which ignores the age, but found yet no way to override/ignore the document boost.

Best regards,

Alex

3条回答
三岁会撩人
2楼-- · 2019-09-04 15:27

http://lucene.apache.org/java/3_0_0/api/core/org/apache/lucene/search/Similarity.html

From the point 6, I reckon it is impossible to ignore boosts at search time:

norm(t,d) encapsulates a few (indexing time) boost and length factors:

  • Document boost - set by calling doc.setBoost() before adding the document to the index.
  • Field boost - set by calling field.setBoost() before adding the field to a document.
  • lengthNorm(field) - computed when the document is added to the index in accordance with the number of tokens of this field in the document, so that shorter fields contribute more to the score. LengthNorm is computed by the Similarity class in effect at indexing.

When a document is added to the index, all the above factors are multiplied. If the document has multiple fields with the same name, all their boosts are multiplied together:

(...)

Last, note that search time is too late to modify this norm part of scoring, e.g. by using a different Similarity for search.

查看更多
霸刀☆藐视天下
3楼-- · 2019-09-04 15:32

Are you looking for something the QueryParser would understand? Because that is simply not possible.

You're adding the boost somewhere in your code, it is not done by Lucene by default. You'll have to remove this additional piece of code, or make it optional in order to ignore the boost.

查看更多
Ridiculous、
4楼-- · 2019-09-04 15:42

Instead of storing your calculated-score as boost, you can store it in a new field, and by implementing CustomScoreQuery + CustomScoreProvider you can control which value(default score or your calculated-one in the field) to return

查看更多
登录 后发表回答