searchkick 4.3.0 → 4.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
  SHA256:
3
- metadata.gz: 964d3c57721433fff2893d53c0dd91b60e66f0e0b75c560e71430bc955fac9cb
4
- data.tar.gz: 02643d50655602ca36ef006f9f68031b185bcc169a739db0769a7921ba00677f
3
+ metadata.gz: 01c6ee30f8005b48d1bff0515d2c3ad4a01b06aa75367be23ba3846905e2452c
4
+ data.tar.gz: 2cd8509ad85e598405f4262f6bcd74d2f14214078b01f927a1e835c1bf2302f6
5
5
  SHA512:
6
- metadata.gz: d5d39a9d775e2beac62552cc498447ffd28d71c8f3ddeee6e6a9cb809b07d3a6c50d66d720bfd335d5b349af75f046ccbf4d5fc4cb4e6a0a27ccebaa8cc46daf
7
- data.tar.gz: 6a3d30a7d90c7119c4bde98acba3ffc42579524e4ab7a2dbafb2865013d68928d18c2773d17253b42e85ad785c56525203f6843661e78210645fad6dd355ba85
6
+ metadata.gz: 00fbf37d1aefa95abe59e749dd820992cc87f0ea12d751b37f80d1a734dc2cc7a0bcbc96bcf63f4a73bc874a9fff276c420f02fd6fe901143834f904cf243fc0
7
+ data.tar.gz: c0b686a80177fd9d743c1bcea45369d59742e8152890cf70d93c4d3b4a67a72653f07b2daf9e8a464ec4d879207c4dbcddd26cee69377508d14c7dbaeaad6a58
@@ -1,3 +1,7 @@
1
+ ## 4.3.1 (2020-05-13)
2
+
3
+ - Fixed error with `exclude` in certain cases for Elasticsearch 7.7
4
+
1
5
  ## 4.3.0 (2020-02-19)
2
6
 
3
7
  - Fixed `like` queries with `"` character
data/README.md CHANGED
@@ -764,8 +764,6 @@ Order
764
764
  Product.search "wingtips", aggs: {color: {order: {"_key" => "asc"}}} # alphabetically
765
765
  ```
766
766
 
767
- **Note:** Use `_term` instead of `_key` in Elasticsearch 5
768
-
769
767
  [All of these options are supported](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-order)
770
768
 
771
769
  Ranges
@@ -1034,7 +1032,7 @@ Searchkick uses `ENV["ELASTICSEARCH_URL"]` for the Elasticsearch server. This de
1034
1032
 
1035
1033
  ### Heroku
1036
1034
 
1037
- Choose an add-on: [Bonsai](https://elements.heroku.com/addons/bonsai) or [Elastic Cloud](https://elements.heroku.com/addons/foundelasticsearch). [SearchBox](https://elements.heroku.com/addons/searchbox) does not work at the moment.
1035
+ Choose an add-on: [Bonsai](https://elements.heroku.com/addons/bonsai), [SearchBox](https://elements.heroku.com/addons/searchbox), or [Elastic Cloud](https://elements.heroku.com/addons/foundelasticsearch).
1038
1036
 
1039
1037
  For Bonsai:
1040
1038
 
@@ -1043,6 +1041,13 @@ heroku addons:create bonsai
1043
1041
  heroku config:set ELASTICSEARCH_URL=`heroku config:get BONSAI_URL`
1044
1042
  ```
1045
1043
 
1044
+ For SearchBox:
1045
+
1046
+ ```sh
1047
+ heroku addons:create searchbox:starter
1048
+ heroku config:set ELASTICSEARCH_URL=`heroku config:get SEARCHBOX_URL`
1049
+ ```
1050
+
1046
1051
  For Elastic Cloud (previously Found):
1047
1052
 
1048
1053
  ```sh
@@ -1807,6 +1812,44 @@ Product.search "ah", misspellings: {prefix_length: 2} # ah, no aha
1807
1812
 
1808
1813
  For performance, only enable Searchkick callbacks for the tests that need it.
1809
1814
 
1815
+ ### Parallel Tests
1816
+
1817
+ Rails 6 enables parallel tests by default. Add to your `test/test_helper.rb`:
1818
+
1819
+ ```ruby
1820
+ class ActiveSupport::TestCase
1821
+ parallelize_setup do |worker|
1822
+ Searchkick.index_suffix = worker
1823
+
1824
+ # reindex models
1825
+ Product.reindex
1826
+
1827
+ # and disable callbacks
1828
+ Searchkick.disable_callbacks
1829
+ end
1830
+ end
1831
+ ```
1832
+
1833
+ And use:
1834
+
1835
+ ```ruby
1836
+ class ProductTest < ActiveSupport::TestCase
1837
+ def setup
1838
+ Searchkick.enable_callbacks
1839
+ end
1840
+
1841
+ def teardown
1842
+ Searchkick.disable_callbacks
1843
+ end
1844
+
1845
+ def test_search
1846
+ Product.create!(name: "Apple")
1847
+ Product.search_index.refresh
1848
+ assert_equal ["Apple"], Product.search("apple").map(&:name)
1849
+ end
1850
+ end
1851
+ ```
1852
+
1810
1853
  ### Minitest
1811
1854
 
1812
1855
  Add to your `test/test_helper.rb`:
@@ -1854,7 +1897,7 @@ RSpec.configure do |config|
1854
1897
  end
1855
1898
 
1856
1899
  config.around(:each, search: true) do |example|
1857
- Searchkick.callbacks(true) do
1900
+ Searchkick.callbacks(nil) do
1858
1901
  example.run
1859
1902
  end
1860
1903
  end
@@ -1896,14 +1939,6 @@ end
1896
1939
  FactoryBot.create(:product, :some_trait, :reindex, some_attribute: "foo")
1897
1940
  ```
