suggester_completion_fuzzy_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2012-2015 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. import (
  6. "encoding/json"
  7. "testing"
  8. )
  9. func TestFuzzyCompletionSuggesterSource(t *testing.T) {
  10. s := NewFuzzyCompletionSuggester("song-suggest").
  11. Text("n").
  12. Field("suggest").
  13. Fuzziness(2)
  14. data, err := json.Marshal(s.Source(true))
  15. if err != nil {
  16. t.Fatalf("marshaling to JSON failed: %v", err)
  17. }
  18. got := string(data)
  19. expected := `{"song-suggest":{"text":"n","completion":{"field":"suggest","fuzziness":2}}}`
  20. if got != expected {
  21. t.Errorf("expected\n%s\n,got:\n%s", expected, got)
  22. }
  23. }
  24. func TestFuzzyCompletionSuggesterWithStringFuzzinessSource(t *testing.T) {
  25. s := NewFuzzyCompletionSuggester("song-suggest").
  26. Text("n").
  27. Field("suggest").
  28. Fuzziness("1..4")
  29. data, err := json.Marshal(s.Source(true))
  30. if err != nil {
  31. t.Fatalf("marshaling to JSON failed: %v", err)
  32. }
  33. got := string(data)
  34. expected := `{"song-suggest":{"text":"n","completion":{"field":"suggest","fuzziness":"1..4"}}}`
  35. if got != expected {
  36. t.Errorf("expected\n%s\n,got:\n%s", expected, got)
  37. }
  38. }