Commit 689c28c22ec52f651d654c06c2166d8284885197
1 parent
305e7994
Exists in
master
and in
17 other branches
Fixed error when suggestions empty
Showing
4 changed files
with
11 additions
and
2 deletions
Show diff stats
CHANGELOG.md
lib/searchkick/query.rb
... | ... | @@ -127,7 +127,8 @@ module Searchkick |
127 | 127 | term: term, |
128 | 128 | scope_results: options[:scope_results], |
129 | 129 | total_entries: options[:total_entries], |
130 | - index_mapping: @index_mapping | |
130 | + index_mapping: @index_mapping, | |
131 | + suggest: options[:suggest] | |
131 | 132 | } |
132 | 133 | |
133 | 134 | if options[:debug] | ... | ... |
lib/searchkick/results.rb
... | ... | @@ -90,7 +90,7 @@ module Searchkick |
90 | 90 | def suggestions |
91 | 91 | if response["suggest"] |
92 | 92 | response["suggest"].values.flat_map { |v| v.first["options"] }.sort_by { |o| -o["score"] }.map { |o| o["text"] }.uniq |
93 | - elsif options[:term] == "*" | |
93 | + elsif options[:suggest] || options[:term] == "*" # TODO remove 2nd term | |
94 | 94 | [] |
95 | 95 | else |
96 | 96 | raise "Pass `suggest: true` to the search method for suggestions" | ... | ... |
test/suggest_test.rb
... | ... | @@ -21,6 +21,10 @@ class SuggestTest < Minitest::Test |
21 | 21 | assert_suggest "How to catch a big tiger shar", "how to catch a big tiger shark", fields: [:name] |
22 | 22 | end |
23 | 23 | |
24 | + def test_empty | |
25 | + assert_suggest "hi", nil | |
26 | + end | |
27 | + | |
24 | 28 | def test_without_option |
25 | 29 | store_names ["hi"] # needed to prevent ElasticsearchException - seed 668 |
26 | 30 | assert_raises(RuntimeError) { Product.search("hi").suggestions } | ... | ... |