Commit 243419c62d5641322d1270e6290dc4681b3592a7

Authored by Andrew
1 parent a3f52dbd

Fixed error with suggestions and match all - fixes #1042

lib/searchkick/query.rb
... ... @@ -112,7 +112,8 @@ module Searchkick
112 112 json: !@json.nil?,
113 113 match_suffix: @match_suffix,
114 114 highlighted_fields: @highlighted_fields || [],
115   - misspellings: @misspellings
  115 + misspellings: @misspellings,
  116 + term: term
116 117 }
117 118  
118 119 if options[:debug]
... ...
lib/searchkick/results.rb
... ... @@ -77,6 +77,8 @@ module Searchkick
77 77 def suggestions
78 78 if response["suggest"]
79 79 response["suggest"].values.flat_map { |v| v.first["options"] }.sort_by { |o| -o["score"] }.map { |o| o["text"] }.uniq
  80 + elsif options[:term] == "*"
  81 + []
80 82 else
81 83 raise "Pass `suggest: true` to the search method for suggestions"
82 84 end
... ...
test/suggest_test.rb
... ... @@ -77,6 +77,10 @@ class SuggestTest < Minitest::Test
77 77 assert_raises(ArgumentError) { Searchkick.search("How Big is a Tigre Shar", suggest: true) }
78 78 end
79 79  
  80 + def test_star
  81 + assert_equal [], Product.search("*", suggest: true).suggestions
  82 + end
  83 +
80 84 protected
81 85  
82 86 def assert_suggest(term, expected, options = {})
... ...