1898
1941
 
1899
- ### Parallel Tests
1900
-
1901
- Set:
1902
-
1903
- ```ruby
1904
- Searchkick.index_suffix = ENV["TEST_ENV_NUMBER"]
1905
- ```
1906
-
1907
1942
  ## Multi-Tenancy
1908
1943
 
1909
1944
  Check out [this great post](https://www.tiagoamaro.com.br/2014/12/11/multi-tenancy-with-searchkick/) on the [Apartment](https://github.com/influitive/apartment) gem. Follow a similar pattern if you use another gem.
@@ -1979,13 +2014,11 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
1979
2014
  - Write, clarify, or fix documentation
1980
2015
  - Suggest or add new features
1981
2016
 
1982
- If you’re looking for ideas, [try here](https://github.com/ankane/searchkick/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22).
1983
-
1984
- To get started with development and testing:
2017
+ To get started with development:
1985
2018
 
1986
2019
  ```sh
1987
2020
  git clone https://github.com/ankane/searchkick.git
1988
2021
  cd searchkick
1989
2022
  bundle install
1990
- rake test
2023
+ bundle exec rake test
1991
2024
  ```
@@ -1,8 +1,10 @@
1
+ # dependencies
1
2
  require "active_support"
2
3
  require "active_support/core_ext/hash/deep_merge"
3
4
  require "elasticsearch"
4
5
  require "hashie"
5
6
 
7
+ # modules
6
8
  require "searchkick/bulk_indexer"
7
9
  require "searchkick/index"
8
10
  require "searchkick/indexer"
@@ -17,6 +19,7 @@ require "searchkick/record_indexer"
17
19
  require "searchkick/results"
18
20
  require "searchkick/version"
19
21
 
22
+ # integrations
20
23
  require "searchkick/railtie" if defined?(Rails)
21
24
  require "searchkick/logging" if defined?(ActiveSupport::Notifications)
22
25
 
@@ -27,6 +30,7 @@ module Searchkick
27
30
  autoload :ProcessQueueJob, "searchkick/process_queue_job"
28
31
  autoload :ReindexV2Job, "searchkick/reindex_v2_job"
29
32
 
33
+ # errors
30
34
  class Error < StandardError; end
31
35
  class MissingIndexError < Error; end
32
36
  class UnsupportedVersionError < Error; end
@@ -142,7 +146,7 @@ module Searchkick
142
146
  end
143
147
  end
144
148
 
145
- def self.callbacks(value)
149
+ def self.callbacks(value = nil)
146
150
  if block_given?
147
151
  previous_value = callbacks_value
148
152
  begin
@@ -249,6 +253,18 @@ module Searchkick
249
253
  }
250
254
  end
251
255
  end
256
+
257
+ # private
258
+ # methods are forwarded to base class
259
+ # this check to see if scope exists on that class
260
+ # it's a bit tricky, but this seems to work
261
+ def self.relation?(klass)
262
+ if klass.respond_to?(:current_scope)
263
+ !klass.current_scope.nil?
264
+ elsif defined?(Mongoid::Threaded)
265
+ !Mongoid::Threaded.current_scope(klass).nil?
266
+ end
267
+ end
252
268
  end
253
269
 
254
270
  # TODO find better ActiveModel hook
@@ -187,11 +187,17 @@ module Searchkick
187
187
  options.delete(:refresh)
188
188
 
189
189
  if method_name
190
+ # TODO throw ArgumentError
191
+ Searchkick.warn("unsupported keywords: #{options.keys.map(&:inspect).join(", ")}") if options.any?
192
+
190
193
  # update
191
194
  import_scope(relation, method_name: method_name, scope: scope)
192
195
  self.refresh if refresh
193
196
  true
194
197
  elsif scoped && !full
198
+ # TODO throw ArgumentError
199
+ Searchkick.warn("unsupported keywords: #{options.keys.map(&:inspect).join(", ")}") if options.any?
200
+
195
201
  # reindex association
196
202
  import_scope(relation, scope: scope)
197
203
  self.refresh if refresh
@@ -27,9 +27,6 @@ module Searchkick
27
27
  default_analyzer = :searchkick_index
28
28
  keyword_mapping = {type: "keyword"}
29
29
 
30
- index_true_value = true
31
- index_false_value = false
32
-
33
30
  keyword_mapping[:ignore_above] = options[:ignore_above] || 30000
34
31
 
35
32
  settings = {
@@ -356,13 +353,13 @@ module Searchkick
356
353
 
357
354
  mapping_options[:searchable].delete("_all")
358
355
 
359
- analyzed_field_options = {type: default_type, index: index_true_value, analyzer: default_analyzer}
356
+ analyzed_field_options = {type: default_type, index: true, analyzer: default_analyzer}
360
357
 
361
358
  mapping_options.values.flatten.uniq.each do |field|
362
359
  fields = {}
363
360
 
364
361
  if options.key?(:filterable) && !mapping_options[:filterable].include?(field)
365
- fields[field] = {type: default_type, index: index_false_value}
362
+ fields[field] = {type: default_type, index: false}
366
363
  else
367
364
  fields[field] = keyword_mapping
368
365
  end
@@ -378,7 +375,7 @@ module Searchkick
378
375
 
379
376
  mapping_options.except(:highlight, :searchable, :filterable, :word).each do |type, f|
380
377
  if options[:match] == type || f.include?(field)
381
- fields[type] = {type: default_type, index: index_true_value, analyzer: "searchkick_#{type}_index"}
378
+ fields[type] = {type: default_type, index: true, analyzer: "searchkick_#{type}_index"}
382
379
  end
383
380
  end
384
381
  end
@@ -418,12 +415,12 @@ module Searchkick
418
415
  }
419
416
 
420
417
  if options.key?(:filterable)
421
- dynamic_fields["{name}"] = {type: default_type, index: index_false_value}
418
+ dynamic_fields["{name}"] = {type: default_type, index: false}
422
419
  end
423
420
 
424
421
  unless options[:searchable]
425
422
  if options[:match] && options[:match] != :word
426
- dynamic_fields[options[:match]] = {type: default_type, index: index_true_value, analyzer: "searchkick_#{options[:match]}_index"}
423
+ dynamic_fields[options[:match]] = {type: default_type, index: true, analyzer: "searchkick_#{options[:match]}_index"}
427
424
  end
428
425
 
429
426
  if word
@@ -41,6 +41,9 @@ module Searchkick
41
41
 
42
42
  class << self
43
43
  def searchkick_search(term = "*", **options, &block)
44
+ # TODO throw error in next major version
45
+ Searchkick.warn("calling search on a relation is deprecated") if Searchkick.relation?(self)
46
+
44
47
  Searchkick.search(term, model: self, **options, &block)
45
48
  end
46
49
  alias_method Searchkick.search_method_name, :searchkick_search if Searchkick.search_method_name
@@ -54,10 +57,11 @@ module Searchkick
54
57
  alias_method :search_index, :searchkick_index unless method_defined?(:search_index)
55
58
 
56
59
  def searchkick_reindex(method_name = nil, **options)
57
- scoped = (respond_to?(:current_scope) && respond_to?(:default_scoped) && current_scope && current_scope.to_sql != default_scoped.to_sql) ||
60
+ # TODO relation = Searchkick.relation?(self)
61
+ relation = (respond_to?(:current_scope) && respond_to?(:default_scoped) && current_scope && current_scope.to_sql != default_scoped.to_sql) ||
58
62
  (respond_to?(:queryable) && queryable != unscoped.with_default_scope)
59
63
 
60
- searchkick_index.reindex(searchkick_klass, method_name, scoped: scoped, **options)
64
+ searchkick_index.reindex(searchkick_klass, method_name, scoped: relation, **options)
61
65
  end
62
66
  alias_method :reindex, :searchkick_reindex unless method_defined?(:reindex)
63
67
 
@@ -574,7 +574,8 @@ module Searchkick
574
574
 
575
575
  def build_query(query, filters, should, must_not, custom_filters, multiply_filters)
576
576
  if filters.any? || must_not.any? || should.any?
577
- bool = {must: query}
577
+ bool = {}
578
+ bool[:must] = query if query
578
579
  bool[:filter] = filters if filters.any? # where
579
580
  bool[:must_not] = must_not if must_not.any? # exclude
580
581
  bool[:should] = should if should.any? # conversions
@@ -1,3 +1,3 @@
1
1
  module Searchkick
2
- VERSION = "4.3.0"
2
+ VERSION = "4.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
4
+ version: 4.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-19 00:00:00.000000000 Z
11
+ date: 2020-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel