Package org.apache.lucene.search
Class AbstractKnnCollector
java.lang.Object
org.apache.lucene.search.AbstractKnnCollector
- All Implemented Interfaces:
KnnCollector
- Direct Known Subclasses:
TopKnnCollector
AbstractKnnCollector is the default implementation for a knn collector used for gathering kNN
results and providing topDocs from the gathered neighbors
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.lucene.search.KnnCollector
KnnCollector.Decorator -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractKnnCollector(int k, long visitLimit) protectedAbstractKnnCollector(int k, long visitLimit, KnnSearchStrategy searchStrategy) -
Method Summary
Modifier and TypeMethodDescriptionabstract booleancollect(int docId, float similarity) Collect the provided docId and include in the result set.final booleanIf search visits too many documents, the results collector will terminate early.final voidincVisitedCount(int count) final intk()abstract floatThis method is utilized during search to ensure only competitive results are explored.abstract intabstract TopDocstopDocs()This drains the collected nearest kNN results and returns them in a newTopDocscollection, ordered by score descending.final longfinal long
-
Field Details
-
visitedCount
protected long visitedCount
-
-
Constructor Details
-
AbstractKnnCollector
-
AbstractKnnCollector
protected AbstractKnnCollector(int k, long visitLimit)
-
-
Method Details
-
earlyTerminated
public final boolean earlyTerminated()Description copied from interface:KnnCollectorIf search visits too many documents, the results collector will terminate early. Usually, this is due to some restricted filter on the document set.When collection is earlyTerminated, the results are not a correct representation of k nearest neighbors.
- Specified by:
earlyTerminatedin interfaceKnnCollector- Returns:
- is the current result set marked as incomplete?
-
incVisitedCount
public final void incVisitedCount(int count) - Specified by:
incVisitedCountin interfaceKnnCollector- Parameters:
count- increments the visited vector count, must be greater than 0.
-
visitedCount
public final long visitedCount()- Specified by:
visitedCountin interfaceKnnCollector- Returns:
- the current visited vector count
-
visitLimit
public final long visitLimit()- Specified by:
visitLimitin interfaceKnnCollector- Returns:
- the visited vector limit
-
k
public final int k()- Specified by:
kin interfaceKnnCollector- Returns:
- the expected number of collected results
-
collect
public abstract boolean collect(int docId, float similarity) Description copied from interface:KnnCollectorCollect the provided docId and include in the result set.- Specified by:
collectin interfaceKnnCollector- Parameters:
docId- of the vector to collectsimilarity- its calculated similarity- Returns:
- true if the vector is collected
-
numCollected
public abstract int numCollected() -
minCompetitiveSimilarity
public abstract float minCompetitiveSimilarity()Description copied from interface:KnnCollectorThis method is utilized during search to ensure only competitive results are explored.Consequently, if this results collector wants to collect `k` results, this should return
Float.NEGATIVE_INFINITYwhen not full.When full, the minimum score should be returned.
- Specified by:
minCompetitiveSimilarityin interfaceKnnCollector- Returns:
- the current minimum competitive similarity in the collection
-
topDocs
Description copied from interface:KnnCollectorThis drains the collected nearest kNN results and returns them in a newTopDocscollection, ordered by score descending. NOTE: This is generally a destructive action and the collector should not be used after topDocs() is called.- Specified by:
topDocsin interfaceKnnCollector- Returns:
- The collected top documents
-
getSearchStrategy
- Specified by:
getSearchStrategyin interfaceKnnCollector- Returns:
- the search strategy used by this collector, can be null
-