Commit eaf977d1382d0502b067afbe4161c8db86bfa0bb
1 parent
342879c9
Exists in
relation
and in
1 other branch
Added highlight [skip ci]
Showing
2 changed files
with
11 additions
and
1 deletions
Show diff stats
lib/searchkick/relation.rb
... | ... | @@ -9,7 +9,7 @@ module Searchkick |
9 | 9 | :took, :error, :model_name, :entry_name, :total_count, :total_entries, |
10 | 10 | :current_page, :per_page, :limit_value, :total_pages, :num_pages, |
11 | 11 | :offset_value, :previous_page, :prev_page, :next_page, :first_page?, :last_page?, |
12 | - :out_of_range?, :hits, :response, :to_a, :first, :scroll | |
12 | + :out_of_range?, :hits, :response, :to_a, :first, :scroll, :highlights | |
13 | 13 | |
14 | 14 | def initialize(klass, term = "*", **options) |
15 | 15 | unknown_keywords = options.keys - [:aggs, :block, :body, :body_options, :boost, |
... | ... | @@ -245,6 +245,15 @@ module Searchkick |
245 | 245 | self |
246 | 246 | end |
247 | 247 | |
248 | + def highlight(value) | |
249 | + spawn.highlight!(value) | |
250 | + end | |
251 | + | |
252 | + def highlight!(value) | |
253 | + options[:highlight] = value | |
254 | + self | |
255 | + end | |
256 | + | |
248 | 257 | # same as Active Record |
249 | 258 | def inspect |
250 | 259 | entries = results.first(11).map!(&:inspect) | ... | ... |
test/highlight_test.rb
... | ... | @@ -4,6 +4,7 @@ class HighlightTest < Minitest::Test |
4 | 4 | def test_basic |
5 | 5 | store_names ["Two Door Cinema Club"] |
6 | 6 | assert_equal "Two Door <em>Cinema</em> Club", Product.search("cinema", highlight: true).highlights.first[:name] |
7 | + assert_equal "Two Door <em>Cinema</em> Club", Product.search("cinema", relation: true).highlight(true).highlights.first[:name] | |
7 | 8 | end |
8 | 9 | |
9 | 10 | def test_with_highlights | ... | ... |