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
class DiversifyingNearestChildrenKnnCollector extends AbstractKnnCollector
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 Classes Modifier and Type Class Description private static class
DiversifyingNearestChildrenKnnCollector.NodeIdCachingHeap
This is a minimum binary heap, inspired byLongHeap
.private static class
DiversifyingNearestChildrenKnnCollector.ParentChildScore
Keeps track of child node, parent node, and the stored score.
-
Field Summary
Fields Modifier and Type Field Description private DiversifyingNearestChildrenKnnCollector.NodeIdCachingHeap
heap
private BitSet
parentBitSet
-
Constructor Summary
Constructors Constructor Description DiversifyingNearestChildrenKnnCollector(int k, int visitLimit, BitSet parentBitSet)
Create a new object for joining nearest child kNN documents with a parent bitset
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.float
minCompetitiveSimilarity()
This method is utilized during search to ensure only competitive results are explored.TopDocs
topDocs()
This drains the collected nearest kNN results and returns them in a newTopDocs
collection, ordered by score descending.java.lang.String
toString()
-
Methods inherited from class org.apache.lucene.search.AbstractKnnCollector
earlyTerminated, incVisitedCount, k, visitedCount, visitLimit
-
-
-
-
Field Detail
-
parentBitSet
private final BitSet parentBitSet
-
heap
private final DiversifyingNearestChildrenKnnCollector.NodeIdCachingHeap heap
-
-
Constructor Detail
-
DiversifyingNearestChildrenKnnCollector
public DiversifyingNearestChildrenKnnCollector(int k, int visitLimit, BitSet parentBitSet)
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 Detail
-
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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
topDocs
public TopDocs 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
-
-