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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08d3471564b063d98692fa8db6e27635b826d9eb
4
- data.tar.gz: 23ff81861bf090b967eacce86c31b99f18370738
3
+ metadata.gz: 1da092cc431fe04831d998435718459f8bebf261
4
+ data.tar.gz: 21a86486b94f81e6b9b9061fb6cf051ac7672650
5
5
  SHA512:
6
- metadata.gz: 0e3fb6959b85a1d63908e7fe7c6086eb817ee597132f701205fa0942f7982e43a6eecdb6b1924e2c7e7d4f1650071df95a2281b1b548e8099a3e2eeffbd1c475
7
- data.tar.gz: 1c774316a7f8833239e27c4e15578c537729ce37c6c9cb54b7202f71b4ee44978d2dda2bad4d330b7e34acfbc643a002fdc92a436af79cfb41e0147d6bda9322
6
+ metadata.gz: 2b8bbdb5158b5c39994277ab80e46a14b222b5dd24a22204dcc3acb8d3b853b50b692e77a1b634774e5611ca930b1e495428200e9ddcd726254af7db3820a251
7
+ data.tar.gz: 3661b1fbb97fd864e524745b2f7435486aeb4cec005381e01a7c37ed6683b38e55b5a5921d60635d46d1700012d18b7662abb99545ee655c635882b9b5b322d4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.3.1
2
+
3
+ - Added index_prefix option
4
+ - Fixed ES issue with incorrect facet counts
5
+ - Added option to turn off special characters
6
+
1
7
  ## 0.3.0
2
8
 
3
9
  - Fixed reversed coordinates
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
@@ -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
@@ -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
@@ -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] || 100000
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
- Searchkick::Results.new(search.json, search.options.merge(term: term))
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
@@ -1,3 +1,3 @@
1
1
  module Searchkick
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
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
- assert_equal 1, Product.search("Product", facets: {store_id: {limit: 1}}).facets["store_id"]["terms"].size
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
@@ -48,6 +48,11 @@ class TestMatch < Minitest::Unit::TestCase
48
48
  assert_search "jalapeno", ["Jalapeño"]
49
49
  end
50
50
 
51
+ def test_swedish
52
+ store_names ["ÅÄÖ"]
53
+ assert_search "aao", ["ÅÄÖ"]
54
+ end
55
+
51
56
  # stemming
52
57
 
53
58
  def test_stemming
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane