All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.senseidb.search.client.req.query.StringQuery Maven / Gradle / Ivy

The newest version!
package com.senseidb.search.client.req.query;

import java.util.Arrays;
import java.util.List;

import com.senseidb.search.client.json.CustomJsonHandler;
import com.senseidb.search.client.json.JsonField;
import com.senseidb.search.client.req.Operator;

/**
 * 

* A query that uses a query parser in order to parse its content. Here is an * example: *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ParameterDescription
queryThe actual query to be parsed.
default_fieldThe default field for query terms if no prefix field is specified. * Defaults to the _all field.
default_operatorThe default operator used if no explicit operator is specified. For * example, with a default operator of OR, the query * capital of Hungary is translated to * capital OR of OR Hungary, and with default operator of * AND, the same query is translated to * capital AND of AND Hungary. The default value is OR * .
analyzerThe analyzer name used to analyze the query string.
allow_leading_wildcardWhen set, * or ? are allowed as the first * character. Defaults to true.
lowercase_expanded_termsWhether terms of wildcard, prefix, fuzzy, and range queries are to be * automatically lower-cased or not (since they are not analyzed). Default it * true.
enable_position_incrementsSet to true to enable position increments in result queries. * Defaults to true.
fuzzy_prefix_lengthSet the prefix length for fuzzy queries. Default is 0.
fuzzy_min_simSet the minimum similarity for fuzzy queries. Defaults to * 0.5
phrase_slopSets the default slop for phrases. If zero, then exact phrase matches are * required. Default value is 0.
boostSets the boost value of the query. Defaults to 1.0.
analyze_wildcardBy default, wildcards terms in a query string are not analyzed. By * setting this value to true, a best effort will be made to * analyze those as well.
auto_generate_phrase_queriesDefault to false.
minimum_should_matchA percent value (for example 20%) controlling how many * “should” clauses in the resulting boolean query should match.
*

* When a multi term query is being generated, one can control how it gets * rewritten using the rewrite parameter. *

* *

Multi Field

*

* The query_string query can also run against multiple fields. The * idea of running the query_string query against multiple fields * is by internally creating several queries for the same query string, each * with default_field that match the fields provided. Since several * queries are generated, combining them can be automatically done either using * a dis_max query or a simple bool query. For example * (the name is boosted by 5 using ^5 notation): *

* *

* When running the query_string query against multiple fields, the * following additional parameters are allowed: *

* * * * * * * * * * * * * * * * * * *
ParameterDescription
use_dis_maxShould the queries be combined using dis_max (set it to * true), or a bool query (set it to * false). Defaults to true.
tie_breakerWhen using dis_max, the disjunction max tie breaker. * Defaults to 0.
*

* The fields parameter can also include pattern based field names, allowing to * automatically expand to the relevant fields (dynamically introduced fields * included). For example: *

* */ @SuppressWarnings("unused") @CustomJsonHandler(QueryJsonHandler.class) public class StringQuery extends Query { @JsonField("default_field") private String defaultField; private String query; @JsonField("default_operator") private Operator defaultOperator; @JsonField("allow_leading_wildCard") private Boolean allowLeadingWildCard; @JsonField("lowercase_expanded_terms") private Boolean lowercaseExpandedTerms; @JsonField("enable_position_increments") private Boolean enablePositionIncrements; @JsonField("fuzzy_prefix_length") private String fuzzyPrefixLength; @JsonField("fuzzy_min_sim") private Double fuzzyMinSim; @JsonField("phrase_slop") private Integer phraseSlop; private Double boost = 1.0; @JsonField("auto_generate_phrase_queries") private Boolean autoGeneratePhraseQueries; private List fields; @JsonField("use_dis_max") private Boolean useDisMax; @JsonField("tie_breaker") private Integer tieBreaker; public static Builder builder() { return new Builder(); } public static class Builder { private final StringQuery query = new StringQuery(); public Builder defaultField(String defaultField) { query.defaultField = defaultField; return this; } public Builder allowLeadingWildCard(boolean allowLeadingWildCard) { query.allowLeadingWildCard = allowLeadingWildCard; return this; } public Builder defaultOperator(Operator op) { query.defaultOperator = op; return this; } public Builder lowercaseExpandedTerms(boolean lowercaseExpandedTerms) { query.lowercaseExpandedTerms = lowercaseExpandedTerms; return this; } public Builder enablePositionIncrements(boolean enablePositionIncrements) { query.enablePositionIncrements = enablePositionIncrements; return this; } public Builder fuzzyPrefixLength(String fuzzyPrefixLength) { query.fuzzyPrefixLength = fuzzyPrefixLength; return this; } public Builder fuzzyMinSim(double fuzzyMinSim) { query.fuzzyMinSim = fuzzyMinSim; return this; } public Builder phraseSlop(int phraseSlop) { query.phraseSlop = phraseSlop; return this; } public Builder boost(double boost) { query.boost = boost; return this; } public Builder autoGeneratePhraseQueries(boolean autoGeneratePhraseQueries) { query.autoGeneratePhraseQueries = autoGeneratePhraseQueries; return this; } public Builder fields(String... fields) { query.fields = Arrays.asList(fields); return this; } public Builder useDisMax(boolean useDisMax) { query.useDisMax = useDisMax; return this; } public Builder tieBreaker(int tieBreaker) { query.tieBreaker = tieBreaker; return this; } public Builder query(String queryParam) { this.query.query = queryParam; return this; } public StringQuery build() { return query; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy