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 classThis is a minimum binary heap, inspired byLongHeap.private static classKeeps 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 TypeMethodDescriptionbooleancollect(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.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, 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:
collectin interfaceKnnCollector- Specified by:
collectin 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: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
-
toString
-
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
-