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
-
public class DiversifyingChildrenFloatKnnVectorQuery extends KnnFloatVectorQuery
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 withToParentBlockJoinQuery
.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 Classes Modifier and Type Class Description (package private) static class
DiversifyingChildrenFloatKnnVectorQuery.DiversifyingChildrenVectorScorer
-
Field Summary
Fields Modifier and Type Field Description private Query
childFilter
private int
k
private static TopDocs
NO_RESULTS
private BitSetProducer
parentsFilter
private float[]
query
-
Fields inherited from class org.apache.lucene.search.AbstractKnnVectorQuery
field
-
-
Constructor Summary
Constructors Constructor Description DiversifyingChildrenFloatKnnVectorQuery(java.lang.String field, float[] query, Query childFilter, int k, BitSetProducer parentsFilter)
Create a ToParentBlockJoinFloatVectorQuery.
-
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.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, 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 float[] query
-
-
Constructor Detail
-
DiversifyingChildrenFloatKnnVectorQuery
public DiversifyingChildrenFloatKnnVectorQuery(java.lang.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 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 classKnnFloatVectorQuery
- 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 classKnnFloatVectorQuery
-
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 classKnnFloatVectorQuery
- 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 classKnnFloatVectorQuery
- See Also:
Query.equals(Object)
-
-