Commit 0e3ddf8b9a9c74a860f963cb148cd449d22df9dc
Exists in
reindex_refactor
Merge branch 'master' into reindex_refactor
Showing
5 changed files
with
29 additions
and
4 deletions
Show diff stats
README.md
@@ -1977,13 +1977,11 @@ Everyone is encouraged to help improve this project. Here are a few ways you can | @@ -1977,13 +1977,11 @@ Everyone is encouraged to help improve this project. Here are a few ways you can | ||
1977 | - Write, clarify, or fix documentation | 1977 | - Write, clarify, or fix documentation |
1978 | - Suggest or add new features | 1978 | - Suggest or add new features |
1979 | 1979 | ||
1980 | -If you’re looking for ideas, [try here](https://github.com/ankane/searchkick/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22). | ||
1981 | - | ||
1982 | -To get started with development and testing: | 1980 | +To get started with development: |
1983 | 1981 | ||
1984 | ```sh | 1982 | ```sh |
1985 | git clone https://github.com/ankane/searchkick.git | 1983 | git clone https://github.com/ankane/searchkick.git |
1986 | cd searchkick | 1984 | cd searchkick |
1987 | bundle install | 1985 | bundle install |
1988 | -rake test | 1986 | +bundle exec rake test |
1989 | ``` | 1987 | ``` |
lib/searchkick/index.rb
@@ -187,11 +187,17 @@ module Searchkick | @@ -187,11 +187,17 @@ module Searchkick | ||
187 | options.delete(:refresh) | 187 | options.delete(:refresh) |
188 | 188 | ||
189 | if method_name | 189 | if method_name |
190 | + # TODO throw ArgumentError | ||
191 | + Searchkick.warn("unsupported keywords: #{options.keys.map(&:inspect).join(", ")}") if options.any? | ||
192 | + | ||
190 | # update | 193 | # update |
191 | import_scope(relation, method_name: method_name, scope: scope) | 194 | import_scope(relation, method_name: method_name, scope: scope) |
192 | self.refresh if refresh | 195 | self.refresh if refresh |
193 | true | 196 | true |
194 | elsif scoped && !full | 197 | elsif scoped && !full |
198 | + # TODO throw ArgumentError | ||
199 | + Searchkick.warn("unsupported keywords: #{options.keys.map(&:inspect).join(", ")}") if options.any? | ||
200 | + | ||
195 | # reindex association | 201 | # reindex association |
196 | import_scope(relation, scope: scope) | 202 | import_scope(relation, scope: scope) |
197 | self.refresh if refresh | 203 | self.refresh if refresh |
lib/searchkick/model.rb
@@ -41,6 +41,8 @@ module Searchkick | @@ -41,6 +41,8 @@ module Searchkick | ||
41 | 41 | ||
42 | class << self | 42 | class << self |
43 | def searchkick_search(term = "*", **options, &block) | 43 | def searchkick_search(term = "*", **options, &block) |
44 | + # TODO same for Mongoid | ||
45 | + Searchkick.warn("calling search on a relation is deprecated") if respond_to?(:current_scope) && !current_scope.nil? | ||
44 | Searchkick.search(term, model: self, **options, &block) | 46 | Searchkick.search(term, model: self, **options, &block) |
45 | end | 47 | end |
46 | alias_method Searchkick.search_method_name, :searchkick_search if Searchkick.search_method_name | 48 | alias_method Searchkick.search_method_name, :searchkick_search if Searchkick.search_method_name |
test/match_test.rb
@@ -301,4 +301,17 @@ class MatchTest < Minitest::Test | @@ -301,4 +301,17 @@ class MatchTest < Minitest::Test | ||
301 | store_names ["Ice Cream Cake"] | 301 | store_names ["Ice Cream Cake"] |
302 | assert_search "🍨🍰", ["Ice Cream Cake"], emoji: true | 302 | assert_search "🍨🍰", ["Ice Cream Cake"], emoji: true |
303 | end | 303 | end |
304 | + | ||
305 | + # TODO find better place | ||
306 | + | ||
307 | + def test_search_relation | ||
308 | + skip unless defined?(ActiveRecord) | ||
309 | + | ||
310 | + assert_nil Product.current_scope | ||
311 | + _, stderr = capture_io { Product.search("*") } | ||
312 | + assert_equal "", stderr | ||
313 | + assert Product.where(name: nil).current_scope | ||
314 | + _, stderr = capture_io { Product.where(name: nil).search("*") } | ||
315 | + assert_match "WARNING", stderr | ||
316 | + end | ||
304 | end | 317 | end |
test/reindex_test.rb
@@ -92,4 +92,10 @@ class ReindexTest < Minitest::Test | @@ -92,4 +92,10 @@ class ReindexTest < Minitest::Test | ||
92 | def test_refresh_full_reindex | 92 | def test_refresh_full_reindex |
93 | Product.reindex(refresh: true) | 93 | Product.reindex(refresh: true) |
94 | end | 94 | end |
95 | + | ||
96 | + def test_partial_async | ||
97 | + store_names ["Product A"] | ||
98 | + # warn for now | ||
99 | + Product.reindex(:search_name, async: true) | ||
100 | + end | ||
95 | end | 101 | end |