Commit 1418ccac8a1ca35efcb7e9f624e4dde17c64dcca
1 parent
857b853c
Exists in
master
and in
21 other branches
Fixed suggestions for partial matches - closes #190
Showing
3 changed files
with
14 additions
and
1 deletions
Show diff stats
CHANGELOG.md
lib/searchkick/query.rb
... | ... | @@ -254,8 +254,12 @@ module Searchkick |
254 | 254 | # suggestions |
255 | 255 | if options[:suggest] |
256 | 256 | suggest_fields = (searchkick_options[:suggest] || []).map(&:to_s) |
257 | + | |
257 | 258 | # intersection |
258 | - suggest_fields = suggest_fields & options[:fields].map(&:to_s) if options[:fields] | |
259 | + if options[:fields] | |
260 | + suggest_fields = suggest_fields & options[:fields].map{|v| (v.is_a?(Hash) ? v.keys.first : v).to_s } | |
261 | + end | |
262 | + | |
259 | 263 | if suggest_fields.any? |
260 | 264 | payload[:suggest] = {text: term} |
261 | 265 | suggest_fields.each do |field| | ... | ... |
test/suggest_test.rb
... | ... | @@ -56,6 +56,11 @@ class TestSuggest < Minitest::Unit::TestCase |
56 | 56 | assert_suggest "shar", "shark", fields: [:name, :unknown] |
57 | 57 | end |
58 | 58 | |
59 | + def test_fields_word_start | |
60 | + store_names ["Great White Shark", "Hammerhead Shark", "Tiger Shark"] | |
61 | + assert_suggest "How Big is a Tigre Shar", "how big is a tiger shark", fields: [{name: :word_start}] | |
62 | + end | |
63 | + | |
59 | 64 | protected |
60 | 65 | |
61 | 66 | def assert_suggest(term, expected, options = {}) | ... | ... |