Mailing List Archive

Implementing Custom DoubleValues

I'm trying to write a custom DoubleValuesSource for use with a
FunctionScoreQuery instance. (I'm trying to migrate from an older version
of Lucene so I need to replace CustomScoreQuery).

To generate the final score of a document I need to:
1) Read from three indexed DocValues fields and
2) Use the score of the wrapped query passed in to the FunctionScoreQuery

For example, a document A would be scored using a formula like:
((docA's_score_from_wrapped_query * some_value_x) + (docA's_field1_value *
some_value_y) + (docA's_field2_value * some_value_z)) * docA's_field3_value
I know that I have to use SimpleBindings and Expressions to achieve this.

Q) How do I implement the following methods when writing a custom
DoubleValues inside a custom DoubleValuesSource implementation ?
a) isCacheable
b) needsScores (I'm aware that this should return true if I need the doc's
score value after running the query that's passed into FunctionScoreQuery's
constructor. However, I do not use the score in the custom DoubleValues
implementation itself, but rather in an outer method that makes use of
this. Would this still need to be 'true' in this case?)

I've read the Javadocs as well as multiple other questions on this topic on
this channel, but it's still confusing to me.

Appreciate your time and help.