Package org.apache.lucene.search
Class DoubleValuesSource
- java.lang.Object
-
- org.apache.lucene.search.DoubleValuesSource
-
- All Implemented Interfaces:
SegmentCacheable
public abstract class DoubleValuesSource extends Object implements SegmentCacheable
Base class for producingDoubleValues
To obtain aDoubleValues
object for a leaf reader, clients should callrewrite(IndexSearcher)
against the top-level searcher, and then callgetValues(LeafReaderContext, DoubleValues)
on the resulting DoubleValuesSource. DoubleValuesSource objects for NumericDocValues fields can be obtained by callingfromDoubleField(String)
,fromFloatField(String)
,fromIntField(String)
orfromLongField(String)
, or fromfromField(String, LongToDoubleFunction)
if special long-to-double encoding is required. Scores may be used as a source for value calculations by wrapping aScorer
usingfromScorer(Scorer)
and passing the resulting DoubleValues togetValues(LeafReaderContext, DoubleValues)
. The scores can then be accessed using theSCORES
DoubleValuesSource.
-
-
Field Summary
Fields Modifier and Type Field Description static DoubleValuesSource
SCORES
A DoubleValuesSource that exposes a document's score If this source is used as part of a values calculation, then callers must not passnull
as theDoubleValues
parameter ongetValues(LeafReaderContext, DoubleValues)
-
Constructor Summary
Constructors Constructor Description DoubleValuesSource()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static DoubleValuesSource
constant(double value)
Creates a DoubleValuesSource that always returns a constant valueabstract boolean
equals(Object obj)
Explanation
explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation)
An explanation of the value for the named document.static DoubleValuesSource
fromDoubleField(String field)
Creates a DoubleValuesSource that wraps a double-valued fieldstatic DoubleValuesSource
fromField(String field, LongToDoubleFunction decoder)
Creates a DoubleValuesSource that wraps a generic NumericDocValues fieldstatic DoubleValuesSource
fromFloatField(String field)
Creates a DoubleValuesSource that wraps a float-valued fieldstatic DoubleValuesSource
fromIntField(String field)
Creates a DoubleValuesSource that wraps an int-valued fieldstatic DoubleValuesSource
fromLongField(String field)
Creates a DoubleValuesSource that wraps a long-valued fieldstatic DoubleValuesSource
fromQuery(Query query)
Create a DoubleValuesSource that returns the score of a particular querystatic DoubleValues
fromScorer(Scorer scorer)
Returns a DoubleValues instance that wraps scores returned by a ScorerSortField
getSortField(boolean reverse)
Create a sort field based on the value of this producerabstract DoubleValues
getValues(LeafReaderContext ctx, DoubleValues scores)
Returns aDoubleValues
instance for the passed-in LeafReaderContext and scores If scores are not needed to calculate the values (iereturns false
, callers may safely passnull
for thescores
parameter.abstract int
hashCode()
abstract boolean
needsScores()
Return true if document scores are needed to calculate valuesabstract DoubleValuesSource
rewrite(IndexSearcher reader)
Return a DoubleValuesSource specialised for the given IndexSearcher Implementations should assume that this will only be called once.LongValuesSource
toLongValuesSource()
Convert to a LongValuesSource by casting the double values to longsabstract String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.lucene.search.SegmentCacheable
isCacheable
-
-
-
-
Field Detail
-
SCORES
public static final DoubleValuesSource SCORES
A DoubleValuesSource that exposes a document's score If this source is used as part of a values calculation, then callers must not passnull
as theDoubleValues
parameter ongetValues(LeafReaderContext, DoubleValues)
-
-
Method Detail
-
getValues
public abstract DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException
Returns aDoubleValues
instance for the passed-in LeafReaderContext and scores If scores are not needed to calculate the values (iereturns false
, callers may safely passnull
for thescores
parameter.- 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 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
public abstract DoubleValuesSource rewrite(IndexSearcher reader) throws IOException
Return a DoubleValuesSource specialised for the given IndexSearcher Implementations should assume that this will only be called once. IndexReader-independent implementations can just returnthis
Queries that use DoubleValuesSource objects should call rewrite() duringQuery.createWeight(IndexSearcher, boolean, float)
rather than duringQuery.rewrite(IndexReader)
to avoid IndexReader reference leakage- Throws:
IOException
-
getSortField
public SortField getSortField(boolean reverse)
Create a sort field based on the value of this producer- Parameters:
reverse
- true if the sort should be decreasing
-
toLongValuesSource
public final LongValuesSource toLongValuesSource()
Convert to a LongValuesSource by casting the double values to longs
-
fromField
public static DoubleValuesSource fromField(String field, LongToDoubleFunction decoder)
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
public static DoubleValuesSource fromDoubleField(String field)
Creates a DoubleValuesSource that wraps a double-valued field
-
fromFloatField
public static DoubleValuesSource fromFloatField(String field)
Creates a DoubleValuesSource that wraps a float-valued field
-
fromLongField
public static DoubleValuesSource fromLongField(String field)
Creates a DoubleValuesSource that wraps a long-valued field
-
fromIntField
public static DoubleValuesSource fromIntField(String field)
Creates a DoubleValuesSource that wraps an int-valued field
-
constant
public static DoubleValuesSource constant(double value)
Creates a DoubleValuesSource that always returns a constant value
-
fromScorer
public static DoubleValues fromScorer(Scorer scorer)
Returns a DoubleValues instance that wraps scores returned by a Scorer
-
fromQuery
public static DoubleValuesSource fromQuery(Query query)
Create a DoubleValuesSource that returns the score of a particular query
-
-