Skip to content

Commit

Permalink
Add missing API's for a few queries (#2089)
Browse files Browse the repository at this point in the history
- Without these API's, these queries are falsely recognised as
`Non-Fieldable` queries.
  • Loading branch information
CascadingRadium authored Nov 14, 2024
1 parent 81609f8 commit d002624
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
18 changes: 13 additions & 5 deletions search/query/multi_phrase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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,
}
}

Expand All @@ -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 {
Expand All @@ -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
Expand Down
18 changes: 13 additions & 5 deletions search/query/phrase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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,
}
}

Expand All @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit d002624

Please sign in to comment.