Module org.apache.lucene.join
Package org.apache.lucene.search.join
Class DiversifyingChildrenByteKnnVectorQuery
- java.lang.Object
-
- org.apache.lucene.search.Query
-
- org.apache.lucene.search.AbstractKnnVectorQuery
-
- org.apache.lucene.search.KnnByteVectorQuery
-
- org.apache.lucene.search.join.DiversifyingChildrenByteKnnVectorQuery
-
public class DiversifyingChildrenByteKnnVectorQuery extends KnnByteVectorQuery
kNN byte 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 withToParentBlockJoinQuery
.Query knnQuery = new DiversifyingChildrenByteKnnVectorQuery(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
Fields Modifier and Type Field Description private Query
childFilter
private int
k
private static TopDocs
NO_RESULTS
private BitSetProducer
parentsFilter
private byte[]
query
-
Fields inherited from class org.apache.lucene.search.AbstractKnnVectorQuery
field
-
-
Constructor Summary
Constructors Constructor Description DiversifyingChildrenByteKnnVectorQuery(java.lang.String field, byte[] query, Query childFilter, int k, BitSetProducer parentsFilter)
Create a ToParentBlockJoinByteVectorQuery.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected TopDocs
approximateSearch(LeafReaderContext context, Bits acceptDocs, int visitedLimit, KnnCollectorManager knnCollectorManager)
boolean
equals(java.lang.Object o)
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.java.lang.String
toString(java.lang.String field)
Prints a query to a string, withfield
assumed to be the default field and omitted.-
Methods inherited from class org.apache.lucene.search.KnnByteVectorQuery
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, rewrite, sameClassAs, toString
-
-
-
-
Field Detail
-
NO_RESULTS
private static final TopDocs NO_RESULTS
-
parentsFilter
private final BitSetProducer parentsFilter
-
childFilter
private final Query childFilter
-
k
private final int k
-
query
private final byte[] query
-
-
Constructor Detail
-
DiversifyingChildrenByteKnnVectorQuery
public DiversifyingChildrenByteKnnVectorQuery(java.lang.String field, byte[] query, Query childFilter, int k, BitSetProducer parentsFilter)
Create a ToParentBlockJoinByteVectorQuery.- 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 Detail
-
exactSearch
protected TopDocs exactSearch(LeafReaderContext context, DocIdSetIterator acceptIterator, QueryTimeout queryTimeout) throws java.io.IOException
- Overrides:
exactSearch
in classAbstractKnnVectorQuery
- Throws:
java.io.IOException
-
getKnnCollectorManager
protected KnnCollectorManager getKnnCollectorManager(int k, IndexSearcher searcher)
- Overrides:
getKnnCollectorManager
in classAbstractKnnVectorQuery
-
approximateSearch
protected TopDocs approximateSearch(LeafReaderContext context, Bits acceptDocs, int visitedLimit, KnnCollectorManager knnCollectorManager) throws java.io.IOException
- Overrides:
approximateSearch
in classKnnByteVectorQuery
- Throws:
java.io.IOException
-
toString
public java.lang.String toString(java.lang.String field)
Description copied from class:Query
Prints a query to a string, withfield
assumed to be the default field and omitted.- Overrides:
toString
in classKnnByteVectorQuery
-
equals
public boolean equals(java.lang.Object o)
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 classKnnByteVectorQuery
- See Also:
Query.sameClassAs(Object)
,Query.classHash()
-
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 classKnnByteVectorQuery
- See Also:
Query.equals(Object)
-
-