Commit b715e9e3c0e7cb96f8d66f90f4c919f8510cba14

Authored by Andrew
1 parent b888bfe2

Removed support for ES2 [skip ci]

@@ -24,13 +24,6 @@ env: @@ -24,13 +24,6 @@ env:
24 jdk: oraclejdk8 24 jdk: oraclejdk8
25 matrix: 25 matrix:
26 include: 26 include:
27 - - gemfile: Gemfile  
28 - env: ELASTICSEARCH_VERSION=2.0.0  
29 - jdk: oraclejdk7  
30 - - gemfile: Gemfile  
31 - env: ELASTICSEARCH_VERSION=2.4.6  
32 - jdk: oraclejdk7  
33 - - gemfile: Gemfile  
34 env: ELASTICSEARCH_VERSION=5.0.1 27 env: ELASTICSEARCH_VERSION=5.0.1
35 jdk: oraclejdk8 28 jdk: oraclejdk8
36 - gemfile: Gemfile 29 - gemfile: Gemfile
  1 +## 3.0.0 [unreleased]
  2 +
  3 +- Removed support for Elasticsearch 2
  4 +- Removed `reindex_async` method. `reindex` now defaults to mode specified by model. Use `reindex(mode: :async)` to force async reindex.
  5 +
1 ## 2.5.1 [unreleased] 6 ## 2.5.1 [unreleased]
2 7
3 - Added `unscoped_reindex_job` option 8 - Added `unscoped_reindex_job` option
@@ -535,7 +535,7 @@ class Image < ApplicationRecord @@ -535,7 +535,7 @@ class Image < ApplicationRecord
535 after_commit :reindex_product 535 after_commit :reindex_product
536 536
537 def reindex_product 537 def reindex_product
538 - product.reindex # or reindex_async 538 + product.reindex
539 end 539 end
540 end 540 end
541 ``` 541 ```
@@ -1531,8 +1531,6 @@ Reindex one record @@ -1531,8 +1531,6 @@ Reindex one record
1531 ```ruby 1531 ```ruby
1532 product = Product.find(1) 1532 product = Product.find(1)
1533 product.reindex 1533 product.reindex
1534 -# or to reindex in the background  
1535 -product.reindex_async  
1536 ``` 1534 ```
1537 1535
1538 Reindex multiple records 1536 Reindex multiple records
lib/searchkick/model.rb
@@ -79,12 +79,11 @@ module Searchkick @@ -79,12 +79,11 @@ module Searchkick
79 end 79 end
80 end 80 end
81 81
82 - callback_name = callbacks == :async ? :reindex_async : :reindex  
83 if respond_to?(:after_commit) 82 if respond_to?(:after_commit)
84 - after_commit callback_name, if: proc { self.class.search_callbacks? } 83 + after_commit :reindex, if: -> { self.class.search_callbacks? }
85 elsif respond_to?(:after_save) 84 elsif respond_to?(:after_save)
86 - after_save callback_name, if: proc { self.class.search_callbacks? }  
87 - after_destroy callback_name, if: proc { self.class.search_callbacks? } 85 + after_save :reindex, if: -> { self.class.search_callbacks? }
  86 + after_destroy :reindex, if: -> { self.class.search_callbacks? }
