forked from ankane/searchkick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
highlight_test.rb
46 lines (39 loc) · 1.51 KB
/
highlight_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require_relative "test_helper"
class TestHighlight < Minitest::Test
def test_basic
store_names ["Two Door Cinema Club"]
assert_equal "Two Door <em>Cinema</em> Club", Product.search("cinema", fields: [:name], highlight: true).with_details.first[1][:highlight][:name]
end
def test_tag
store_names ["Two Door Cinema Club"]
assert_equal "Two Door <strong>Cinema</strong> Club", Product.search("cinema", fields: [:name], highlight: {tag: "<strong>"}).with_details.first[1][:highlight][:name]
end
def test_multiple_fields
store [{name: "Two Door Cinema Club", color: "Cinema Orange"}]
highlight = Product.search("cinema", fields: [:name, :color], highlight: true).with_details.first[1][:highlight]
assert_equal "Two Door <em>Cinema</em> Club", highlight[:name]
assert_equal "<em>Cinema</em> Orange", highlight[:color]
end
def test_multiple_words
store_names ["Hello World Hello"]
assert_equal "<em>Hello</em> World <em>Hello</em>", Product.search("hello", fields: [:name], highlight: true).with_details.first[1][:highlight][:name]
end
def test_json
store_names ["Two Door Cinema Club"]
json = {
query: {
match: {
_all: "cinema"
}
},
highlight: {
pre_tags: ["<strong>"],
post_tags: ["</strong>"],
fields: {
"name.analyzed" => {}
}
}
}
assert_equal "Two Door <strong>Cinema</strong> Club", Product.search(json: json).with_details.first[1][:highlight][:"name.analyzed"]
end
end