Module org.apache.lucene.join
Package org.apache.lucene.search.join
Class DiversifyingChildrenFloatKnnVectorQuery
java.lang.Object
org.apache.lucene.search.Query
org.apache.lucene.search.AbstractKnnVectorQuery
org.apache.lucene.search.KnnFloatVectorQuery
org.apache.lucene.search.join.DiversifyingChildrenFloatKnnVectorQuery
kNN float vector query that joins matching children vector documents with their parent doc id.
The top documents returned are the child document ids and the calculated scores. Here is how to
use this in conjunction with
ToParentBlockJoinQuery.
Query knnQuery = new DiversifyingChildrenFloatKnnVectorQuery(fieldName, queryVector, ...); // Rewrite executes kNN search and collects nearest children docIds and their scores Query rewrittenKnnQuery = searcher.rewrite(knnQuery); // Join the scored children docs with their parents and score the parents Query childrenToParents = new ToParentBlockJoinQuery(rewrittenKnnQuery, parentsFilter, ScoreMode.MAX);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Queryprivate final intprivate static final TopDocsprivate final BitSetProducerprivate final float[]Fields inherited from class org.apache.lucene.search.AbstractKnnVectorQuery
field -
Constructor Summary
ConstructorsConstructorDescriptionDiversifyingChildrenFloatKnnVectorQuery(String field, float[] query, Query childFilter, int k, BitSetProducer parentsFilter) Create a ToParentBlockJoinFloatVectorQuery. -
Method Summary
Modifier and TypeMethodDescriptionprotected TopDocsapproximateSearch(LeafReaderContext context, Bits acceptDocs, int visitedLimit, KnnCollectorManager knnCollectorManager) booleanOverride and implement query instance equivalence properly in a subclass.protected TopDocsexactSearch(LeafReaderContext context, DocIdSetIterator acceptIterator, QueryTimeout queryTimeout) protected KnnCollectorManagergetKnnCollectorManager(int k, IndexSearcher searcher) inthashCode()Override and implement query hash code properly in a subclass.Prints a query to a string, withfieldassumed to be the default field and omitted.Methods inherited from class org.apache.lucene.search.KnnFloatVectorQuery
getTargetCopyMethods inherited from class org.apache.lucene.search.AbstractKnnVectorQuery
getField, getFilter, getK, mergeLeafResults, rewrite, visitMethods inherited from class org.apache.lucene.search.Query
classHash, createWeight, rewrite, sameClassAs, toString
-
Field Details
-
NO_RESULTS
-
parentsFilter
-
childFilter
-
k
private final int k -
query
private final float[] query
-
-
Constructor Details
-
DiversifyingChildrenFloatKnnVectorQuery
public DiversifyingChildrenFloatKnnVectorQuery(String field, float[] query, Query childFilter, int k, BitSetProducer parentsFilter) Create a ToParentBlockJoinFloatVectorQuery.- Parameters:
field- the query fieldquery- the vector querychildFilter- the child filterk- how many parent documents to return given the matching childrenparentsFilter- Filter identifying the parent documents.
-
-
Method Details
-
exactSearch
protected TopDocs exactSearch(LeafReaderContext context, DocIdSetIterator acceptIterator, QueryTimeout queryTimeout) throws IOException - Overrides:
exactSearchin classAbstractKnnVectorQuery- Throws:
IOException
-
getKnnCollectorManager
- Overrides:
getKnnCollectorManagerin classAbstractKnnVectorQuery
-
approximateSearch
protected TopDocs approximateSearch(LeafReaderContext context, Bits acceptDocs, int visitedLimit, KnnCollectorManager knnCollectorManager) throws IOException - Overrides:
approximateSearchin classKnnFloatVectorQuery- Throws:
IOException
-
toString
Description copied from class:QueryPrints a query to a string, withfieldassumed to be the default field and omitted.- Overrides:
toStringin classKnnFloatVectorQuery
-
equals
Description copied from class:QueryOverride and implement query instance equivalence properly in a subclass. This is required so thatQueryCacheworks properly.Typically a query will be equal to another only if it's an instance of the same class and its document-filtering properties are identical to those of the other instance. Utility methods are provided for certain repetitive code.
- Overrides:
equalsin classKnnFloatVectorQuery- See Also:
-
hashCode
public int hashCode()Description copied from class:QueryOverride and implement query hash code properly in a subclass. This is required so thatQueryCacheworks properly.- Overrides:
hashCodein classKnnFloatVectorQuery- See Also:
-