Package org.apache.lucene.expressions
Class ExpressionValueSource
java.lang.Object
org.apache.lucene.search.DoubleValuesSource
org.apache.lucene.expressions.ExpressionValueSource
- All Implemented Interfaces:
SegmentCacheable
- Direct Known Subclasses:
CachingExpressionValueSource
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final Expression
(package private) final boolean
(package private) final DoubleValuesSource[]
Fields inherited from class org.apache.lucene.search.DoubleValuesSource
SCORES
-
Constructor Summary
ConstructorsConstructorDescriptionExpressionValueSource
(Bindings bindings, Expression expression) ExpressionValueSource
(DoubleValuesSource[] variables, Expression expression, boolean needsScores) -
Method Summary
Modifier and TypeMethodDescriptionboolean
explain
(LeafReaderContext ctx, int docId, Explanation scoreExplanation) An explanation of the value for the named document.getValues
(LeafReaderContext readerContext, DoubleValues scores) Returns aDoubleValues
instance for the passed-in LeafReaderContext and scoresint
hashCode()
boolean
boolean
Return true if document scores are needed to calculate valuesrewrite
(IndexSearcher searcher) Return a DoubleValuesSource specialised for the given IndexSearchertoString()
(package private) static DoubleValues
Create a wrapper around all the expression arguments to do two things: Default to 0 for any argument that doesn't have a value for a given doc (i.e., #advanceExact returns false) Be as lazy as possible about actually advancing to the given doc until the argument value is actually needed by the expression.Methods inherited from class org.apache.lucene.search.DoubleValuesSource
constant, fromDoubleField, fromField, fromFloatField, fromIntField, fromLongField, fromQuery, fromScorer, getSortField, similarityToQueryVector, similarityToQueryVector, toLongValuesSource
-
Field Details
-
variables
-
expression
-
needsScores
final boolean needsScores
-
-
Constructor Details
-
ExpressionValueSource
ExpressionValueSource(Bindings bindings, Expression expression) -
ExpressionValueSource
ExpressionValueSource(DoubleValuesSource[] variables, Expression expression, boolean needsScores)
-
-
Method Details
-
getValues
public DoubleValues getValues(LeafReaderContext readerContext, DoubleValues scores) throws IOException Description copied from class:DoubleValuesSource
Returns aDoubleValues
instance for the passed-in LeafReaderContext and scoresIf scores are not needed to calculate the values (ie
returns false
, callers may safely passnull
for thescores
parameter.- Specified by:
getValues
in classDoubleValuesSource
- Throws:
IOException
-
zeroWhenUnpositioned
Create a wrapper around all the expression arguments to do two things:- Default to 0 for any argument that doesn't have a value for a given doc (i.e., #advanceExact returns false)
- Be as lazy as possible about actually advancing to the given doc until the argument value
is actually needed by the expression. For a given doc, some arguments may not actually be
needed, e.g., because of condition short-circuiting (
(true || X)
doesn't need to evaluateX
) or ternary branching (true ? X : Y
doesn't need to evaluateY
).
-
toString
- Specified by:
toString
in classDoubleValuesSource
-
hashCode
public int hashCode()- Specified by:
hashCode
in classDoubleValuesSource
-
equals
- Specified by:
equals
in classDoubleValuesSource
-
needsScores
public boolean needsScores()Description copied from class:DoubleValuesSource
Return true if document scores are needed to calculate values- Specified by:
needsScores
in classDoubleValuesSource
-
isCacheable
- Returns:
true
if the object can be cached against a given leaf
-
explain
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException Description copied from class:DoubleValuesSource
An explanation of the value for the named document.- Overrides:
explain
in classDoubleValuesSource
- Parameters:
ctx
- the readers context to create theExplanation
for.docId
- the document's id relative to the given context's reader- Returns:
- an Explanation for the value
- Throws:
IOException
- if anIOException
occurs
-
rewrite
Description copied from class:DoubleValuesSource
Return a DoubleValuesSource specialised for the given IndexSearcherImplementations should assume that this will only be called once. IndexReader-independent implementations can just return
this
Queries that use DoubleValuesSource objects should call rewrite() during
Query.createWeight(IndexSearcher, ScoreMode, float)
rather than duringQuery.rewrite(IndexSearcher)
to avoid IndexReader reference leakage.For the same reason, implementations that cache references to the IndexSearcher should return a new object from this method.
- Specified by:
rewrite
in classDoubleValuesSource
- Throws:
IOException
-