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 Query
private final int
private static final TopDocs
private final BitSetProducer
private final float[]
Fields inherited from class org.apache.lucene.search.AbstractKnnVectorQuery
field, filter
-
Constructor Summary
ConstructorsConstructorDescriptionDiversifyingChildrenFloatKnnVectorQuery
(String field, float[] query, Query childFilter, int k, BitSetProducer parentsFilter) Create a ToParentBlockJoinFloatVectorQuery. -
Method Summary
Modifier and TypeMethodDescriptionprotected TopDocs
approximateSearch
(LeafReaderContext context, Bits acceptDocs, int visitedLimit, KnnCollectorManager knnCollectorManager) boolean
Override and implement query instance equivalence properly in a subclass.protected TopDocs
exactSearch
(LeafReaderContext context, DocIdSetIterator acceptIterator, QueryTimeout queryTimeout) protected KnnCollectorManager
getKnnCollectorManager
(int k, IndexSearcher searcher) int
hashCode()
Override and implement query hash code properly in a subclass.Prints a query to a string, withfield
assumed to be the default field and omitted.Methods inherited from class org.apache.lucene.search.KnnFloatVectorQuery
getTargetCopy
Methods inherited from class org.apache.lucene.search.AbstractKnnVectorQuery
getField, getFilter, getK, mergeLeafResults, rewrite, visit
Methods inherited from class org.apache.lucene.search.Query
classHash, createWeight, 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:
exactSearch
in classAbstractKnnVectorQuery
- Throws:
IOException
-
getKnnCollectorManager
- Overrides:
getKnnCollectorManager
in classAbstractKnnVectorQuery
-
approximateSearch
protected TopDocs approximateSearch(LeafReaderContext context, Bits acceptDocs, int visitedLimit, KnnCollectorManager knnCollectorManager) throws IOException - Overrides:
approximateSearch
in classKnnFloatVectorQuery
- Throws:
IOException
-
toString
Description copied from class:Query
Prints a query to a string, withfield
assumed to be the default field and omitted.- Overrides:
toString
in classKnnFloatVectorQuery
-
equals
Description copied from class:Query
Override and implement query instance equivalence properly in a subclass. This is required so thatQueryCache
works 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:
equals
in classKnnFloatVectorQuery
- See Also:
-
hashCode
public int hashCode()Description copied from class:Query
Override and implement query hash code properly in a subclass. This is required so thatQueryCache
works properly.- Overrides:
hashCode
in classKnnFloatVectorQuery
- See Also:
-