Skip to content

Commit 1783ebb

Browse files
CBB-1170: support _name on multi-match (#14)
1 parent 274a03a commit 1783ebb

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

query_multi_match.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,24 @@ type multiMatchParams struct {
3434
MinMatch string `structs:"minimum_should_match,omitempty"`
3535
ZeroTerms ZeroTerms `structs:"zero_terms_query,string,omitempty"`
3636
Slp uint16 `structs:"slop,omitempty"`
37+
Name string `structs:"_name,omitempty"`
3738
}
3839

3940
// MultiMatch creates a new query of type "multi_match"
40-
func MultiMatch(simpleQuery ...interface{}) *MultiMatchQuery {
41-
return newMultiMatch(simpleQuery...)
41+
func MultiMatch(fieldNames []string, simpleQuery ...interface{}) *MultiMatchQuery {
42+
return newMultiMatch(fieldNames, simpleQuery...)
4243
}
4344

44-
func newMultiMatch(simpleQuery ...interface{}) *MultiMatchQuery {
45+
func newMultiMatch(fieldNames []string, simpleQuery ...interface{}) *MultiMatchQuery {
4546
var qry interface{}
4647
if len(simpleQuery) > 0 {
4748
qry = simpleQuery[len(simpleQuery)-1]
4849
}
4950

5051
return &MultiMatchQuery{
5152
params: multiMatchParams{
52-
Qry: qry,
53+
Fields: fieldNames,
54+
Qry: qry,
5355
},
5456
}
5557
}
@@ -68,12 +70,6 @@ func (q *MultiMatchQuery) Analyzer(a string) *MultiMatchQuery {
6870
return q
6971
}
7072

71-
// Fields sets the fields used in the query
72-
func (q *MultiMatchQuery) Fields(a ...string) *MultiMatchQuery {
73-
q.params.Fields = append(q.params.Fields, a...)
74-
return q
75-
}
76-
7773
// AutoGenerateSynonymsPhraseQuery sets the "auto_generate_synonyms_phrase_query"
7874
// boolean.
7975
func (q *MultiMatchQuery) AutoGenerateSynonymsPhraseQuery(b bool) *MultiMatchQuery {
@@ -164,6 +160,11 @@ func (q *MultiMatchQuery) ZeroTermsQuery(s ZeroTerms) *MultiMatchQuery {
164160
return q
165161
}
166162

163+
func (q *MultiMatchQuery) Name(name string) Mappable {
164+
q.params.Name = name
165+
return q
166+
}
167+
167168
// MatchType is an enumeration type representing supported values for a
168169
// multi match query's "type" parameter.
169170
type MultiMatchType uint8

query_multi_match_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func TestMultiMatch(t *testing.T) {
88
runMapTests(t, []mapTest{
99
{
1010
"simple multi_match",
11-
MultiMatch("value1", "value2").Fields("title"),
11+
MultiMatch([]string{"title"}, "value1", "value2"),
1212
map[string]interface{}{
1313
"multi_match": map[string]interface{}{
1414
"fields": []string{"title"},
@@ -18,10 +18,9 @@ func TestMultiMatch(t *testing.T) {
1818
},
1919
{
2020
"multi_match all params",
21-
MultiMatch("original").
21+
MultiMatch([]string{"title", "body"}, "original").
2222
Query("test").
2323
Analyzer("stop").
24-
Fields("title", "body").
2524
AutoGenerateSynonymsPhraseQuery(true).
2625
Fuzziness("AUTO").
2726
MaxExpansions(16).
@@ -35,7 +34,8 @@ func TestMultiMatch(t *testing.T) {
3534
Type(MatchTypePhrase).
3635
MinimumShouldMatch("3<90%").
3736
Slop(2).
38-
ZeroTermsQuery(ZeroTermsAll),
37+
ZeroTermsQuery(ZeroTermsAll).
38+
Name("query_name"),
3939
map[string]interface{}{
4040
"multi_match": map[string]interface{}{
4141
"analyzer": "stop",
@@ -55,6 +55,7 @@ func TestMultiMatch(t *testing.T) {
5555
"slop": 2,
5656
"query": "test",
5757
"fields": []string{"title", "body"},
58+
"_name": "query_name",
5859
},
5960
},
6061
},

0 commit comments

Comments
 (0)