diff options
Diffstat (limited to 'vendor/gopkg.in/olivere/elastic.v5/search_queries_match.go')
-rw-r--r-- | vendor/gopkg.in/olivere/elastic.v5/search_queries_match.go | 71 |
1 files changed, 23 insertions, 48 deletions
diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_queries_match.go b/vendor/gopkg.in/olivere/elastic.v5/search_queries_match.go index 0c44c5d57..1f2f16f69 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/search_queries_match.go +++ b/vendor/gopkg.in/olivere/elastic.v5/search_queries_match.go @@ -16,16 +16,13 @@ package elastic type MatchQuery struct { name string text interface{} - typ string // boolean, phrase, phrase_prefix operator string // or / and analyzer string boost *float64 - slop *int fuzziness string prefixLength *int maxExpansions *int minimumShouldMatch string - rewrite string fuzzyRewrite string lenient *bool fuzzyTranspositions *bool @@ -39,22 +36,6 @@ func NewMatchQuery(name string, text interface{}) *MatchQuery { return &MatchQuery{name: name, text: text} } -// NewMatchPhraseQuery creates and initializes a new MatchQuery of type phrase. -func NewMatchPhraseQuery(name string, text interface{}) *MatchQuery { - return &MatchQuery{name: name, text: text, typ: "phrase"} -} - -// NewMatchPhrasePrefixQuery creates and initializes a new MatchQuery of type phrase_prefix. -func NewMatchPhrasePrefixQuery(name string, text interface{}) *MatchQuery { - return &MatchQuery{name: name, text: text, typ: "phrase_prefix"} -} - -// Type can be "boolean", "phrase", or "phrase_prefix". Defaults to "boolean". -func (q *MatchQuery) Type(typ string) *MatchQuery { - q.typ = typ - return q -} - // Operator sets the operator to use when using a boolean query. // Can be "AND" or "OR" (default). func (q *MatchQuery) Operator(operator string) *MatchQuery { @@ -69,18 +50,6 @@ func (q *MatchQuery) Analyzer(analyzer string) *MatchQuery { return q } -// Boost sets the boost to apply to this query. -func (q *MatchQuery) Boost(boost float64) *MatchQuery { - q.boost = &boost - return q -} - -// Slop sets the phrase slop if evaluated to a phrase query type. -func (q *MatchQuery) Slop(slop int) *MatchQuery { - q.slop = &slop - return q -} - // Fuzziness sets the fuzziness when evaluated to a fuzzy query type. // Defaults to "AUTO". func (q *MatchQuery) Fuzziness(fuzziness string) *MatchQuery { @@ -88,6 +57,8 @@ func (q *MatchQuery) Fuzziness(fuzziness string) *MatchQuery { return q } +// PrefixLength sets the length of a length of common (non-fuzzy) +// prefix for fuzzy match queries. It must be non-negative. func (q *MatchQuery) PrefixLength(prefixLength int) *MatchQuery { q.prefixLength = &prefixLength return q @@ -109,21 +80,28 @@ func (q *MatchQuery) CutoffFrequency(cutoff float64) *MatchQuery { return q } +// MinimumShouldMatch sets the optional minimumShouldMatch value to +// apply to the query. func (q *MatchQuery) MinimumShouldMatch(minimumShouldMatch string) *MatchQuery { q.minimumShouldMatch = minimumShouldMatch return q } -func (q *MatchQuery) Rewrite(rewrite string) *MatchQuery { - q.rewrite = rewrite - return q -} - +// FuzzyRewrite sets the fuzzy_rewrite parameter controlling how the +// fuzzy query will get rewritten. func (q *MatchQuery) FuzzyRewrite(fuzzyRewrite string) *MatchQuery { q.fuzzyRewrite = fuzzyRewrite return q } +// FuzzyTranspositions sets whether transpositions are supported in +// fuzzy queries. +// +// The default metric used by fuzzy queries to determine a match is +// the Damerau-Levenshtein distance formula which supports transpositions. +// Setting transposition to false will +// * switch to classic Levenshtein distance. +// * If not set, Damerau-Levenshtein distance metric will be used. func (q *MatchQuery) FuzzyTranspositions(fuzzyTranspositions bool) *MatchQuery { q.fuzzyTranspositions = &fuzzyTranspositions return q @@ -141,6 +119,12 @@ func (q *MatchQuery) ZeroTermsQuery(zeroTermsQuery string) *MatchQuery { return q } +// Boost sets the boost to apply to this query. +func (q *MatchQuery) Boost(boost float64) *MatchQuery { + q.boost = &boost + return q +} + // QueryName sets the query name for the filter that can be used when // searching for matched filters per hit. func (q *MatchQuery) QueryName(queryName string) *MatchQuery { @@ -161,21 +145,12 @@ func (q *MatchQuery) Source() (interface{}, error) { query["query"] = q.text - if q.typ != "" { - query["type"] = q.typ - } if q.operator != "" { query["operator"] = q.operator } if q.analyzer != "" { query["analyzer"] = q.analyzer } - if q.boost != nil { - query["boost"] = *q.boost - } - if q.slop != nil { - query["slop"] = *q.slop - } if q.fuzziness != "" { query["fuzziness"] = q.fuzziness } @@ -188,9 +163,6 @@ func (q *MatchQuery) Source() (interface{}, error) { if q.minimumShouldMatch != "" { query["minimum_should_match"] = q.minimumShouldMatch } - if q.rewrite != "" { - query["rewrite"] = q.rewrite - } if q.fuzzyRewrite != "" { query["fuzzy_rewrite"] = q.fuzzyRewrite } @@ -206,6 +178,9 @@ func (q *MatchQuery) Source() (interface{}, error) { if q.cutoffFrequency != nil { query["cutoff_frequency"] = q.cutoffFrequency } + if q.boost != nil { + query["boost"] = *q.boost + } if q.queryName != "" { query["_name"] = q.queryName } |