From e6abd4e6aecca759b9bb4bad4d670fe6e4145691 Mon Sep 17 00:00:00 2001 From: CascadingRadium Date: Wed, 16 Oct 2024 16:12:12 +0530 Subject: [PATCH] Add missing API's for a few queries --- search/query/multi_phrase.go | 18 +++++++++++++----- search/query/phrase.go | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/search/query/multi_phrase.go b/search/query/multi_phrase.go index d1144d908..f5aa53979 100644 --- a/search/query/multi_phrase.go +++ b/search/query/multi_phrase.go @@ -27,7 +27,7 @@ import ( type MultiPhraseQuery struct { Terms [][]string `json:"terms"` - Field string `json:"field,omitempty"` + FieldVal string `json:"field,omitempty"` BoostVal *Boost `json:"boost,omitempty"` Fuzziness int `json:"fuzziness"` } @@ -43,8 +43,8 @@ type MultiPhraseQuery struct { // IncludeTermVectors set to true. func NewMultiPhraseQuery(terms [][]string, field string) *MultiPhraseQuery { return &MultiPhraseQuery{ - Terms: terms, - Field: field, + Terms: terms, + FieldVal: field, } } @@ -61,8 +61,16 @@ func (q *MultiPhraseQuery) Boost() float64 { return q.BoostVal.Value() } +func (q *MultiPhraseQuery) Field() string { + return q.FieldVal +} + +func (q *MultiPhraseQuery) SetField(f string) { + q.FieldVal = f +} + func (q *MultiPhraseQuery) Searcher(ctx context.Context, i index.IndexReader, m mapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error) { - return searcher.NewMultiPhraseSearcher(ctx, i, q.Terms, q.Fuzziness, q.Field, q.BoostVal.Value(), options) + return searcher.NewMultiPhraseSearcher(ctx, i, q.Terms, q.Fuzziness, q.FieldVal, q.BoostVal.Value(), options) } func (q *MultiPhraseQuery) Validate() error { @@ -80,7 +88,7 @@ func (q *MultiPhraseQuery) UnmarshalJSON(data []byte) error { return err } q.Terms = tmp.Terms - q.Field = tmp.Field + q.FieldVal = tmp.FieldVal q.BoostVal = tmp.BoostVal q.Fuzziness = tmp.Fuzziness return nil diff --git a/search/query/phrase.go b/search/query/phrase.go index 9092e72d0..f3c04a482 100644 --- a/search/query/phrase.go +++ b/search/query/phrase.go @@ -27,7 +27,7 @@ import ( type PhraseQuery struct { Terms []string `json:"terms"` - Field string `json:"field,omitempty"` + FieldVal string `json:"field,omitempty"` BoostVal *Boost `json:"boost,omitempty"` Fuzziness int `json:"fuzziness"` } @@ -40,8 +40,8 @@ type PhraseQuery struct { // IncludeTermVectors set to true. func NewPhraseQuery(terms []string, field string) *PhraseQuery { return &PhraseQuery{ - Terms: terms, - Field: field, + Terms: terms, + FieldVal: field, } } @@ -58,8 +58,16 @@ func (q *PhraseQuery) Boost() float64 { return q.BoostVal.Value() } +func (q *PhraseQuery) SetField(f string) { + q.FieldVal = f +} + +func (q *PhraseQuery) Field() string { + return q.FieldVal +} + func (q *PhraseQuery) Searcher(ctx context.Context, i index.IndexReader, m mapping.IndexMapping, options search.SearcherOptions) (search.Searcher, error) { - return searcher.NewPhraseSearcher(ctx, i, q.Terms, q.Fuzziness, q.Field, q.BoostVal.Value(), options) + return searcher.NewPhraseSearcher(ctx, i, q.Terms, q.Fuzziness, q.FieldVal, q.BoostVal.Value(), options) } func (q *PhraseQuery) Validate() error { @@ -77,7 +85,7 @@ func (q *PhraseQuery) UnmarshalJSON(data []byte) error { return err } q.Terms = tmp.Terms - q.Field = tmp.Field + q.FieldVal = tmp.FieldVal q.BoostVal = tmp.BoostVal q.Fuzziness = tmp.Fuzziness return nil