88 end 87 end
89 88
90 def reindex(method_name = nil, refresh: false, async: false, mode: nil) 89 def reindex(method_name = nil, refresh: false, async: false, mode: nil)
@@ -96,8 +95,7 @@ module Searchkick @@ -96,8 +95,7 @@ module Searchkick
96 :async 95 :async
97 elsif Searchkick.callbacks_value 96 elsif Searchkick.callbacks_value
98 Searchkick.callbacks_value 97 Searchkick.callbacks_value
99 - elsif klass_options.key?(:callbacks) && klass_options[:callbacks] != :async  
100 - # TODO remove 2nd condition in next major version 98 + elsif klass_options.key?(:callbacks)
101 klass_options[:callbacks] 99 klass_options[:callbacks]
102 end 100 end
103 end 101 end
@@ -130,11 +128,6 @@ module Searchkick @@ -130,11 +128,6 @@ module Searchkick
130 end 128 end
131 end unless method_defined?(:reindex) 129 end unless method_defined?(:reindex)
132 130
133 - # TODO remove this method in next major version  
134 - def reindex_async  
135 - reindex(async: true)  
136 - end unless method_defined?(:reindex_async)  
137 -  
138 def similar(options = {}) 131 def similar(options = {})
139 self.class.searchkick_index.similar_record(self, options) 132 self.class.searchkick_index.similar_record(self, options)
140 end unless method_defined?(:similar) 133 end unless method_defined?(:similar)
test/boost_test.rb
@@ -122,13 +122,7 @@ class BoostTest < Minitest::Test @@ -122,13 +122,7 @@ class BoostTest < Minitest::Test
122 {name: "Tomato B", orders_count: 10}, 122 {name: "Tomato B", orders_count: 10},
123 ] 123 ]
124 124
125 - if elasticsearch_below50?  
126 - assert_raises(ArgumentError) do  
127 - assert_order "tomato", ["Tomato A", "Tomato B"], boost_by: {orders_count: {missing: 100}}  
128 - end  
129 - else  
130 - assert_order "tomato", ["Tomato A", "Tomato B"], boost_by: {orders_count: {missing: 100}}  
131 - end 125 + assert_order "tomato", ["Tomato A", "Tomato B"], boost_by: {orders_count: {missing: 100}}
132 end 126 end
133 127
134 def test_boost_by_boost_mode_multiply 128 def test_boost_by_boost_mode_multiply
test/geo_shape_test.rb
@@ -145,7 +145,6 @@ class GeoShapeTest < Minitest::Test @@ -145,7 +145,6 @@ class GeoShapeTest < Minitest::Test
145 end 145 end
146 146
147 def test_contains 147 def test_contains
148 - skip if elasticsearch_below22?  
149 assert_search "*", ["Region C"], { 148 assert_search "*", ["Region C"], {
150 where: { 149 where: {
151 territory: { 150 territory: {
test/index_test.rb
@@ -131,9 +131,10 @@ class IndexTest < Minitest::Test @@ -131,9 +131,10 @@ class IndexTest < Minitest::Test
131 def test_filterable 131 def test_filterable
132 # skip for 5.0 since it throws 132 # skip for 5.0 since it throws
133 # Cannot search on field [alt_description] since it is not indexed. 133 # Cannot search on field [alt_description] since it is not indexed.
134 - skip unless elasticsearch_below50?  
135 store [{name: "Product A", alt_description: "Hello"}] 134 store [{name: "Product A", alt_description: "Hello"}]
136 - assert_search "*", [], where: {alt_description: "Hello"} 135 + assert_raises(Searchkick::InvalidQueryError) do
  136 + assert_search "*", [], where: {alt_description: "Hello"}
  137 + end
137 end 138 end
138 139
139 def test_filterable_non_string 140 def test_filterable_non_string
@@ -155,7 +156,7 @@ class IndexTest < Minitest::Test @@ -155,7 +156,7 @@ class IndexTest < Minitest::Test
155 end 156 end
156 157
157 def test_very_large_value 158 def test_very_large_value
158 - skip if nobrainer? || elasticsearch_below22? 159 + skip if nobrainer?
159 large_value = 10000.times.map { "hello" }.join(" ") 160 large_value = 10000.times.map { "hello" }.join(" ")
160 store [{name: "Product A", text: large_value}], Region 161 store [{name: "Product A", text: large_value}], Region
161 assert_search "product", ["Product A"], {}, Region 162 assert_search "product", ["Product A"], {}, Region
test/order_test.rb
@@ -29,14 +29,8 @@ class OrderTest < Minitest::Test @@ -29,14 +29,8 @@ class OrderTest < Minitest::Test
29 assert_order "product", ["Product A", "Product B", "Product C"], order: {color: :asc, store_id: :desc} 29 assert_order "product", ["Product A", "Product B", "Product C"], order: {color: :asc, store_id: :desc}
30 end 30 end
31 31
32 - def test_order_ignore_unmapped  
33 - skip unless elasticsearch_below50?  
34 - assert_order "product", [], order: {not_mapped: {ignore_unmapped: true}}, conversions: false  
35 - end  
36 -  
37 def test_order_unmapped_type 32 def test_order_unmapped_type
38 - skip if elasticsearch_below50?  
39 - assert_order "product", [], order: {not_mapped: {unmapped_type: "long"}}, conversions: false 33 + assert_order "product", [], order: {not_mapped: {unmapped_type: "long"}}
40 end 34 end
41 35
42 def test_order_array 36 def test_order_array
test/sql_test.rb
@@ -125,36 +125,7 @@ class SqlTest < Minitest::Test @@ -125,36 +125,7 @@ class SqlTest < Minitest::Test
125 assert_nil hit["_source"] 125 assert_nil hit["_source"]
126 end 126 end
127 127
128 - def test_select_include  
129 - skip unless elasticsearch_below50?  
130 - store [{name: "Product A", user_ids: [1, 2]}]  
131 - result = Product.search("product", load: false, select: {include: [:name]}).first  
132 - assert_equal %w(id name), result.keys.reject { |k| k.start_with?("_") }.sort  
133 - assert_equal "Product A", result.name  
134 - assert_nil result.store_id  
135 - end  
136 -  
137 - def test_select_exclude  
138 - skip unless elasticsearch_below50?  
139 - store [{name: "Product A", user_ids: [1, 2], store_id: 1}]  
140 - result = Product.search("product", load: false, select: {exclude: [:name]}).first  
141 - assert_nil result.name  
142 - assert_equal [1, 2], result.user_ids  
143 - assert_equal 1, result.store_id  
144 - end  
145 -  
146 - def test_select_include_and_exclude  
147 - skip unless elasticsearch_below50?  
148 - # let's take this to the next level  
149 - store [{name: "Product A", user_ids: [1, 2], store_id: 1}]  
150 - result = Product.search("product", load: false, select: {include: [:store_id], exclude: [:name]}).first  
151 - assert_equal 1, result.store_id  
152 - assert_nil result.name  
153 - assert_nil result.user_ids  
154 - end  
155 -  
156 def test_select_includes 128 def test_select_includes
157 - skip if elasticsearch_below50?  
158 store [{name: "Product A", user_ids: [1, 2]}] 129 store [{name: "Product A", user_ids: [1, 2]}]
159 result = Product.search("product", load: false, select: {includes: [:name]}).first 130 result = Product.search("product", load: false, select: {includes: [:name]}).first
160 assert_equal %w(id name), result.keys.reject { |k| k.start_with?("_") }.sort 131 assert_equal %w(id name), result.keys.reject { |k| k.start_with?("_") }.sort
@@ -163,7 +134,6 @@ class SqlTest < Minitest::Test @@ -163,7 +134,6 @@ class SqlTest < Minitest::Test
163 end 134 end
164 135
165 def test_select_excludes 136 def test_select_excludes
166 - skip if elasticsearch_below50?  
167 store [{name: "Product A", user_ids: [1, 2], store_id: 1}] 137 store [{name: "Product A", user_ids: [1, 2], store_id: 1}]
168 result = Product.search("product", load: false, select: {excludes: [:name]}).first 138 result = Product.search("product", load: false, select: {excludes: [:name]}).first
169 assert_nil result.name 139 assert_nil result.name
@@ -172,7 +142,6 @@ class SqlTest < Minitest::Test @@ -172,7 +142,6 @@ class SqlTest < Minitest::Test
172 end 142 end
173 143
174 def test_select_include_and_excludes 144 def test_select_include_and_excludes
175 - skip if elasticsearch_below50?  
176 # let's take this to the next level 145 # let's take this to the next level
177 store [{name: "Product A", user_ids: [1, 2], store_id: 1}] 146 store [{name: "Product A", user_ids: [1, 2], store_id: 1}]
178 result = Product.search("product", load: false, select: {includes: [:store_id], excludes: [:name]}).first 147 result = Product.search("product", load: false, select: {includes: [:store_id], excludes: [:name]}).first
test/test_helper.rb
@@ -38,18 +38,10 @@ end @@ -38,18 +38,10 @@ end
38 38
39 ActiveSupport::LogSubscriber.logger = ActiveSupport::Logger.new(STDOUT) if ENV["NOTIFICATIONS"] 39 ActiveSupport::LogSubscriber.logger = ActiveSupport::Logger.new(STDOUT) if ENV["NOTIFICATIONS"]
40 40
41 -def elasticsearch_below50?  
42 - Searchkick.server_below?("5.0.0-alpha1")  
43 -end  
44 -  
45 def elasticsearch_below60? 41 def elasticsearch_below60?
46 Searchkick.server_below?("6.0.0-alpha1") 42 Searchkick.server_below?("6.0.0-alpha1")
47 end 43 end
48 44
49 -def elasticsearch_below22?  
50 - Searchkick.server_below?("2.2.0")  
51 -end  
52 -  
53 def nobrainer? 45 def nobrainer?
54 defined?(NoBrainer) 46 defined?(NoBrainer)
55 end 47 end
@@ -454,7 +446,7 @@ class Store @@ -454,7 +446,7 @@ class Store
454 mappings: { 446 mappings: {
455 store: { 447 store: {
456 properties: { 448 properties: {
457 - name: elasticsearch_below50? ? {type: "string", analyzer: "keyword"} : {type: "keyword"} 449 + name: {type: "keyword"}
458 } 450 }
459 } 451 }
460 } 452 }