Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement parameter auto_generate_synonyms_phrase_query #1620

Open
wants to merge 1 commit into
base: release-branch.v7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 26 additions & 15 deletions search_queries_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ package elastic
// For more details, see
// https://www.elastic.co/guide/en/elasticsearch/reference/7.0/query-dsl-match-query.html
type MatchQuery struct {
name string
text interface{}
operator string // or / and
analyzer string
boost *float64
fuzziness string
prefixLength *int
maxExpansions *int
minimumShouldMatch string
fuzzyRewrite string
lenient *bool
fuzzyTranspositions *bool
zeroTermsQuery string
cutoffFrequency *float64
queryName string
name string
text interface{}
operator string // or / and
analyzer string
boost *float64
fuzziness string
prefixLength *int
maxExpansions *int
minimumShouldMatch string
fuzzyRewrite string
lenient *bool
fuzzyTranspositions *bool
zeroTermsQuery string
cutoffFrequency *float64
queryName string
autoGenerateSynonymsPhraseQuery *bool
}

// NewMatchQuery creates and initializes a new MatchQuery.
Expand Down Expand Up @@ -132,6 +133,13 @@ func (q *MatchQuery) QueryName(queryName string) *MatchQuery {
return q
}

// AutoGenerateSynonymsPhraseQuery indicates whether match phrase queries
// will be automatically created for multi-term synonyms.
func (q *MatchQuery) AutoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery bool) *MatchQuery {
q.autoGenerateSynonymsPhraseQuery = &autoGenerateSynonymsPhraseQuery
return q
}

// Source returns JSON for the function score query.
func (q *MatchQuery) Source() (interface{}, error) {
// {"match":{"name":{"query":"value","type":"boolean/phrase"}}}
Expand Down Expand Up @@ -184,6 +192,9 @@ func (q *MatchQuery) Source() (interface{}, error) {
if q.queryName != "" {
query["_name"] = q.queryName
}
if q.autoGenerateSynonymsPhraseQuery != nil {
query["auto_generate_synonyms_phrase_query"] = *q.autoGenerateSynonymsPhraseQuery
}

return source, nil
}
49 changes: 30 additions & 19 deletions search_queries_multi_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@ import (
// For more details, see
// https://www.elastic.co/guide/en/elasticsearch/reference/7.0/query-dsl-multi-match-query.html
type MultiMatchQuery struct {
text interface{}
fields []string
fieldBoosts map[string]*float64
typ string // best_fields, boolean, most_fields, cross_fields, phrase, phrase_prefix
operator string // AND or OR
analyzer string
boost *float64
slop *int
fuzziness string
prefixLength *int
maxExpansions *int
minimumShouldMatch string
rewrite string
fuzzyRewrite string
tieBreaker *float64
lenient *bool
cutoffFrequency *float64
zeroTermsQuery string
queryName string
text interface{}
fields []string
fieldBoosts map[string]*float64
typ string // best_fields, boolean, most_fields, cross_fields, phrase, phrase_prefix
operator string // AND or OR
analyzer string
boost *float64
slop *int
fuzziness string
prefixLength *int
maxExpansions *int
minimumShouldMatch string
rewrite string
fuzzyRewrite string
tieBreaker *float64
lenient *bool
cutoffFrequency *float64
zeroTermsQuery string
queryName string
autoGenerateSynonymsPhraseQuery *bool
}

// MultiMatchQuery creates and initializes a new MultiMatchQuery.
Expand Down Expand Up @@ -182,6 +183,13 @@ func (q *MultiMatchQuery) QueryName(queryName string) *MultiMatchQuery {
return q
}

// AutoGenerateSynonymsPhraseQuery indicates whether match phrase queries
// will be automatically created for multi-term synonyms.
func (q *MultiMatchQuery) AutoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery bool) *MultiMatchQuery {
q.autoGenerateSynonymsPhraseQuery = &autoGenerateSynonymsPhraseQuery
return q
}

// Source returns JSON for the query.
func (q *MultiMatchQuery) Source() (interface{}, error) {
//
Expand Down Expand Up @@ -266,5 +274,8 @@ func (q *MultiMatchQuery) Source() (interface{}, error) {
if q.queryName != "" {
multiMatch["_name"] = q.queryName
}
if q.autoGenerateSynonymsPhraseQuery != nil {
multiMatch["auto_generate_synonyms_phrase_query"] = *q.autoGenerateSynonymsPhraseQuery
}
return source, nil
}