From eaf977d1382d0502b067afbe4161c8db86bfa0bb Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 17 Mar 2020 21:29:34 -0700 Subject: [PATCH] Added highlight [skip ci] --- lib/searchkick/relation.rb | 11 ++++++++++- test/highlight_test.rb | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) 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