Module org.apache.lucene.join
Package org.apache.lucene.search.join
Class DiversifyingNearestChildrenKnnCollector
java.lang.Object
org.apache.lucene.search.AbstractKnnCollector
org.apache.lucene.search.join.DiversifyingNearestChildrenKnnCollector
- All Implemented Interfaces:
KnnCollector
This collects the nearest children vectors. Diversifying the results over the provided parent
filter. This means the nearest children vectors are returned, but only one per parent
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
This is a minimum binary heap, inspired byLongHeap
.private static final record
Keeps track of child node, parent node, and the stored score. -
Field Summary
FieldsFields inherited from class org.apache.lucene.search.AbstractKnnCollector
visitedCount
-
Constructor Summary
ConstructorsConstructorDescriptionDiversifyingNearestChildrenKnnCollector
(int k, int visitLimit, BitSet parentBitSet) Create a new object for joining nearest child kNN documents with a parent bitset -
Method Summary
Modifier and TypeMethodDescriptionboolean
collect
(int docId, float nodeScore) If the heap is not full (size is less than the initialSize provided to the constructor), adds a new node-and-score element.float
This method is utilized during search to ensure only competitive results are explored.int
topDocs()
This drains the collected nearest kNN results and returns them in a newTopDocs
collection, ordered by score descending.toString()
Methods inherited from class org.apache.lucene.search.AbstractKnnCollector
earlyTerminated, incVisitedCount, k, visitedCount, visitLimit
-
Field Details
-
parentBitSet
-
heap
-
-
Constructor Details
-
DiversifyingNearestChildrenKnnCollector
Create a new object for joining nearest child kNN documents with a parent bitset- Parameters:
k
- The number of joined parent documents to collectvisitLimit
- how many child vectors can be visitedparentBitSet
- The leaf parent bitset
-
-
Method Details
-
collect
public boolean collect(int docId, float nodeScore) If the heap is not full (size is less than the initialSize provided to the constructor), adds a new node-and-score element. If the heap is full, compares the score against the current top score, and replaces the top element if newScore is better than (greater than unless the heap is reversed), the current top score.If docId's parent node has previously been collected and the provided nodeScore is less than the stored score it will not be collected.
- Specified by:
collect
in interfaceKnnCollector
- Specified by:
collect
in classAbstractKnnCollector
- Parameters:
docId
- the neighbor docIdnodeScore
- the score of the neighbor, relative to some other node- 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
- Specified by:
minCompetitiveSimilarity
in classAbstractKnnCollector
- Returns:
- the current minimum competitive similarity in the collection
-
toString
-
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
- Specified by:
topDocs
in classAbstractKnnCollector
- Returns:
- The collected top documents
-
numCollected
public int numCollected()- Specified by:
numCollected
in classAbstractKnnCollector
-