Skip to content

CBB-1170: support _name on multi-match #14

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

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions query_multi_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,24 @@ type multiMatchParams struct {
MinMatch string `structs:"minimum_should_match,omitempty"`
ZeroTerms ZeroTerms `structs:"zero_terms_query,string,omitempty"`
Slp uint16 `structs:"slop,omitempty"`
Name string `structs:"_name,omitempty"`
}

// MultiMatch creates a new query of type "multi_match"
func MultiMatch(simpleQuery ...interface{}) *MultiMatchQuery {
return newMultiMatch(simpleQuery...)
func MultiMatch(fieldNames []string, simpleQuery ...interface{}) *MultiMatchQuery {
return newMultiMatch(fieldNames, simpleQuery...)
}

func newMultiMatch(simpleQuery ...interface{}) *MultiMatchQuery {
func newMultiMatch(fieldNames []string, simpleQuery ...interface{}) *MultiMatchQuery {
var qry interface{}
if len(simpleQuery) > 0 {
qry = simpleQuery[len(simpleQuery)-1]
}

return &MultiMatchQuery{
params: multiMatchParams{
Qry: qry,
Fields: fieldNames,
Qry: qry,
},
}
}
Expand All @@ -68,12 +70,6 @@ func (q *MultiMatchQuery) Analyzer(a string) *MultiMatchQuery {
return q
}

// Fields sets the fields used in the query
func (q *MultiMatchQuery) Fields(a ...string) *MultiMatchQuery {
q.params.Fields = append(q.params.Fields, a...)
return q
}

// AutoGenerateSynonymsPhraseQuery sets the "auto_generate_synonyms_phrase_query"
// boolean.
func (q *MultiMatchQuery) AutoGenerateSynonymsPhraseQuery(b bool) *MultiMatchQuery {
Expand Down Expand Up @@ -164,6 +160,11 @@ func (q *MultiMatchQuery) ZeroTermsQuery(s ZeroTerms) *MultiMatchQuery {
return q
}

func (q *MultiMatchQuery) Name(name string) Mappable {
q.params.Name = name
return q
}

// MatchType is an enumeration type representing supported values for a
// multi match query's "type" parameter.
type MultiMatchType uint8
Expand Down
9 changes: 5 additions & 4 deletions query_multi_match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func TestMultiMatch(t *testing.T) {
runMapTests(t, []mapTest{
{
"simple multi_match",
MultiMatch("value1", "value2").Fields("title"),
MultiMatch([]string{"title"}, "value1", "value2"),
map[string]interface{}{
"multi_match": map[string]interface{}{
"fields": []string{"title"},
Expand All @@ -18,10 +18,9 @@ func TestMultiMatch(t *testing.T) {
},
{
"multi_match all params",
MultiMatch("original").
MultiMatch([]string{"title", "body"}, "original").
Query("test").
Analyzer("stop").
Fields("title", "body").
AutoGenerateSynonymsPhraseQuery(true).
Fuzziness("AUTO").
MaxExpansions(16).
Expand All @@ -35,7 +34,8 @@ func TestMultiMatch(t *testing.T) {
Type(MatchTypePhrase).
MinimumShouldMatch("3<90%").
Slop(2).
ZeroTermsQuery(ZeroTermsAll),
ZeroTermsQuery(ZeroTermsAll).
Name("query_name"),
map[string]interface{}{
"multi_match": map[string]interface{}{
"analyzer": "stop",
Expand All @@ -55,6 +55,7 @@ func TestMultiMatch(t *testing.T) {
"slop": 2,
"query": "test",
"fields": []string{"title", "body"},
"_name": "query_name",
},
},
},
Expand Down
Loading