Commit ce45f050ddae1a36cd28659a5cb7355271ea7bcf
1 parent
6eaa7bfc
Exists in
relation
and in
1 other branch
Added suggest [skip ci]
Showing
2 changed files
with
10 additions
and
0 deletions
Show diff stats
lib/searchkick/relation.rb
@@ -345,6 +345,15 @@ module Searchkick | @@ -345,6 +345,15 @@ module Searchkick | ||
345 | self | 345 | self |
346 | end | 346 | end |
347 | 347 | ||
348 | + def suggest(value) | ||
349 | + spawn.suggest!(value) | ||
350 | + end | ||
351 | + | ||
352 | + def suggest!(value) | ||
353 | + options[:suggest] = value | ||
354 | + self | ||
355 | + end | ||
356 | + | ||
348 | # same as Active Record | 357 | # same as Active Record |
349 | def inspect | 358 | def inspect |
350 | entries = results.first(11).map!(&:inspect) | 359 | entries = results.first(11).map!(&:inspect) |
test/suggest_test.rb
@@ -9,6 +9,7 @@ class SuggestTest < Minitest::Test | @@ -9,6 +9,7 @@ class SuggestTest < Minitest::Test | ||
9 | def test_basic | 9 | def test_basic |
10 | store_names ["Great White Shark", "Hammerhead Shark", "Tiger Shark"] | 10 | store_names ["Great White Shark", "Hammerhead Shark", "Tiger Shark"] |
11 | assert_suggest "How Big is a Tigre Shar", "how big is a tiger shark", fields: [:name] | 11 | assert_suggest "How Big is a Tigre Shar", "how big is a tiger shark", fields: [:name] |
12 | + assert Product.search("How Big is a Tigre Shar", relation: true).suggest(true).fields(:name).suggestions.include?("how big is a tiger shark") | ||
12 | end | 13 | end |
13 | 14 | ||
14 | def test_perfect | 15 | def test_perfect |