rescore.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2012-present Oliver Eilhard. All rights reserved.
  2. // Use of this source code is governed by a MIT-license.
  3. // See http://olivere.mit-license.org/license.txt for details.
  4. package elastic
  5. type Rescore struct {
  6. rescorer Rescorer
  7. windowSize *int
  8. defaultRescoreWindowSize *int
  9. }
  10. func NewRescore() *Rescore {
  11. return &Rescore{}
  12. }
  13. func (r *Rescore) WindowSize(windowSize int) *Rescore {
  14. r.windowSize = &windowSize
  15. return r
  16. }
  17. func (r *Rescore) IsEmpty() bool {
  18. return r.rescorer == nil
  19. }
  20. func (r *Rescore) Rescorer(rescorer Rescorer) *Rescore {
  21. r.rescorer = rescorer
  22. return r
  23. }
  24. func (r *Rescore) Source() (interface{}, error) {
  25. source := make(map[string]interface{})
  26. if r.windowSize != nil {
  27. source["window_size"] = *r.windowSize
  28. } else if r.defaultRescoreWindowSize != nil {
  29. source["window_size"] = *r.defaultRescoreWindowSize
  30. }
  31. rescorerSrc, err := r.rescorer.Source()
  32. if err != nil {
  33. return nil, err
  34. }
  35. source[r.rescorer.Name()] = rescorerSrc
  36. return source, nil
  37. }