org.elasticsearch.index.query
Class QueryStringQueryBuilder

java.lang.Object
  extended by org.elasticsearch.index.query.BaseQueryBuilder
      extended by org.elasticsearch.index.query.QueryStringQueryBuilder
All Implemented Interfaces:
ToXContent, BoostableQueryBuilder<QueryStringQueryBuilder>, QueryBuilder

public class QueryStringQueryBuilder
extends BaseQueryBuilder
implements BoostableQueryBuilder<QueryStringQueryBuilder>

A query that parses a query string and runs it. There are two modes that this operates. The first, when no field is added (using field(String), will run the query once and non prefixed fields will use the defaultField(String) set. The second, when one or more fields are added (using field(String)), will run the parsed query against the provided fields, and combine them either using DisMax or a plain boolean query (see useDisMax(boolean)).

(shay.baon)


Nested Class Summary
static class QueryStringQueryBuilder.Operator
           
 
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.MapParams, ToXContent.Params
 
Field Summary
 
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
 
Constructor Summary
QueryStringQueryBuilder(String queryString)
           
 
Method Summary
 QueryStringQueryBuilder allowLeadingWildcard(boolean allowLeadingWildcard)
          Should leading wildcards be allowed or not.
 QueryStringQueryBuilder analyzer(String analyzer)
          The optional analyzer used to analyze the query string.
 QueryStringQueryBuilder analyzeWildcard(boolean analyzeWildcard)
          Set to true to enable analysis on wildcard and prefix queries.
 QueryStringQueryBuilder autoGeneratePhraseQueries(boolean autoGeneratePhraseQueries)
          Set to true if phrase queries will be automatically generated when the analyzer returns more than one term from whitespace delimited text.
 QueryStringQueryBuilder boost(float boost)
          Sets the boost for this query.
 QueryStringQueryBuilder defaultField(String defaultField)
          The default field to run against when no prefix field is specified.
 QueryStringQueryBuilder defaultOperator(QueryStringQueryBuilder.Operator defaultOperator)
          Sets the boolean operator of the query parser used to parse the query string.
protected  void doXContent(XContentBuilder builder, ToXContent.Params params)
           
 QueryStringQueryBuilder enablePositionIncrements(boolean enablePositionIncrements)
          Set to true to enable position increments in result query.
 QueryStringQueryBuilder field(String field)
          Adds a field to run the query string against.
 QueryStringQueryBuilder field(String field, float boost)
          Adds a field to run the query string against with a specific boost.
 QueryStringQueryBuilder fuzzyMaxExpansions(int fuzzyMaxExpansions)
           
 QueryStringQueryBuilder fuzzyMinSim(float fuzzyMinSim)
          Set the minimum similarity for fuzzy queries.
 QueryStringQueryBuilder fuzzyPrefixLength(int fuzzyPrefixLength)
          Set the minimum similarity for fuzzy queries.
 QueryStringQueryBuilder fuzzyRewrite(String fuzzyRewrite)
           
 QueryStringQueryBuilder lenient(Boolean lenient)
          Sets the query string parser to be lenient when parsing field values, defaults to the index setting and if not set, defaults to false.
 QueryStringQueryBuilder lowercaseExpandedTerms(boolean lowercaseExpandedTerms)
          Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically lower-cased or not.
 QueryStringQueryBuilder minimumShouldMatch(String minimumShouldMatch)
           
 QueryStringQueryBuilder phraseSlop(int phraseSlop)
          Sets the default slop for phrases.
 QueryStringQueryBuilder quoteAnalyzer(String analyzer)
          The optional analyzer used to analyze the query string for phrase searches.
 QueryStringQueryBuilder quoteFieldSuffix(String quoteFieldSuffix)
          An optional field name suffix to automatically try and add to the field searched when using quoted text.
 QueryStringQueryBuilder rewrite(String rewrite)
           
 QueryStringQueryBuilder tieBreaker(float tieBreaker)
          When more than one field is used with the query string, and combined queries are using dis max, control the tie breaker for it.
 QueryStringQueryBuilder useDisMax(boolean useDisMax)
          When more than one field is used with the query string, should queries be combined using dis max, or boolean query.
 
Methods inherited from class org.elasticsearch.index.query.BaseQueryBuilder
buildAsBytes, buildAsBytes, toString, toXContent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QueryStringQueryBuilder

public QueryStringQueryBuilder(String queryString)
Method Detail

defaultField

public QueryStringQueryBuilder defaultField(String defaultField)
The default field to run against when no prefix field is specified. Only relevant when not explicitly adding fields the query string will run against.


field

public QueryStringQueryBuilder field(String field)
Adds a field to run the query string against.


field

public QueryStringQueryBuilder field(String field,
                                     float boost)
Adds a field to run the query string against with a specific boost.


useDisMax

public QueryStringQueryBuilder useDisMax(boolean useDisMax)
When more than one field is used with the query string, should queries be combined using dis max, or boolean query. Defaults to dis max (true).


tieBreaker

public QueryStringQueryBuilder tieBreaker(float tieBreaker)
When more than one field is used with the query string, and combined queries are using dis max, control the tie breaker for it.


defaultOperator

public QueryStringQueryBuilder defaultOperator(QueryStringQueryBuilder.Operator defaultOperator)
Sets the boolean operator of the query parser used to parse the query string.

In default mode (FieldQueryBuilder.Operator.OR) terms without any modifiers are considered optional: for example capital of Hungary is equal to capital OR of OR Hungary.

In FieldQueryBuilder.Operator.AND mode terms are considered to be in conjunction: the above mentioned query is parsed as capital AND of AND Hungary


analyzer

public QueryStringQueryBuilder analyzer(String analyzer)
The optional analyzer used to analyze the query string. Note, if a field has search analyzer defined for it, then it will be used automatically. Defaults to the smart search analyzer.


quoteAnalyzer

public QueryStringQueryBuilder quoteAnalyzer(String analyzer)
The optional analyzer used to analyze the query string for phrase searches. Note, if a field has search (quote) analyzer defined for it, then it will be used automatically. Defaults to the smart search analyzer.


autoGeneratePhraseQueries

public QueryStringQueryBuilder autoGeneratePhraseQueries(boolean autoGeneratePhraseQueries)
Set to true if phrase queries will be automatically generated when the analyzer returns more than one term from whitespace delimited text. NOTE: this behavior may not be suitable for all languages.

Set to false if phrase queries should only be generated when surrounded by double quotes.


allowLeadingWildcard

public QueryStringQueryBuilder allowLeadingWildcard(boolean allowLeadingWildcard)
Should leading wildcards be allowed or not. Defaults to true.


lowercaseExpandedTerms

public QueryStringQueryBuilder lowercaseExpandedTerms(boolean lowercaseExpandedTerms)
Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically lower-cased or not. Default is true.


enablePositionIncrements

public QueryStringQueryBuilder enablePositionIncrements(boolean enablePositionIncrements)
Set to true to enable position increments in result query. Defaults to true.

When set, result phrase and multi-phrase queries will be aware of position increments. Useful when e.g. a StopFilter increases the position increment of the token that follows an omitted token.


fuzzyMinSim

public QueryStringQueryBuilder fuzzyMinSim(float fuzzyMinSim)
Set the minimum similarity for fuzzy queries. Default is 0.5f.


fuzzyPrefixLength

public QueryStringQueryBuilder fuzzyPrefixLength(int fuzzyPrefixLength)
Set the minimum similarity for fuzzy queries. Default is 0.5f.


fuzzyMaxExpansions

public QueryStringQueryBuilder fuzzyMaxExpansions(int fuzzyMaxExpansions)

fuzzyRewrite

public QueryStringQueryBuilder fuzzyRewrite(String fuzzyRewrite)

phraseSlop

public QueryStringQueryBuilder phraseSlop(int phraseSlop)
Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is zero.


analyzeWildcard

public QueryStringQueryBuilder analyzeWildcard(boolean analyzeWildcard)
Set to true to enable analysis on wildcard and prefix queries.


rewrite

public QueryStringQueryBuilder rewrite(String rewrite)

minimumShouldMatch

public QueryStringQueryBuilder minimumShouldMatch(String minimumShouldMatch)

boost

public QueryStringQueryBuilder boost(float boost)
Sets the boost for this query. Documents matching this query will (in addition to the normal weightings) have their score multiplied by the boost provided.

Specified by:
boost in interface BoostableQueryBuilder<QueryStringQueryBuilder>

quoteFieldSuffix

public QueryStringQueryBuilder quoteFieldSuffix(String quoteFieldSuffix)
An optional field name suffix to automatically try and add to the field searched when using quoted text.


lenient

public QueryStringQueryBuilder lenient(Boolean lenient)
Sets the query string parser to be lenient when parsing field values, defaults to the index setting and if not set, defaults to false.


doXContent

protected void doXContent(XContentBuilder builder,
                          ToXContent.Params params)
                   throws IOException
Specified by:
doXContent in class BaseQueryBuilder
Throws:
IOException


Copyright © 2009-2012. All Rights Reserved.