forked from ankane/searchkick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatch_test.rb
156 lines (121 loc) · 3.64 KB
/
match_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# encoding: utf-8
require_relative "test_helper"
class TestMatch < Minitest::Test
# exact
def test_match
store_names ["Whole Milk", "Fat Free Milk", "Milk"]
assert_search "milk", ["Milk", "Whole Milk", "Fat Free Milk"]
end
def test_case
store_names ["Whole Milk", "Fat Free Milk", "Milk"]
assert_search "MILK", ["Milk", "Whole Milk", "Fat Free Milk"]
end
def test_cheese_space_in_index
store_names ["Pepper Jack Cheese Skewers"]
assert_search "pepperjack cheese skewers", ["Pepper Jack Cheese Skewers"]
end
# def test_cheese_space_in_query
# store_names ["Pepperjack Cheese Skewers"]
# assert_search "pepper jack cheese skewers", ["Pepperjack Cheese Skewers"]
# end
def test_middle_token
store_names ["Dish Washer Amazing Organic Soap"]
assert_search "dish soap", ["Dish Washer Amazing Organic Soap"]
end
def test_middle_token_wine
store_names ["Beringer Wine Founders Estate Chardonnay"]
assert_search "beringer chardonnay", ["Beringer Wine Founders Estate Chardonnay"]
end
def test_percent
store_names ["1% Milk", "2% Milk", "Whole Milk"]
assert_search "1%", ["1% Milk"]
end
# ascii
def test_jalapenos
store_names ["Jalapeño"]
assert_search "jalapeno", ["Jalapeño"]
end
def test_swedish
store_names ["ÅÄÖ"]
assert_search "aao", ["ÅÄÖ"]
end
# stemming
def test_stemming
store_names ["Whole Milk", "Fat Free Milk", "Milk"]
assert_search "milks", ["Milk", "Whole Milk", "Fat Free Milk"]
end
# fuzzy
def test_misspelling_sriracha
store_names ["Sriracha"]
assert_search "siracha", ["Sriracha"]
end
def test_misspelling_multiple
store_names ["Greek Yogurt", "Green Onions"]
assert_search "greed", ["Greek Yogurt", "Green Onions"]
end
def test_short_word
store_names ["Finn"]
assert_search "fin", ["Finn"]
end
def test_edit_distance_two
store_names ["Bingo"]
assert_search "bin", []
assert_search "bingooo", []
assert_search "mango", []
end
def test_edit_distance_one
store_names ["Bingo"]
assert_search "bing", ["Bingo"]
assert_search "bingoo", ["Bingo"]
assert_search "ringo", ["Bingo"]
end
def test_edit_distance_long_word
store_names ["thisisareallylongword"]
assert_search "thisisareallylongwor", ["thisisareallylongword"] # missing letter
assert_search "thisisareelylongword", [] # edit distance = 2
end
def test_misspelling_tabasco
store_names ["Tabasco"]
assert_search "tobasco", ["Tabasco"]
end
def test_misspelling_zucchini
store_names ["Zucchini"]
assert_search "zuchini", ["Zucchini"]
end
def test_misspelling_ziploc
store_names ["Ziploc"]
assert_search "zip lock", ["Ziploc"]
end
# spaces
def test_spaces_in_field
store_names ["Red Bull"]
assert_search "redbull", ["Red Bull"]
end
def test_spaces_in_query
store_names ["Dishwasher"]
assert_search "dish washer", ["Dishwasher"]
end
def test_spaces_three_words
store_names ["Dish Washer Soap", "Dish Washer"]
assert_search "dish washer soap", ["Dish Washer Soap"]
end
def test_spaces_stemming
store_names ["Almond Milk"]
assert_search "almondmilks", ["Almond Milk"]
end
def test_all
store_names ["Product A", "Product B"]
assert_search "*", ["Product A", "Product B"]
end
def test_no_arguments
assert_equal [], Product.search.to_a
end
def test_no_term
store_names ["Product A"]
assert_equal ["Product A"], Product.search(where: {name: "Product A"}).map(&:name)
end
def test_to_be_or_not_to_be
store_names ["to be or not to be"]
assert_search "to be", ["to be or not to be"]
end
end