MultiTermQuery

abstract class MultiTermQuery(field: String, rewriteMethod: MultiTermQuery.RewriteMethod) : Query

An abstract Query that matches documents containing a subset of terms provided by a FilteredTermsEnum enumeration.

This query cannot be used directly; you must subclass it and define .getTermsEnum to provide a FilteredTermsEnum that iterates through the terms to be matched.

NOTE: if RewriteMethod is either .CONSTANT_SCORE_BOOLEAN_REWRITE or .SCORING_BOOLEAN_REWRITE, you may encounter a IndexSearcher.TooManyClauses exception during searching, which happens when the number of terms to be searched exceeds IndexSearcher.getMaxClauseCount. Setting RewriteMethod to .CONSTANT_SCORE_BLENDED_REWRITE or .CONSTANT_SCORE_REWRITE prevents this.

The recommended rewrite method is .CONSTANT_SCORE_BLENDED_REWRITE: it doesn't spend CPU computing unhelpful scores, and is the most performant rewrite method given the query. If you need scoring (like FuzzyQuery, use TopTermsScoringBooleanQueryRewrite which uses a priority queue to only collect competitive terms and not hit this limitation.

Note that org.gnit.lucenekmp.queryparser.classic.QueryParser produces MultiTermQueries using .CONSTANT_SCORE_REWRITE by default.

Inheritors

Constructors

Link copied to clipboard
constructor(field: String, rewriteMethod: MultiTermQuery.RewriteMethod)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
abstract class RewriteMethod

Abstract class that defines how the query is rewritten.

Link copied to clipboard

A rewrite method that first translates each term into BooleanClause.Occur.SHOULD clause in a BooleanQuery, but adjusts the frequencies used for scoring to be blended across the terms, otherwise the rarest term typically ranks highest (often not useful eg in the set of expanded terms in a FuzzyQuery).

Link copied to clipboard

A rewrite method that first translates each term into BooleanClause.Occur.SHOULD clause in a BooleanQuery, but the scores are only computed as the boost.

Link copied to clipboard

A rewrite method that first translates each term into BooleanClause.Occur.SHOULD clause in a BooleanQuery, and keeps the scores as computed by the query.

Properties

Link copied to clipboard
open val field: String

Returns the field name for this query

Link copied to clipboard
open val termsCount: Long

Functions

Link copied to clipboard
open fun createWeight(searcher: IndexSearcher, scoreMode: ScoreMode, boost: Float): Weight

Expert: Constructs an appropriate Weight implementation for this query.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Override and implement query instance equivalence properly in a subclass. This is required so that QueryCache works properly.

Link copied to clipboard

Constructs an enumeration that expands the pattern term. This method should only be called if the field exists (ie, implementations can assume the field does exist). This method never returns null. The returned TermsEnum is positioned to the first matching term.

Link copied to clipboard
open override fun hashCode(): Int

Override and implement query hash code properly in a subclass. This is required so that [ ] works properly.

Link copied to clipboard
open override fun rewrite(indexSearcher: IndexSearcher): Query

To rewrite to a simpler form, instead return a simpler enum from .getTermsEnum. For example, to rewrite to a single term, return a SingleTermsEnum

Link copied to clipboard
open override fun toString(): String

Prints a query to a string.

abstract fun toString(field: String?): String

Prints a query to a string, with field assumed to be the default field and omitted.

Link copied to clipboard
abstract fun visit(visitor: QueryVisitor)

Recurse through the query tree, visiting any child queries.