Commit ce45f050ddae1a36cd28659a5cb7355271ea7bcf

Authored by Andrew Kane
1 parent 6eaa7bfc

Added suggest [skip ci]

lib/searchkick/relation.rb
... ... @@ -345,6 +345,15 @@ module Searchkick
345 345 self
346 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 357 # same as Active Record
349 358 def inspect
350 359 entries = results.first(11).map!(&:inspect)
... ...
test/suggest_test.rb
... ... @@ -9,6 +9,7 @@ class SuggestTest < Minitest::Test
9 9 def test_basic
10 10 store_names ["Great White Shark", "Hammerhead Shark", "Tiger Shark"]
11 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 13 end
13 14  
14 15 def test_perfect
... ...