diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index e577b93..34b8f75 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -112,7 +112,8 @@ module Searchkick json: !@json.nil?, match_suffix: @match_suffix, highlighted_fields: @highlighted_fields || [], - misspellings: @misspellings + misspellings: @misspellings, + term: term } if options[:debug] diff --git a/lib/searchkick/results.rb b/lib/searchkick/results.rb index 9ccfe4f..e4af90a 100644 --- a/lib/searchkick/results.rb +++ b/lib/searchkick/results.rb @@ -77,6 +77,8 @@ module Searchkick def suggestions if response["suggest"] response["suggest"].values.flat_map { |v| v.first["options"] }.sort_by { |o| -o["score"] }.map { |o| o["text"] }.uniq + elsif options[:term] == "*" + [] else raise "Pass `suggest: true` to the search method for suggestions" end diff --git a/test/suggest_test.rb b/test/suggest_test.rb index 9319ea2..083ee3c 100644 --- a/test/suggest_test.rb +++ b/test/suggest_test.rb @@ -77,6 +77,10 @@ class SuggestTest < Minitest::Test assert_raises(ArgumentError) { Searchkick.search("How Big is a Tigre Shar", suggest: true) } end + def test_star + assert_equal [], Product.search("*", suggest: true).suggestions + end + protected def assert_suggest(term, expected, options = {}) -- libgit2 0.21.0