Class XCombinedFieldQuery
- All Implemented Interfaces:
org.apache.lucene.util.Accountable
public final class XCombinedFieldQuery
extends org.apache.lucene.search.Query
implements org.apache.lucene.util.Accountable
Query
that treats multiple fields as a single stream and scores terms as if you had
indexed them as a single term in a single field.
The query works as follows:
- Given a list of fields and weights, it pretends there is a synthetic combined field where all terms have been indexed. It computes new term and collection statistics for this combined field.
- It uses a disjunction iterator and
IndexSearcher.getSimilarity()
to score documents.
In order for a similarity to be compatible, Similarity.computeNorm(org.apache.lucene.index.FieldInvertState)
must be additive:
the norm of the combined field is the sum of norms for each individual field. The norms must also
be encoded using SmallFloat.intToByte4(int)
. These requirements hold for all similarities that
compute norms the same way as SimilarityBase.computeNorm(org.apache.lucene.index.FieldInvertState)
, which includes BM25Similarity
and DFRSimilarity
. Per-field similarities are not supported.
The scoring is based on BM25F's simple formula described in:
http://www.staff.city.ac.uk/~sb317/papers/foundations_bm25_review.pdf. This query implements the
same approach but allows other similarities besides BM25Similarity
.
TODO: this is temporarily copied from Lucene, remove once we update to Lucene 8.9.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
XCombinedFieldQuery.Builder
A builder forXCombinedFieldQuery
. -
Field Summary
Fields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE
-
Method Summary
Modifier and Type Method Description org.apache.lucene.search.Weight
createWeight(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.ScoreMode scoreMode, float boost)
boolean
equals(java.lang.Object other)
java.util.List<org.apache.lucene.index.Term>
getTerms()
int
hashCode()
long
ramBytesUsed()
org.apache.lucene.search.Query
rewrite(org.apache.lucene.index.IndexReader reader)
java.lang.String
toString(java.lang.String field)
void
visit(org.apache.lucene.search.QueryVisitor visitor)
Methods inherited from class org.apache.lucene.search.Query
classHash, sameClassAs, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.lucene.util.Accountable
getChildResources
-
Method Details
-
getTerms
public java.util.List<org.apache.lucene.index.Term> getTerms() -
toString
public java.lang.String toString(java.lang.String field)- Specified by:
toString
in classorg.apache.lucene.search.Query
-
hashCode
public int hashCode()- Specified by:
hashCode
in classorg.apache.lucene.search.Query
-
equals
public boolean equals(java.lang.Object other)- Specified by:
equals
in classorg.apache.lucene.search.Query
-
ramBytesUsed
public long ramBytesUsed()- Specified by:
ramBytesUsed
in interfaceorg.apache.lucene.util.Accountable
-
rewrite
public org.apache.lucene.search.Query rewrite(org.apache.lucene.index.IndexReader reader) throws java.io.IOException- Overrides:
rewrite
in classorg.apache.lucene.search.Query
- Throws:
java.io.IOException
-
visit
public void visit(org.apache.lucene.search.QueryVisitor visitor)- Overrides:
visit
in classorg.apache.lucene.search.Query
-
createWeight
public org.apache.lucene.search.Weight createWeight(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.ScoreMode scoreMode, float boost) throws java.io.IOException- Overrides:
createWeight
in classorg.apache.lucene.search.Query
- Throws:
java.io.IOException
-