Package org.apache.lucene.search.join
Class DiversifyingChildrenFloatKnnVectorQuery
java.lang.Object
org.apache.lucene.search.Query
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);
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final String
protected final Query
protected final KnnSearchStrategy
Fields inherited from class org.apache.lucene.search.KnnFloatVectorQuery
target
-
Constructor Summary
ConstructorsConstructorDescriptionDiversifyingChildrenFloatKnnVectorQuery
(String field, float[] query, Query childFilter, int k, BitSetProducer parentsFilter) Create a DiversifyingChildrenFloatKnnVectorQuery.DiversifyingChildrenFloatKnnVectorQuery
(String field, float[] query, Query childFilter, int k, BitSetProducer parentsFilter, KnnSearchStrategy searchStrategy) Create a DiversifyingChildrenFloatKnnVectorQuery. -
Method Summary
Modifier and TypeMethodDescriptionprotected TopDocs
approximateSearch
(LeafReaderContext context, Bits acceptDocs, int visitedLimit, KnnCollectorManager knnCollectorManager) boolean
protected TopDocs
exactSearch
(LeafReaderContext context, DocIdSetIterator acceptIterator, QueryTimeout queryTimeout) getField()
int
getK()
protected KnnCollectorManager
getKnnCollectorManager
(int k, IndexSearcher searcher) int
hashCode()
protected TopDocs
mergeLeafResults
(TopDocs[] arg0) rewrite
(IndexSearcher arg0) void
visit
(QueryVisitor arg0) Methods inherited from class org.apache.lucene.search.KnnFloatVectorQuery
getTargetCopy
Methods inherited from class org.apache.lucene.search.Query
classHash, createWeight, sameClassAs, toString
-
Field Details
-
field
-
filter
-
searchStrategy
-
-
Constructor Details
-
DiversifyingChildrenFloatKnnVectorQuery
public DiversifyingChildrenFloatKnnVectorQuery(String field, float[] query, Query childFilter, int k, BitSetProducer parentsFilter) Create a DiversifyingChildrenFloatKnnVectorQuery.- 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.
-
DiversifyingChildrenFloatKnnVectorQuery
public DiversifyingChildrenFloatKnnVectorQuery(String field, float[] query, Query childFilter, int k, BitSetProducer parentsFilter, KnnSearchStrategy searchStrategy) Create a DiversifyingChildrenFloatKnnVectorQuery.- 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.searchStrategy
- the search strategy to use. If null, the default strategy will be used. The underlying format may not support all strategies and is free to ignore the requested strategy.- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
-
Method Details
-
exactSearch
protected TopDocs exactSearch(LeafReaderContext context, DocIdSetIterator acceptIterator, QueryTimeout queryTimeout) throws IOException - Throws:
IOException
-
getKnnCollectorManager
-
approximateSearch
protected TopDocs approximateSearch(LeafReaderContext context, Bits acceptDocs, int visitedLimit, KnnCollectorManager knnCollectorManager) throws IOException - Overrides:
approximateSearch
in classKnnFloatVectorQuery
- Throws:
IOException
-
toString
- Overrides:
toString
in classKnnFloatVectorQuery
-
equals
- Overrides:
equals
in classKnnFloatVectorQuery
-
hashCode
public int hashCode()- Overrides:
hashCode
in classKnnFloatVectorQuery
-
rewrite
- Overrides:
rewrite
in classQuery
- Throws:
IOException
-
mergeLeafResults
-
visit
-
getField
-
getK
public int getK() -
getFilter
-