Here is a patch with two new queries, FunctionScoreQuery and FunctionMatchQuery.
- FunctionScoreQuery takes a query to wrap and a DoubleValuesSource, and modifies the internal query's score using the per-document values. This can act as a replacement for FunctionQuery using a constant or per-field DoubleValuesSource, or as a replacement for CustomScoreQuery or BoostedQuery using an expression. The wrapped query's scores are passed to any DoubleValues created via getValues(LeafReaderContext, DoubleValues).
- FunctionMatchQuery takes a DoubleValuesSource and a Predicate<Double>, and returns any documents with a value that matches the predicate. It works by linear scan, but uses two-phase iteration so it should be efficient when combined with a more restrictive query. Unlike FunctionRangeQuery, it returns a constant score, so if you want to use the DoubleValues as scores, you will need to wrap it with a FunctionScoreQuery.
The patch also adds some more informative toString() implementations to expressions and field DoubleValues, to make the Explanations for FunctionScoreQuery more useful.