Package org.elasticsearch.index.query
Class CommonTermsQueryBuilder
- java.lang.Object
-
- org.elasticsearch.index.query.AbstractQueryBuilder<CommonTermsQueryBuilder>
-
- org.elasticsearch.index.query.CommonTermsQueryBuilder
-
- All Implemented Interfaces:
NamedWriteable
,Writeable
,ToXContent
,ToXContentObject
,QueryBuilder
,Rewriteable<QueryBuilder>
public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQueryBuilder>
CommonTermsQuery query is a query that executes high-frequency terms in a optional sub-query to prevent slow queries due to "common" terms like stopwords. This query basically builds 2 queries off the#add(Term) added
terms where low-frequency terms are added to a required boolean clause and high-frequency terms are added to an optional boolean clause. The optional clause is only executed if the required "low-frequency' clause matches.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
-
Field Summary
Fields Modifier and Type Field Description static float
DEFAULT_CUTOFF_FREQ
static boolean
DEFAULT_DISABLE_COORD
static Operator
DEFAULT_HIGH_FREQ_OCCUR
static Operator
DEFAULT_LOW_FREQ_OCCUR
static java.lang.String
NAME
-
Fields inherited from class org.elasticsearch.index.query.AbstractQueryBuilder
boost, BOOST_FIELD, DEFAULT_BOOST, NAME_FIELD, queryName
-
Fields inherited from interface org.elasticsearch.index.query.Rewriteable
MAX_REWRITE_ROUNDS
-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Constructor Description CommonTermsQueryBuilder(java.lang.String fieldName, java.lang.Object text)
Constructs a new common terms query.CommonTermsQueryBuilder(StreamInput in)
Read from a stream.
-
Method Summary
Modifier and Type Method Description java.lang.String
analyzer()
CommonTermsQueryBuilder
analyzer(java.lang.String analyzer)
Explicitly set the analyzer to use.float
cutoffFrequency()
CommonTermsQueryBuilder
cutoffFrequency(float cutoffFrequency)
Sets the cutoff document frequency for high / low frequent terms.protected boolean
doEquals(CommonTermsQueryBuilder other)
Indicates whether some otherQueryBuilder
object of the same type is "equal to" this one.protected int
doHashCode()
protected org.apache.lucene.search.Query
doToQuery(QueryShardContext context)
protected void
doWriteTo(StreamOutput out)
protected void
doXContent(XContentBuilder builder, ToXContent.Params params)
java.lang.String
fieldName()
static CommonTermsQueryBuilder
fromXContent(XContentParser parser)
java.lang.String
getWriteableName()
Returns the name of the writeable objectjava.lang.String
highFreqMinimumShouldMatch()
CommonTermsQueryBuilder
highFreqMinimumShouldMatch(java.lang.String highFreqMinimumShouldMatch)
Sets the minimum number of high frequent query terms that need to match in order to produce a hit when there are no low frequent terms.Operator
highFreqOperator()
CommonTermsQueryBuilder
highFreqOperator(Operator operator)
Sets the operator to use for terms with a high document frequency (greater than or equal tocutoffFrequency(float)
.java.lang.String
lowFreqMinimumShouldMatch()
CommonTermsQueryBuilder
lowFreqMinimumShouldMatch(java.lang.String lowFreqMinimumShouldMatch)
Sets the minimum number of low frequent query terms that need to match in order to produce a hit.Operator
lowFreqOperator()
CommonTermsQueryBuilder
lowFreqOperator(Operator operator)
Sets the operator to use for terms with a low document frequency (less thancutoffFrequency(float)
.java.lang.Object
value()
-
Methods inherited from class org.elasticsearch.index.query.AbstractQueryBuilder
addValidationError, boost, boost, checkNegativeBoost, declareStandardFields, doRewrite, equals, extractInnerHitBuilders, getName, hashCode, parseInnerQueryBuilder, printBoostAndQueryName, queryName, queryName, requireValue, rewrite, throwParsingExceptionOnMultipleFields, toFilter, toQuery, toString, toString, toXContent, writeTo
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
-
-
-
Field Detail
-
NAME
public static final java.lang.String NAME
- See Also:
- Constant Field Values
-
DEFAULT_CUTOFF_FREQ
public static final float DEFAULT_CUTOFF_FREQ
- See Also:
- Constant Field Values
-
DEFAULT_HIGH_FREQ_OCCUR
public static final Operator DEFAULT_HIGH_FREQ_OCCUR
-
DEFAULT_LOW_FREQ_OCCUR
public static final Operator DEFAULT_LOW_FREQ_OCCUR
-
DEFAULT_DISABLE_COORD
public static final boolean DEFAULT_DISABLE_COORD
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CommonTermsQueryBuilder
public CommonTermsQueryBuilder(java.lang.String fieldName, java.lang.Object text)
Constructs a new common terms query.
-
CommonTermsQueryBuilder
public CommonTermsQueryBuilder(StreamInput in) throws java.io.IOException
Read from a stream.- Throws:
java.io.IOException
-
-
Method Detail
-
doWriteTo
protected void doWriteTo(StreamOutput out) throws java.io.IOException
- Specified by:
doWriteTo
in classAbstractQueryBuilder<CommonTermsQueryBuilder>
- Throws:
java.io.IOException
-
fieldName
public java.lang.String fieldName()
-
value
public java.lang.Object value()
-
highFreqOperator
public CommonTermsQueryBuilder highFreqOperator(Operator operator)
Sets the operator to use for terms with a high document frequency (greater than or equal tocutoffFrequency(float)
. Defaults toAND
.
-
highFreqOperator
public Operator highFreqOperator()
-
lowFreqOperator
public CommonTermsQueryBuilder lowFreqOperator(Operator operator)
Sets the operator to use for terms with a low document frequency (less thancutoffFrequency(float)
. Defaults toAND
.
-
lowFreqOperator
public Operator lowFreqOperator()
-
analyzer
public CommonTermsQueryBuilder analyzer(java.lang.String analyzer)
Explicitly set the analyzer to use. Defaults to use explicit mapping config for the field, or, if not set, the default search analyzer.
-
analyzer
public java.lang.String analyzer()
-
cutoffFrequency
public CommonTermsQueryBuilder cutoffFrequency(float cutoffFrequency)
Sets the cutoff document frequency for high / low frequent terms. A value in [0..1] (or absolute number >=1) representing the maximum threshold of a terms document frequency to be considered a low frequency term. Defaults to{@value #DEFAULT_CUTOFF_FREQ}
-
cutoffFrequency
public float cutoffFrequency()
-
highFreqMinimumShouldMatch
public CommonTermsQueryBuilder highFreqMinimumShouldMatch(java.lang.String highFreqMinimumShouldMatch)
Sets the minimum number of high frequent query terms that need to match in order to produce a hit when there are no low frequent terms.
-
highFreqMinimumShouldMatch
public java.lang.String highFreqMinimumShouldMatch()
-
lowFreqMinimumShouldMatch
public CommonTermsQueryBuilder lowFreqMinimumShouldMatch(java.lang.String lowFreqMinimumShouldMatch)
Sets the minimum number of low frequent query terms that need to match in order to produce a hit.
-
lowFreqMinimumShouldMatch
public java.lang.String lowFreqMinimumShouldMatch()
-
doXContent
protected void doXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
doXContent
in classAbstractQueryBuilder<CommonTermsQueryBuilder>
- Throws:
java.io.IOException
-
fromXContent
public static CommonTermsQueryBuilder fromXContent(XContentParser parser) throws java.io.IOException
- Throws:
java.io.IOException
-
getWriteableName
public java.lang.String getWriteableName()
Description copied from interface:NamedWriteable
Returns the name of the writeable object
-
doToQuery
protected org.apache.lucene.search.Query doToQuery(QueryShardContext context) throws java.io.IOException
- Specified by:
doToQuery
in classAbstractQueryBuilder<CommonTermsQueryBuilder>
- Throws:
java.io.IOException
-
doHashCode
protected int doHashCode()
- Specified by:
doHashCode
in classAbstractQueryBuilder<CommonTermsQueryBuilder>
-
doEquals
protected boolean doEquals(CommonTermsQueryBuilder other)
Description copied from class:AbstractQueryBuilder
Indicates whether some otherQueryBuilder
object of the same type is "equal to" this one.- Specified by:
doEquals
in classAbstractQueryBuilder<CommonTermsQueryBuilder>
-
-