searchkick 0.3.0 → 0.3.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 +6 -0
- data/README.md +17 -0
- data/lib/searchkick/model.rb +1 -1
- data/lib/searchkick/reindex.rb +6 -0
- data/lib/searchkick/search.rb +17 -2
- data/lib/searchkick/version.rb +1 -1
- data/test/facets_test.rb +4 -1
- data/test/match_test.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1da092cc431fe04831d998435718459f8bebf261
|
4
|
+
data.tar.gz: 21a86486b94f81e6b9b9061fb6cf051ac7672650
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b8bbdb5158b5c39994277ab80e46a14b222b5dd24a22204dcc3acb8d3b853b50b692e77a1b634774e5611ca930b1e495428200e9ddcd726254af7db3820a251
|
7
|
+
data.tar.gz: 3661b1fbb97fd864e524745b2f7435486aeb4cec005381e01a7c37ed6683b38e55b5a5921d60635d46d1700012d18b7662abb99545ee655c635882b9b5b322d4
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -444,6 +444,14 @@ class Product < ActiveRecord::Base
|
|
444
444
|
end
|
445
445
|
```
|
446
446
|
|
447
|
+
Prefix the index name
|
448
|
+
|
449
|
+
```ruby
|
450
|
+
class Product < ActiveRecord::Base
|
451
|
+
searchkick index_prefix: "datakick"
|
452
|
+
end
|
453
|
+
```
|
454
|
+
|
447
455
|
Turn off callbacks
|
448
456
|
|
449
457
|
```ruby
|
@@ -464,6 +472,15 @@ Do not load models
|
|
464
472
|
Product.search "milk", load: false
|
465
473
|
```
|
466
474
|
|
475
|
+
Turn off special characters
|
476
|
+
|
477
|
+
```ruby
|
478
|
+
class Product < ActiveRecord::Base
|
479
|
+
# A will not match Ä
|
480
|
+
searchkick special_characters: false
|
481
|
+
end
|
482
|
+
```
|
483
|
+
|
467
484
|
Reindex all models (Rails only)
|
468
485
|
|
469
486
|
```sh
|
data/lib/searchkick/model.rb
CHANGED
@@ -13,7 +13,7 @@ module Searchkick
|
|
13
13
|
include Tire::Model::Search
|
14
14
|
include Tire::Model::Callbacks unless options[:callbacks] == false
|
15
15
|
tire do
|
16
|
-
index_name options[:index_name] || [klass.model_name.plural, searchkick_env].join("_")
|
16
|
+
index_name options[:index_name] || [options[:index_prefix], klass.model_name.plural, searchkick_env].compact.join("_")
|
17
17
|
end
|
18
18
|
|
19
19
|
def reindex
|
data/lib/searchkick/reindex.rb
CHANGED
@@ -174,6 +174,12 @@ module Searchkick
|
|
174
174
|
settings[:analysis][:analyzer][:default_index][:filter] << "searchkick_synonym"
|
175
175
|
end
|
176
176
|
|
177
|
+
if options[:special_characters] == false
|
178
|
+
settings[:analysis][:analyzer].each do |analyzer, analyzer_settings|
|
179
|
+
analyzer_settings[:filter].reject!{|f| f == "asciifolding" }
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
177
183
|
mapping = {}
|
178
184
|
|
179
185
|
# conversions
|
data/lib/searchkick/search.rb
CHANGED
@@ -234,6 +234,7 @@ module Searchkick
|
|
234
234
|
end
|
235
235
|
|
236
236
|
# facets
|
237
|
+
facet_limits = {}
|
237
238
|
if options[:facets]
|
238
239
|
facets = options[:facets] || {}
|
239
240
|
if facets.is_a?(Array) # convert to more advanced syntax
|
@@ -242,12 +243,15 @@ module Searchkick
|
|
242
243
|
|
243
244
|
payload[:facets] = {}
|
244
245
|
facets.each do |field, facet_options|
|
246
|
+
# ask for extra facets due to
|
247
|
+
# https://github.com/elasticsearch/elasticsearch/issues/1305
|
245
248
|
payload[:facets][field] = {
|
246
249
|
terms: {
|
247
250
|
field: field,
|
248
|
-
size: facet_options[:limit]
|
251
|
+
size: facet_options[:limit] ? facet_options[:limit] + 150 : 100000
|
249
252
|
}
|
250
253
|
}
|
254
|
+
facet_limits[field] = facet_options[:limit] if facet_options[:limit]
|
251
255
|
|
252
256
|
# offset is not possible
|
253
257
|
# http://elasticsearch-users.115913.n3.nabble.com/Is-pagination-possible-in-termsStatsFacet-td3422943.html
|
@@ -285,7 +289,18 @@ module Searchkick
|
|
285
289
|
payload[:fields] = [] if load
|
286
290
|
|
287
291
|
search = Tire::Search::Search.new(index_name, load: load, payload: payload, size: per_page, from: offset)
|
288
|
-
|
292
|
+
response = search.json
|
293
|
+
|
294
|
+
# apply facet limit in client due to
|
295
|
+
# https://github.com/elasticsearch/elasticsearch/issues/1305
|
296
|
+
facet_limits.each do |field, limit|
|
297
|
+
field = field.to_s
|
298
|
+
facet = response["facets"][field]
|
299
|
+
response["facets"][field]["terms"] = facet["terms"].first(limit)
|
300
|
+
response["facets"][field]["other"] = facet["total"] - facet["terms"].sum{|term| term["count"] }
|
301
|
+
end
|
302
|
+
|
303
|
+
Searchkick::Results.new(response, search.options.merge(term: term))
|
289
304
|
end
|
290
305
|
|
291
306
|
end
|
data/lib/searchkick/version.rb
CHANGED
data/test/facets_test.rb
CHANGED
@@ -20,7 +20,10 @@ class TestFacets < Minitest::Unit::TestCase
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_limit
|
23
|
-
|
23
|
+
facet = Product.search("Product", facets: {store_id: {limit: 1}}).facets["store_id"]
|
24
|
+
assert_equal 1, facet["terms"].size
|
25
|
+
assert_equal 3, facet["total"]
|
26
|
+
assert_equal 1, facet["other"]
|
24
27
|
end
|
25
28
|
|
26
29
|
end
|
data/test/match_test.rb
CHANGED