searchkick 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/CONTRIBUTING.md +9 -7
- data/README.md +86 -24
- data/lib/searchkick/bulk_indexer.rb +1 -1
- data/lib/searchkick/index_options.rb +12 -0
- data/lib/searchkick/model.rb +2 -2
- data/lib/searchkick/query.rb +36 -21
- data/lib/searchkick/record_data.rb +2 -2
- data/lib/searchkick/results.rb +2 -2
- data/lib/searchkick/version.rb +1 -1
- metadata +8 -106
- data/.github/ISSUE_TEMPLATE.md +0 -7
- data/.gitignore +0 -22
- data/.travis.yml +0 -33
- data/Gemfile +0 -16
- data/Rakefile +0 -16
- data/benchmark/Gemfile +0 -24
- data/benchmark/index.rb +0 -99
- data/benchmark/search.rb +0 -48
- data/docs/Searchkick-3-Upgrade.md +0 -57
- data/searchkick.gemspec +0 -30
- data/test/aggs_test.rb +0 -217
- data/test/autocomplete_test.rb +0 -81
- data/test/boost_test.rb +0 -225
- data/test/callbacks_test.rb +0 -59
- data/test/ci/before_install.sh +0 -17
- data/test/errors_test.rb +0 -19
- data/test/gemfiles/activerecord42.gemfile +0 -7
- data/test/gemfiles/activerecord50.gemfile +0 -7
- data/test/gemfiles/activerecord51.gemfile +0 -7
- data/test/gemfiles/apartment.gemfile +0 -8
- data/test/gemfiles/cequel.gemfile +0 -8
- data/test/gemfiles/mongoid5.gemfile +0 -7
- data/test/gemfiles/mongoid6.gemfile +0 -12
- data/test/gemfiles/nobrainer.gemfile +0 -8
- data/test/gemfiles/parallel_tests.gemfile +0 -8
- data/test/geo_shape_test.rb +0 -171
- data/test/highlight_test.rb +0 -109
- data/test/index_test.rb +0 -168
- data/test/inheritance_test.rb +0 -82
- data/test/language_test.rb +0 -79
- data/test/marshal_test.rb +0 -13
- data/test/match_test.rb +0 -293
- data/test/misspellings_test.rb +0 -56
- data/test/model_test.rb +0 -40
- data/test/multi_search_test.rb +0 -37
- data/test/multi_tenancy_test.rb +0 -22
- data/test/order_test.rb +0 -40
- data/test/pagination_test.rb +0 -96
- data/test/partial_reindex_test.rb +0 -65
- data/test/query_test.rb +0 -43
- data/test/reindex_test.rb +0 -87
- data/test/reindex_v2_job_test.rb +0 -27
- data/test/routing_test.rb +0 -23
- data/test/should_index_test.rb +0 -32
- data/test/similar_test.rb +0 -28
- data/test/sql_test.rb +0 -190
- data/test/suggest_test.rb +0 -100
- data/test/support/kaminari.yml +0 -21
- data/test/synonyms_test.rb +0 -69
- data/test/test_helper.rb +0 -593
- data/test/where_test.rb +0 -249
data/test/callbacks_test.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
class CallbacksTest < Minitest::Test
|
4
|
-
def test_true_create
|
5
|
-
Searchkick.callbacks(true) do
|
6
|
-
store_names ["Product A", "Product B"]
|
7
|
-
end
|
8
|
-
Product.searchkick_index.refresh
|
9
|
-
assert_search "product", ["Product A", "Product B"]
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_false_create
|
13
|
-
Searchkick.callbacks(false) do
|
14
|
-
store_names ["Product A", "Product B"]
|
15
|
-
end
|
16
|
-
Product.searchkick_index.refresh
|
17
|
-
assert_search "product", []
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_bulk_create
|
21
|
-
Searchkick.callbacks(:bulk) do
|
22
|
-
store_names ["Product A", "Product B"]
|
23
|
-
end
|
24
|
-
Product.searchkick_index.refresh
|
25
|
-
assert_search "product", ["Product A", "Product B"]
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_queue
|
29
|
-
skip unless defined?(ActiveJob) && defined?(Redis)
|
30
|
-
|
31
|
-
reindex_queue = Product.searchkick_index.reindex_queue
|
32
|
-
reindex_queue.clear
|
33
|
-
|
34
|
-
Searchkick.callbacks(:queue) do
|
35
|
-
store_names ["Product A", "Product B"]
|
36
|
-
end
|
37
|
-
Product.searchkick_index.refresh
|
38
|
-
assert_search "product", [], load: false, conversions: false
|
39
|
-
assert_equal 2, reindex_queue.length
|
40
|
-
|
41
|
-
Searchkick::ProcessQueueJob.perform_later(class_name: "Product")
|
42
|
-
Product.searchkick_index.refresh
|
43
|
-
assert_search "product", ["Product A", "Product B"], load: false
|
44
|
-
assert_equal 0, reindex_queue.length
|
45
|
-
|
46
|
-
Searchkick.callbacks(:queue) do
|
47
|
-
Product.where(name: "Product B").destroy_all
|
48
|
-
Product.create!(name: "Product C")
|
49
|
-
end
|
50
|
-
Product.searchkick_index.refresh
|
51
|
-
assert_search "product", ["Product A", "Product B"], load: false
|
52
|
-
assert_equal 2, reindex_queue.length
|
53
|
-
|
54
|
-
Searchkick::ProcessQueueJob.perform_later(class_name: "Product")
|
55
|
-
Product.searchkick_index.refresh
|
56
|
-
assert_search "product", ["Product A", "Product C"], load: false
|
57
|
-
assert_equal 0, reindex_queue.length
|
58
|
-
end
|
59
|
-
end
|
data/test/ci/before_install.sh
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
|
3
|
-
set -e
|
4
|
-
|
5
|
-
gem install bundler
|
6
|
-
|
7
|
-
if [[ $ELASTICSEARCH_VERSION == 1* ]]; then
|
8
|
-
curl -L -O https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-$ELASTICSEARCH_VERSION.tar.gz
|
9
|
-
elif [[ $ELASTICSEARCH_VERSION == 2* ]]; then
|
10
|
-
curl -L -O https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/$ELASTICSEARCH_VERSION/elasticsearch-$ELASTICSEARCH_VERSION.tar.gz
|
11
|
-
else
|
12
|
-
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-$ELASTICSEARCH_VERSION.tar.gz
|
13
|
-
fi
|
14
|
-
tar -xvf elasticsearch-$ELASTICSEARCH_VERSION.tar.gz
|
15
|
-
cd elasticsearch-$ELASTICSEARCH_VERSION/bin
|
16
|
-
./elasticsearch -d
|
17
|
-
wget -O- --waitretry=1 --tries=60 --retry-connrefused -v http://127.0.0.1:9200/
|
data/test/errors_test.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
class ErrorsTest < Minitest::Test
|
4
|
-
def test_bulk_import_raises_error
|
5
|
-
valid_dog = Product.create(name: "2016-01-02")
|
6
|
-
invalid_dog = Product.create(name: "Ol' One-Leg")
|
7
|
-
index = Searchkick::Index.new "dogs", mappings: {
|
8
|
-
dog: {
|
9
|
-
properties: {
|
10
|
-
name: {type: "date"}
|
11
|
-
}
|
12
|
-
}
|
13
|
-
}
|
14
|
-
index.store valid_dog
|
15
|
-
assert_raises(Searchkick::ImportError) do
|
16
|
-
index.bulk_index [valid_dog, invalid_dog]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/test/geo_shape_test.rb
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
class GeoShapeTest < Minitest::Test
|
4
|
-
def setup
|
5
|
-
Region.destroy_all
|
6
|
-
store [
|
7
|
-
{
|
8
|
-
name: "Region A",
|
9
|
-
text: "The witch had a cat",
|
10
|
-
territory: {
|
11
|
-
type: "polygon",
|
12
|
-
coordinates: [[[30, 40], [35, 45], [40, 40], [40, 30], [30, 30], [30, 40]]]
|
13
|
-
}
|
14
|
-
},
|
15
|
-
{
|
16
|
-
name: "Region B",
|
17
|
-
text: "and a very tall hat",
|
18
|
-
territory: {
|
19
|
-
type: "polygon",
|
20
|
-
coordinates: [[[50, 60], [55, 65], [60, 60], [60, 50], [50, 50], [50, 60]]]
|
21
|
-
}
|
22
|
-
},
|
23
|
-
{
|
24
|
-
name: "Region C",
|
25
|
-
text: "and long ginger hair which she wore in a plait",
|
26
|
-
territory: {
|
27
|
-
type: "polygon",
|
28
|
-
coordinates: [[[10, 20], [15, 25], [20, 20], [20, 10], [10, 10], [10, 20]]]
|
29
|
-
}
|
30
|
-
}
|
31
|
-
], Region
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_circle
|
35
|
-
assert_search "*", ["Region A"], {
|
36
|
-
where: {
|
37
|
-
territory: {
|
38
|
-
geo_shape: {
|
39
|
-
type: "circle",
|
40
|
-
coordinates: {lat: 28.0, lon: 38.0},
|
41
|
-
radius: "444000m"
|
42
|
-
}
|
43
|
-
}
|
44
|
-
}
|
45
|
-
}, Region
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_envelope
|
49
|
-
assert_search "*", ["Region A"], {
|
50
|
-
where: {
|
51
|
-
territory: {
|
52
|
-
geo_shape: {
|
53
|
-
type: "envelope",
|
54
|
-
coordinates: [[28, 42], [32, 38]]
|
55
|
-
}
|
56
|
-
}
|
57
|
-
}
|
58
|
-
}, Region
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_polygon
|
62
|
-
assert_search "*", ["Region A"], {
|
63
|
-
where: {
|
64
|
-
territory: {
|
65
|
-
geo_shape: {
|
66
|
-
type: "polygon",
|
67
|
-
coordinates: [[[38, 42], [42, 42], [42, 38], [38, 38], [38, 42]]]
|
68
|
-
}
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}, Region
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_multipolygon
|
75
|
-
assert_search "*", ["Region A", "Region B"], {
|
76
|
-
where: {
|
77
|
-
territory: {
|
78
|
-
geo_shape: {
|
79
|
-
type: "multipolygon",
|
80
|
-
coordinates: [
|
81
|
-
[[[38, 42], [42, 42], [42, 38], [38, 38], [38, 42]]],
|
82
|
-
[[[58, 62], [62, 62], [62, 58], [58, 58], [58, 62]]]
|
83
|
-
]
|
84
|
-
}
|
85
|
-
}
|
86
|
-
}
|
87
|
-
}, Region
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_disjoint
|
91
|
-
assert_search "*", ["Region B", "Region C"], {
|
92
|
-
where: {
|
93
|
-
territory: {
|
94
|
-
geo_shape: {
|
95
|
-
type: "envelope",
|
96
|
-
relation: "disjoint",
|
97
|
-
coordinates: [[28, 42], [32, 38]]
|
98
|
-
}
|
99
|
-
}
|
100
|
-
}
|
101
|
-
}, Region
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_within
|
105
|
-
assert_search "*", ["Region A"], {
|
106
|
-
where: {
|
107
|
-
territory: {
|
108
|
-
geo_shape: {
|
109
|
-
type: "envelope",
|
110
|
-
relation: "within",
|
111
|
-
coordinates: [[20, 50], [50, 20]]
|
112
|
-
}
|
113
|
-
}
|
114
|
-
}
|
115
|
-
}, Region
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_search_math
|
119
|
-
assert_search "witch", ["Region A"], {
|
120
|
-
where: {
|
121
|
-
territory: {
|
122
|
-
geo_shape: {
|
123
|
-
type: "envelope",
|
124
|
-
coordinates: [[28, 42], [32, 38]]
|
125
|
-
}
|
126
|
-
}
|
127
|
-
}
|
128
|
-
}, Region
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_search_no_match
|
132
|
-
assert_search "ginger hair", [], {
|
133
|
-
where: {
|
134
|
-
territory: {
|
135
|
-
geo_shape: {
|
136
|
-
type: "envelope",
|
137
|
-
coordinates: [[28, 42], [32, 38]]
|
138
|
-
}
|
139
|
-
}
|
140
|
-
}
|
141
|
-
}, Region
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_contains
|
145
|
-
assert_search "*", ["Region C"], {
|
146
|
-
where: {
|
147
|
-
territory: {
|
148
|
-
geo_shape: {
|
149
|
-
type: "envelope",
|
150
|
-
relation: "contains",
|
151
|
-
coordinates: [[12, 13], [13, 12]]
|
152
|
-
}
|
153
|
-
}
|
154
|
-
}
|
155
|
-
}, Region
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_latlon
|
159
|
-
assert_search "*", ["Region A"], {
|
160
|
-
where: {
|
161
|
-
territory: {
|
162
|
-
geo_shape: {
|
163
|
-
type: "envelope",
|
164
|
-
coordinates: [{lat: 42, lon: 28}, {lat: 38, lon: 32}]
|
165
|
-
}
|
166
|
-
}
|
167
|
-
}
|
168
|
-
}, Region
|
169
|
-
end
|
170
|
-
|
171
|
-
end
|
data/test/highlight_test.rb
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
class HighlightTest < Minitest::Test
|
4
|
-
def test_basic
|
5
|
-
store_names ["Two Door Cinema Club"]
|
6
|
-
assert_equal "Two Door <em>Cinema</em> Club", Product.search("cinema", highlight: true).highlights.first[:name]
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_tag
|
10
|
-
store_names ["Two Door Cinema Club"]
|
11
|
-
assert_equal "Two Door <strong>Cinema</strong> Club", Product.search("cinema", highlight: {tag: "<strong>"}).highlights.first[:name]
|
12
|
-
end
|
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", highlight: {tag: "<strong class='classy'>"}).highlights.first[:name]
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_very_long
|
20
|
-
store_names [("Two Door Cinema Club " * 100).strip]
|
21
|
-
assert_equal ("Two Door <em>Cinema</em> Club " * 100).strip, Product.search("cinema", highlight: true).highlights.first[:name]
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_multiple_fields
|
25
|
-
store [{name: "Two Door Cinema Club", color: "Cinema Orange"}]
|
26
|
-
highlights = Product.search("cinema", fields: [:name, :color], highlight: true).highlights.first
|
27
|
-
assert_equal "Two Door <em>Cinema</em> Club", highlights[:name]
|
28
|
-
assert_equal "<em>Cinema</em> Orange", highlights[:color]
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_fields
|
32
|
-
store [{name: "Two Door Cinema Club", color: "Cinema Orange"}]
|
33
|
-
highlights = Product.search("cinema", fields: [:name, :color], highlight: {fields: [:name]}).highlights.first
|
34
|
-
assert_equal "Two Door <em>Cinema</em> Club", highlights[:name]
|
35
|
-
assert_nil highlights[:color]
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_field_options
|
39
|
-
store_names ["Two Door Cinema Club are a Northern Irish indie rock band"]
|
40
|
-
fragment_size = ENV["MATCH"] == "word_start" ? 26 : 21
|
41
|
-
assert_equal "Two Door <em>Cinema</em> Club are", Product.search("cinema", highlight: {fields: {name: {fragment_size: fragment_size}}}).highlights.first[:name]
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_multiple_words
|
45
|
-
store_names ["Hello World Hello"]
|
46
|
-
assert_equal "<em>Hello</em> World <em>Hello</em>", Product.search("hello", highlight: true).highlights.first[:name]
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_encoder
|
50
|
-
store_names ["<b>Hello</b>"]
|
51
|
-
assert_equal "<b><em>Hello</em></b>", Product.search("hello", highlight: {encoder: "html"}, misspellings: false).highlights.first[:name]
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_word_middle
|
55
|
-
store_names ["Two Door Cinema Club"]
|
56
|
-
assert_equal "Two Door <em>Cinema</em> Club", Product.search("ine", match: :word_middle, highlight: true).highlights.first[:name]
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_body
|
60
|
-
skip if ENV["MATCH"] == "word_start"
|
61
|
-
store_names ["Two Door Cinema Club"]
|
62
|
-
body = {
|
63
|
-
query: {
|
64
|
-
match: {
|
65
|
-
"name.analyzed" => "cinema"
|
66
|
-
}
|
67
|
-
},
|
68
|
-
highlight: {
|
69
|
-
pre_tags: ["<strong>"],
|
70
|
-
post_tags: ["</strong>"],
|
71
|
-
fields: {
|
72
|
-
"name.analyzed" => {}
|
73
|
-
}
|
74
|
-
}
|
75
|
-
}
|
76
|
-
assert_equal "Two Door <strong>Cinema</strong> Club", Product.search(body: body).highlights.first[:"name.analyzed"]
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_multiple_highlights
|
80
|
-
store_names ["Two Door Cinema Club Some Other Words And Much More Doors Cinema Club"]
|
81
|
-
highlights = Product.search("cinema", highlight: {fragment_size: 20}).highlights(multiple: true).first[:name]
|
82
|
-
assert highlights.is_a?(Array)
|
83
|
-
assert_equal highlights.count, 2
|
84
|
-
refute_equal highlights.first, highlights.last
|
85
|
-
highlights.each do |highlight|
|
86
|
-
assert highlight.include?("<em>Cinema</em>")
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_search_highlights_method
|
91
|
-
store_names ["Two Door Cinema Club"]
|
92
|
-
assert_equal "Two Door <em>Cinema</em> Club", Product.search("cinema", highlight: true).first.search_highlights[:name]
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_match_all
|
96
|
-
store_names ["Two Door Cinema Club"]
|
97
|
-
assert_nil Product.search("*", highlight: true).highlights.first[:name]
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_match_all_load_false
|
101
|
-
store_names ["Two Door Cinema Club"]
|
102
|
-
assert_nil Product.search("*", highlight: true, load: false).highlights.first[:name]
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_match_all_search_highlights
|
106
|
-
store_names ["Two Door Cinema Club"]
|
107
|
-
assert_nil Product.search("*", highlight: true).first.search_highlights[:name]
|
108
|
-
end
|
109
|
-
end
|