Package org.apache.lucene.search
Class TopKnnCollector
java.lang.Object
org.apache.lucene.search.AbstractKnnCollector
org.apache.lucene.search.TopKnnCollector
- All Implemented Interfaces:
KnnCollector
TopKnnCollector is a specific KnnCollector. A minHeap is used to keep track of the currently
collected vectors allowing for efficient updates as better vectors are collected.
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.lucene.search.KnnCollector
KnnCollector.Decorator -
Field Summary
FieldsFields inherited from class org.apache.lucene.search.AbstractKnnCollector
visitedCount -
Constructor Summary
ConstructorsConstructorDescriptionTopKnnCollector(int k, int visitLimit) Constructor, with default search strategyTopKnnCollector(int k, int visitLimit, KnnSearchStrategy searchStrategy) -
Method Summary
Modifier and TypeMethodDescriptionbooleancollect(int docId, float similarity) Collect the provided docId and include in the result set.floatThis method is utilized during search to ensure only competitive results are explored.inttopDocs()This drains the collected nearest kNN results and returns them in a newTopDocscollection, ordered by score descending.toString()Methods inherited from class org.apache.lucene.search.AbstractKnnCollector
earlyTerminated, getSearchStrategy, incVisitedCount, k, visitedCount, visitLimit
-
Field Details
-
queue
-
-
Constructor Details
-
TopKnnCollector
public TopKnnCollector(int k, int visitLimit) Constructor, with default search strategy -
TopKnnCollector
- Parameters:
k- the number of neighbors to collectvisitLimit- how many vector nodes the results are allowed to visitsearchStrategy- the search strategy to use
-
-
Method Details
-
collect
public boolean collect(int docId, float similarity) Description copied from interface:KnnCollectorCollect the provided docId and include in the result set.- Specified by:
collectin interfaceKnnCollector- Specified by:
collectin classAbstractKnnCollector- 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: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- Specified by:
minCompetitiveSimilarityin classAbstractKnnCollector- 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- Specified by:
topDocsin classAbstractKnnCollector- Returns:
- The collected top documents
-
numCollected
public int numCollected()- Specified by:
numCollectedin classAbstractKnnCollector
-
toString
-