diff --git a/lib/searchkick/relation.rb b/lib/searchkick/relation.rb
index 909b8a9..b95516c 100644
--- a/lib/searchkick/relation.rb
+++ b/lib/searchkick/relation.rb
@@ -9,7 +9,7 @@ module Searchkick
:took, :error, :model_name, :entry_name, :total_count, :total_entries,
:current_page, :per_page, :limit_value, :total_pages, :num_pages,
:offset_value, :previous_page, :prev_page, :next_page, :first_page?, :last_page?,
- :out_of_range?, :hits, :response, :to_a, :first, :scroll
+ :out_of_range?, :hits, :response, :to_a, :first, :scroll, :highlights
def initialize(klass, term = "*", **options)
unknown_keywords = options.keys - [:aggs, :block, :body, :body_options, :boost,
@@ -245,6 +245,15 @@ module Searchkick
self
end
+ def highlight(value)
+ spawn.highlight!(value)
+ end
+
+ def highlight!(value)
+ options[:highlight] = value
+ self
+ end
+
# same as Active Record
def inspect
entries = results.first(11).map!(&:inspect)
diff --git a/test/highlight_test.rb b/test/highlight_test.rb
index b6ec16d..ae8e404 100644
--- a/test/highlight_test.rb
+++ b/test/highlight_test.rb
@@ -4,6 +4,7 @@ class HighlightTest < Minitest::Test
def test_basic
store_names ["Two Door Cinema Club"]
assert_equal "Two Door Cinema Club", Product.search("cinema", highlight: true).highlights.first[:name]
+ assert_equal "Two Door Cinema Club", Product.search("cinema", relation: true).highlight(true).highlights.first[:name]
end
def test_with_highlights
--
libgit2 0.21.0