java.lang.Object
org.apache.lucene.search.knn.MultiLeafKnnCollector
- All Implemented Interfaces:
KnnCollector
MultiLeafKnnCollector is a specific KnnCollector that can exchange the top collected results
across segments through a shared global queue.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate float
private static final float
private final BlockingFloatHeap
private final float
private final int
private boolean
private final FloatHeap
private final AbstractKnnCollector
private final FloatHeap
private final float[]
-
Constructor Summary
ConstructorsConstructorDescriptionMultiLeafKnnCollector
(int k, BlockingFloatHeap globalSimilarityQueue, AbstractKnnCollector subCollector) Create a new MultiLeafKnnCollector. -
Method Summary
Modifier and TypeMethodDescriptionboolean
collect
(int docId, float similarity) Collect the provided docId and include in the result set.boolean
If search visits too many documents, the results collector will terminate early.void
incVisitedCount
(int count) int
k()
float
This method is utilized during search to ensure only competitive results are explored.topDocs()
This drains the collected nearest kNN results and returns them in a newTopDocs
collection, ordered by score descending.toString()
long
long
-
Field Details
-
DEFAULT_GREEDINESS
private static final float DEFAULT_GREEDINESS- See Also:
-
globalSimilarityQueue
-
nonCompetitiveQueue
-
greediness
private final float greediness -
updatesQueue
-
updatesScratch
private final float[] updatesScratch -
interval
private final int interval- See Also:
-
kResultsCollected
private boolean kResultsCollected -
cachedGlobalMinSim
private float cachedGlobalMinSim -
subCollector
-
-
Constructor Details
-
MultiLeafKnnCollector
public MultiLeafKnnCollector(int k, BlockingFloatHeap globalSimilarityQueue, AbstractKnnCollector subCollector) Create a new MultiLeafKnnCollector.- Parameters:
k
- the number of neighbors to collectglobalSimilarityQueue
- the global queue of the highest similarities collected so far across all segmentssubCollector
- the local collector
-
-
Method Details
-
earlyTerminated
public boolean earlyTerminated()Description copied from interface:KnnCollector
If 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:
earlyTerminated
in interfaceKnnCollector
- Returns:
- is the current result set marked as incomplete?
-
incVisitedCount
public void incVisitedCount(int count) - Specified by:
incVisitedCount
in interfaceKnnCollector
- Parameters:
count
- increments the visited vector count, must be greater than 0.
-
visitedCount
public long visitedCount()- Specified by:
visitedCount
in interfaceKnnCollector
- Returns:
- the current visited vector count
-
visitLimit
public long visitLimit()- Specified by:
visitLimit
in interfaceKnnCollector
- Returns:
- the visited vector limit
-
k
public int k()- Specified by:
k
in interfaceKnnCollector
- Returns:
- the expected number of collected results
-
collect
public boolean collect(int docId, float similarity) Description copied from interface:KnnCollector
Collect the provided docId and include in the result set.- Specified by:
collect
in interfaceKnnCollector
- Parameters:
docId
- of the vector to collectsimilarity
- its calculated similarity- Returns:
- true if the vector is collected
-
minCompetitiveSimilarity
public float minCompetitiveSimilarity()Description copied from interface:KnnCollector
This 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_INFINITY
when not full.When full, the minimum score should be returned.
- Specified by:
minCompetitiveSimilarity
in interfaceKnnCollector
- Returns:
- the current minimum competitive similarity in the collection
-
topDocs
Description copied from interface:KnnCollector
This drains the collected nearest kNN results and returns them in a newTopDocs
collection, ordered by score descending. NOTE: This is generally a destructive action and the collector should not be used after topDocs() is called.- Specified by:
topDocs
in interfaceKnnCollector
- Returns:
- The collected top documents
-
toString
-