Commit 07fae03c63c8fc2861650089a78df8739b6bbc82
1 parent
c7b63c10
Exists in
master
and in
19 other branches
Added support for attributes in highlight tags - closes #801
Showing
3 changed files
with
7 additions
and
1 deletions
Show diff stats
CHANGELOG.md
lib/searchkick/query.rb
... | ... | @@ -542,7 +542,7 @@ module Searchkick |
542 | 542 | if options[:highlight].is_a?(Hash) |
543 | 543 | if (tag = options[:highlight][:tag]) |
544 | 544 | payload[:highlight][:pre_tags] = [tag] |
545 | - payload[:highlight][:post_tags] = [tag.to_s.gsub(/\A</, "</")] | |
545 | + payload[:highlight][:post_tags] = [tag.to_s.gsub(/\A<(\w+).+/, "</\\1>")] | |
546 | 546 | end |
547 | 547 | |
548 | 548 | if (fragment_size = options[:highlight][:fragment_size]) | ... | ... |
test/highlight_test.rb
... | ... | @@ -11,6 +11,11 @@ class HighlightTest < Minitest::Test |
11 | 11 | assert_equal "Two Door <strong>Cinema</strong> Club", Product.search("cinema", fields: [:name], highlight: {tag: "<strong>"}).first.search_highlights[:name] |
12 | 12 | end |
13 | 13 | |
14 | + def test_tag_class | |
15 | + store_names ["Two Door Cinema Club"] | |
16 | + assert_equal "Two Door <strong class='classy'>Cinema</strong> Club", Product.search("cinema", fields: [:name], highlight: {tag: "<strong class='classy'>"}).first.search_highlights[:name] | |
17 | + end | |
18 | + | |
14 | 19 | def test_multiple_fields |
15 | 20 | store [{name: "Two Door Cinema Club", color: "Cinema Orange"}] |
16 | 21 | highlights = Product.search("cinema", fields: [:name, :color], highlight: true).first.search_highlights | ... | ... |