Package org.apache.lucene.search
Class DoubleValuesSource
java.lang.Object
org.apache.lucene.search.DoubleValuesSource
- All Implemented Interfaces:
SegmentCacheable
- Direct Known Subclasses:
DoubleValuesSource.ConstantValuesSource,DoubleValuesSource.FieldValuesSource,DoubleValuesSource.QueryDoubleValuesSource,DoubleValuesSource.WeightDoubleValuesSource,ExpressionValueSource,FeatureDoubleValuesSource,FunctionScoreQuery.MultiplicativeBoostValuesSource,FunctionScoreQuery.QueryBoostValuesSource,IndexReaderFunctions.IndexReaderDoubleValuesSource,IndexReaderFunctions.NoCacheConstantDoubleValuesSource,IndexReaderFunctions.TermFreqDoubleValuesSource,LongValuesSource.DoubleLongValuesSource,ValueSource.WrappedDoubleValuesSource
Base class for producing
DoubleValues
To obtain a DoubleValues object for a leaf reader, clients should call
rewrite(IndexSearcher) against the top-level searcher, and then
call getValues(LeafReaderContext, DoubleValues) on the resulting
DoubleValuesSource.
DoubleValuesSource objects for NumericDocValues fields can be obtained by calling
fromDoubleField(String), fromFloatField(String), fromIntField(String)
or fromLongField(String), or from fromField(String, LongToDoubleFunction) if
special long-to-double encoding is required.
Scores may be used as a source for value calculations by wrapping a Scorer using
fromScorer(Scorable) and passing the resulting DoubleValues to getValues(LeafReaderContext, DoubleValues).
The scores can then be accessed using the SCORES DoubleValuesSource.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classprivate static classprivate static classprivate static classprivate static classprivate static classprivate static classprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DoubleValuesSourceA DoubleValuesSource that exposes a document's score If this source is used as part of a values calculation, then callers must not passnullas theDoubleValuesparameter ongetValues(LeafReaderContext, DoubleValues) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static NumericDocValuesstatic DoubleValuesSourceconstant(double value) Creates a DoubleValuesSource that always returns a constant valueabstract booleanexplain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) An explanation of the value for the named document.static DoubleValuesSourcefromDoubleField(String field) Creates a DoubleValuesSource that wraps a double-valued fieldstatic DoubleValuesSourcefromField(String field, LongToDoubleFunction decoder) Creates a DoubleValuesSource that wraps a generic NumericDocValues fieldstatic DoubleValuesSourcefromFloatField(String field) Creates a DoubleValuesSource that wraps a float-valued fieldstatic DoubleValuesSourcefromIntField(String field) Creates a DoubleValuesSource that wraps an int-valued fieldstatic DoubleValuesSourcefromLongField(String field) Creates a DoubleValuesSource that wraps a long-valued fieldstatic DoubleValuesSourceCreate a DoubleValuesSource that returns the score of a particular querystatic DoubleValuesfromScorer(Scorable scorer) Returns a DoubleValues instance that wraps scores returned by a ScorergetSortField(boolean reverse) Create a sort field based on the value of this producerabstract DoubleValuesgetValues(LeafReaderContext ctx, DoubleValues scores) Returns aDoubleValuesinstance for the passed-in LeafReaderContext and scores If scores are not needed to calculate the values (iereturns false, callers may safely passnullfor thescoresparameter.abstract inthashCode()abstract booleanReturn true if document scores are needed to calculate valuesabstract DoubleValuesSourcerewrite(IndexSearcher reader) Return a DoubleValuesSource specialised for the given IndexSearcher Implementations should assume that this will only be called once.final LongValuesSourceConvert to a LongValuesSource by casting the double values to longsabstract StringtoString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.lucene.search.SegmentCacheable
isCacheable
-
Field Details
-
SCORES
A DoubleValuesSource that exposes a document's score If this source is used as part of a values calculation, then callers must not passnullas theDoubleValuesparameter ongetValues(LeafReaderContext, DoubleValues)
-
-
Constructor Details
-
DoubleValuesSource
public DoubleValuesSource()
-
-
Method Details
-
getValues
public abstract DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException Returns aDoubleValuesinstance for the passed-in LeafReaderContext and scores If scores are not needed to calculate the values (iereturns false, callers may safely passnullfor thescoresparameter.- Throws:
IOException
-
needsScores
public abstract boolean needsScores()Return true if document scores are needed to calculate values -
explain
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException An explanation of the value for the named document.- Parameters:
ctx- the readers context to create theExplanationfor.docId- the document's id relative to the given context's reader- Returns:
- an Explanation for the value
- Throws:
IOException- if anIOExceptionoccurs
-
rewrite
Return a DoubleValuesSource specialised for the given IndexSearcher Implementations should assume that this will only be called once. IndexReader-independent implementations can just returnthisQueries that use DoubleValuesSource objects should call rewrite() duringQuery.createWeight(IndexSearcher, ScoreMode, float)rather than duringQuery.rewrite(IndexReader)to avoid IndexReader reference leakage. For the same reason, implementations that cache references to the IndexSearcher should return a new object from this method.- Throws:
IOException
-
getSortField
Create a sort field based on the value of this producer- Parameters:
reverse- true if the sort should be decreasing
-
hashCode
public abstract int hashCode() -
equals
-
toString
-
toLongValuesSource
Convert to a LongValuesSource by casting the double values to longs -
fromField
Creates a DoubleValuesSource that wraps a generic NumericDocValues field- Parameters:
field- the field to wrap, must have NumericDocValuesdecoder- a function to convert the long-valued doc values to doubles
-
fromDoubleField
Creates a DoubleValuesSource that wraps a double-valued field -
fromFloatField
Creates a DoubleValuesSource that wraps a float-valued field -
fromLongField
Creates a DoubleValuesSource that wraps a long-valued field -
fromIntField
Creates a DoubleValuesSource that wraps an int-valued field -
constant
Creates a DoubleValuesSource that always returns a constant value -
fromScorer
Returns a DoubleValues instance that wraps scores returned by a Scorer -
asNumericDocValues
private static NumericDocValues asNumericDocValues(DoubleValuesSource.DoubleValuesHolder in, DoubleToLongFunction converter) -
fromQuery
Create a DoubleValuesSource that returns the score of a particular query
-