Commit 07fae03c63c8fc2861650089a78df8739b6bbc82

Authored by Andrew Kane
1 parent c7b63c10

Added support for attributes in highlight tags - closes #801

CHANGELOG.md
1 1 ## 2.0.2 [unreleased]
2 2  
3 3 - Fixed potentially silent errors in reindex job
  4 +- Added support for attributes in highlight tags
4 5  
5 6 ## 2.0.1
6 7  
... ...
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 &lt; 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
... ...