chewy 7.3.5 → 7.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +2 -28
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +20 -0
- data/Gemfile +4 -4
- data/README.md +1 -1
- data/chewy.gemspec +3 -17
- data/gemfiles/base.gemfile +12 -0
- data/gemfiles/rails.6.1.activerecord.gemfile +2 -1
- data/gemfiles/rails.7.0.activerecord.gemfile +2 -1
- data/gemfiles/rails.7.1.activerecord.gemfile +2 -1
- data/lib/chewy/config.rb +12 -10
- data/lib/chewy/fields/root.rb +1 -1
- data/lib/chewy/index/adapter/active_record.rb +1 -1
- data/lib/chewy/index/adapter/object.rb +3 -3
- data/lib/chewy/index/adapter/orm.rb +2 -2
- data/lib/chewy/index/import/bulk_builder.rb +2 -2
- data/lib/chewy/index/import.rb +2 -2
- data/lib/chewy/index/observe/active_record_methods.rb +1 -1
- data/lib/chewy/index/syncer.rb +1 -1
- data/lib/chewy/minitest/search_index_receiver.rb +3 -1
- data/lib/chewy/rake_helper.rb +3 -3
- data/lib/chewy/rspec/update_index.rb +3 -3
- data/lib/chewy/runtime/version.rb +1 -1
- data/lib/chewy/search/parameters/indices.rb +1 -1
- data/lib/chewy/search/parameters/knn.rb +16 -0
- data/lib/chewy/search/parameters/storage.rb +1 -1
- data/lib/chewy/search/parameters.rb +3 -3
- data/lib/chewy/search/request.rb +14 -3
- data/lib/chewy/search.rb +6 -4
- data/lib/chewy/version.rb +1 -1
- data/lib/chewy.rb +1 -1
- data/spec/chewy/index/actions_spec.rb +4 -4
- data/spec/chewy/index/import/bulk_builder_spec.rb +3 -3
- data/spec/chewy/index/import_spec.rb +3 -3
- data/spec/chewy/minitest/helpers_spec.rb +1 -1
- data/spec/chewy/minitest/search_index_receiver_spec.rb +6 -4
- data/spec/chewy/rake_helper_spec.rb +4 -4
- data/spec/chewy/rspec/helpers_spec.rb +1 -1
- data/spec/chewy/search/pagination/kaminari_examples.rb +1 -1
- data/spec/chewy/search/pagination/kaminari_spec.rb +1 -1
- data/spec/chewy/search/parameters/knn_spec.rb +5 -0
- data/spec/chewy/search/request_spec.rb +9 -7
- data/spec/chewy/strategy/active_job_spec.rb +8 -8
- data/spec/chewy/strategy/lazy_sidekiq_spec.rb +10 -10
- data/spec/chewy/strategy/sidekiq_spec.rb +4 -4
- data/spec/chewy_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +8 -268
- data/gemfiles/rails.5.2.activerecord.gemfile +0 -11
- data/gemfiles/rails.6.0.activerecord.gemfile +0 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a5afbccc50c9249e0a78e4f2383cef346360cef2fe9f1015d05972f4df31c26f
|
|
4
|
+
data.tar.gz: 3f0238841652782eff513dfdaa4916e8151469db5749e95e661f9c0236c526f1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e46394c42fc5cadabd70e5917a795bc071667c4bdf69a2b0d1d1a53c1db547a9b3221839ca8463c738030192bf135998a2de5c3652c87b6523cd08f7e69d80ad
|
|
7
|
+
data.tar.gz: 0bbf17766315cd0bf21bd9ec5e402584212515094cd086a003c08e23594083e2ac5b44758f27b1750b82f284260c0eb8e4cb8d12e32357cf770efc917da6595e
|
data/.github/workflows/ruby.yml
CHANGED
|
@@ -11,39 +11,13 @@ on:
|
|
|
11
11
|
]
|
|
12
12
|
|
|
13
13
|
jobs:
|
|
14
|
-
ruby-2:
|
|
15
|
-
runs-on: ubuntu-latest
|
|
16
|
-
strategy:
|
|
17
|
-
fail-fast: false
|
|
18
|
-
matrix:
|
|
19
|
-
ruby: [2.6, 2.7]
|
|
20
|
-
gemfile: [rails.5.2.activerecord, rails.6.0.activerecord, rails.6.1.activerecord]
|
|
21
|
-
name: ${{ matrix.ruby }}-${{ matrix.gemfile }}
|
|
22
|
-
|
|
23
|
-
env:
|
|
24
|
-
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
|
25
|
-
|
|
26
|
-
steps:
|
|
27
|
-
- uses: actions/checkout@v4
|
|
28
|
-
- uses: ruby/setup-ruby@v1
|
|
29
|
-
with:
|
|
30
|
-
ruby-version: ${{ matrix.ruby }}
|
|
31
|
-
bundler-cache: true
|
|
32
|
-
- name: Run Elasticsearch
|
|
33
|
-
uses: elastic/elastic-github-actions/elasticsearch@9de0f78f306e4ebc0838f057e6b754364685e759
|
|
34
|
-
with:
|
|
35
|
-
stack-version: 7.10.1
|
|
36
|
-
port: 9250
|
|
37
|
-
- name: Tests
|
|
38
|
-
run: bundle exec rspec
|
|
39
|
-
|
|
40
14
|
ruby-3:
|
|
41
15
|
runs-on: ubuntu-latest
|
|
42
16
|
strategy:
|
|
43
17
|
fail-fast: false
|
|
44
18
|
matrix:
|
|
45
19
|
ruby: [ '3.0', '3.1', '3.2' ]
|
|
46
|
-
gemfile: [
|
|
20
|
+
gemfile: [rails.6.1.activerecord, rails.7.0.activerecord, rails.7.1.activerecord]
|
|
47
21
|
name: ${{ matrix.ruby }}-${{ matrix.gemfile }}
|
|
48
22
|
|
|
49
23
|
env:
|
|
@@ -69,6 +43,6 @@ jobs:
|
|
|
69
43
|
- uses: actions/checkout@v4
|
|
70
44
|
- uses: ruby/setup-ruby@v1
|
|
71
45
|
with:
|
|
72
|
-
ruby-version:
|
|
46
|
+
ruby-version: 3.0
|
|
73
47
|
bundler-cache: true
|
|
74
48
|
- run: bundle exec rubocop --format simple
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,26 @@
|
|
|
8
8
|
|
|
9
9
|
### Bugs Fixed
|
|
10
10
|
|
|
11
|
+
## 7.4.0 (2023-12-13)
|
|
12
|
+
|
|
13
|
+
### New Features
|
|
14
|
+
|
|
15
|
+
### Changes
|
|
16
|
+
|
|
17
|
+
* [#911](https://github.com/toptal/chewy/pull/911): Remove ruby 2.x. ([@konalegi][https://github.com/konalegi])
|
|
18
|
+
|
|
19
|
+
### Bugs Fixed
|
|
20
|
+
|
|
21
|
+
## 7.3.5 (2023-12-13)
|
|
22
|
+
|
|
23
|
+
### New Features
|
|
24
|
+
|
|
25
|
+
* [#890](https://github.com/toptal/chewy/pull/890): Add the [`knn`](https://www.elastic.co/guide/en/elasticsearch/reference/current/knn-search.html) option to the request. ([@jkostolansky][])
|
|
26
|
+
|
|
27
|
+
### Changes
|
|
28
|
+
|
|
29
|
+
### Bugs Fixed
|
|
30
|
+
|
|
11
31
|
## 7.3.5 (2023-12-06)
|
|
12
32
|
|
|
13
33
|
### New Features
|
data/Gemfile
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
2
|
|
|
3
|
-
gemspec
|
|
4
|
-
|
|
5
3
|
gem 'activerecord'
|
|
6
4
|
|
|
7
5
|
gem 'activejob', require: false
|
|
@@ -18,5 +16,7 @@ gem 'guard-rspec'
|
|
|
18
16
|
gem 'redcarpet'
|
|
19
17
|
gem 'yard'
|
|
20
18
|
|
|
21
|
-
gem 'rexml'
|
|
22
|
-
|
|
19
|
+
gem 'rexml'
|
|
20
|
+
|
|
21
|
+
eval_gemfile 'gemfiles/base.gemfile'
|
|
22
|
+
gemspec
|
data/README.md
CHANGED
data/chewy.gemspec
CHANGED
|
@@ -2,7 +2,7 @@ lib = File.expand_path('lib', __dir__)
|
|
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
require 'chewy/version'
|
|
4
4
|
|
|
5
|
-
Gem::Specification.new do |spec|
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
6
|
spec.name = 'chewy'
|
|
7
7
|
spec.version = Chewy::VERSION
|
|
8
8
|
spec.authors = ['Toptal, LLC', 'pyromaniac']
|
|
@@ -14,24 +14,10 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
|
|
14
14
|
|
|
15
15
|
spec.files = `git ls-files`.split($RS)
|
|
16
16
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
17
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
18
17
|
spec.require_paths = ['lib']
|
|
19
18
|
|
|
20
|
-
spec.
|
|
21
|
-
spec.add_development_dependency 'elasticsearch-extensions'
|
|
22
|
-
spec.add_development_dependency 'mock_redis'
|
|
23
|
-
spec.add_development_dependency 'rake'
|
|
24
|
-
spec.add_development_dependency 'rspec', '>= 3.7.0'
|
|
25
|
-
spec.add_development_dependency 'rspec-collection_matchers'
|
|
26
|
-
spec.add_development_dependency 'rspec-its'
|
|
27
|
-
spec.add_development_dependency 'rubocop', '1.11'
|
|
28
|
-
spec.add_development_dependency 'sqlite3'
|
|
29
|
-
spec.add_development_dependency 'timecop'
|
|
30
|
-
|
|
31
|
-
spec.add_development_dependency 'method_source'
|
|
32
|
-
spec.add_development_dependency 'unparser'
|
|
33
|
-
|
|
34
|
-
spec.add_dependency 'activesupport', '>= 5.2'
|
|
19
|
+
spec.add_dependency 'activesupport', '>= 5.2' # Remove with major version bump, 8.x
|
|
35
20
|
spec.add_dependency 'elasticsearch', '>= 7.12.0', '< 7.14.0'
|
|
36
21
|
spec.add_dependency 'elasticsearch-dsl'
|
|
22
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
37
23
|
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
gem 'database_cleaner'
|
|
2
|
+
gem 'elasticsearch-extensions'
|
|
3
|
+
gem 'method_source'
|
|
4
|
+
gem 'mock_redis'
|
|
5
|
+
gem 'rake'
|
|
6
|
+
gem 'rspec', '>= 3.7.0'
|
|
7
|
+
gem 'rspec-collection_matchers'
|
|
8
|
+
gem 'rspec-its'
|
|
9
|
+
gem 'rubocop', '1.48'
|
|
10
|
+
gem 'sqlite3'
|
|
11
|
+
gem 'timecop'
|
|
12
|
+
gem 'unparser'
|
data/lib/chewy/config.rb
CHANGED
|
@@ -127,17 +127,19 @@ module Chewy
|
|
|
127
127
|
private
|
|
128
128
|
|
|
129
129
|
def yaml_settings
|
|
130
|
-
@yaml_settings ||=
|
|
131
|
-
|
|
132
|
-
file = Rails.root.join('config', 'chewy.yml')
|
|
130
|
+
@yaml_settings ||= build_yaml_settings || {}
|
|
131
|
+
end
|
|
133
132
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
133
|
+
def build_yaml_settings
|
|
134
|
+
return unless defined?(Rails::VERSION)
|
|
135
|
+
|
|
136
|
+
file = Rails.root.join('config', 'chewy.yml')
|
|
137
|
+
|
|
138
|
+
return unless File.exist?(file)
|
|
139
|
+
|
|
140
|
+
yaml = ERB.new(File.read(file)).result
|
|
141
|
+
hash = YAML.unsafe_load(yaml)
|
|
142
|
+
hash[Rails.env].try(:deep_symbolize_keys) if hash
|
|
141
143
|
end
|
|
142
144
|
|
|
143
145
|
def build_search_class(base)
|
data/lib/chewy/fields/root.rb
CHANGED
|
@@ -6,7 +6,7 @@ module Chewy
|
|
|
6
6
|
class ActiveRecord < Orm
|
|
7
7
|
def self.accepts?(target)
|
|
8
8
|
defined?(::ActiveRecord::Base) && (
|
|
9
|
-
target.is_a?(Class) && target < ::ActiveRecord::Base ||
|
|
9
|
+
(target.is_a?(Class) && target < ::ActiveRecord::Base) ||
|
|
10
10
|
target.is_a?(::ActiveRecord::Relation))
|
|
11
11
|
end
|
|
12
12
|
|
|
@@ -85,7 +85,7 @@ module Chewy
|
|
|
85
85
|
# @param args [Array<#to_json>]
|
|
86
86
|
# @option options [Integer] :batch_size import processing batch size
|
|
87
87
|
# @return [true, false]
|
|
88
|
-
|
|
88
|
+
def import(*args, &block)
|
|
89
89
|
collection, options = import_args(*args)
|
|
90
90
|
import_objects(collection, options, &block)
|
|
91
91
|
end
|
|
@@ -113,7 +113,7 @@ module Chewy
|
|
|
113
113
|
# end
|
|
114
114
|
#
|
|
115
115
|
# @see Chewy::Index::Adapter::Base#import_fields
|
|
116
|
-
|
|
116
|
+
def import_fields(*args, &block)
|
|
117
117
|
return enum_for(:import_fields, *args) unless block_given?
|
|
118
118
|
|
|
119
119
|
options = args.extract_options!
|
|
@@ -139,7 +139,7 @@ module Chewy
|
|
|
139
139
|
# For the Object adapter returns the objects themselves in batches.
|
|
140
140
|
#
|
|
141
141
|
# @see Chewy::Index::Adapter::Base#import_references
|
|
142
|
-
|
|
142
|
+
def import_references(*args, &block)
|
|
143
143
|
return enum_for(:import_references, *args) unless block_given?
|
|
144
144
|
|
|
145
145
|
collection, options = import_args(*args)
|
|
@@ -72,7 +72,7 @@ module Chewy
|
|
|
72
72
|
# # or
|
|
73
73
|
# UsersIndex.import users.map(&:id) # user ids will be deleted from index
|
|
74
74
|
#
|
|
75
|
-
|
|
75
|
+
def import(*args, &block)
|
|
76
76
|
collection, options = import_args(*args)
|
|
77
77
|
|
|
78
78
|
if !collection.is_a?(relation_class) || options[:direct_import]
|
|
@@ -82,7 +82,7 @@ module Chewy
|
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
def import_fields(*args, &block)
|
|
86
86
|
return enum_for(:import_fields, *args) unless block_given?
|
|
87
87
|
|
|
88
88
|
collection, options = import_args(*args)
|
|
@@ -162,12 +162,12 @@ module Chewy
|
|
|
162
162
|
.filter(ids: {values: ids_for_cache})
|
|
163
163
|
.order('_doc')
|
|
164
164
|
.pluck(:_id, :_routing, join_field)
|
|
165
|
-
.
|
|
165
|
+
.to_h do |id, routing, join|
|
|
166
166
|
[
|
|
167
167
|
id,
|
|
168
168
|
{routing: routing, parent_id: join['parent']}
|
|
169
169
|
]
|
|
170
|
-
end
|
|
170
|
+
end
|
|
171
171
|
end
|
|
172
172
|
|
|
173
173
|
def existing_routing(id)
|
data/lib/chewy/index/import.rb
CHANGED
|
@@ -72,7 +72,7 @@ module Chewy
|
|
|
72
72
|
# @option options [true, false] update_failover enables full objects reimport in cases of partial update errors, `true` by default
|
|
73
73
|
# @option options [true, Integer, Hash] parallel enables parallel import processing with the Parallel gem, accepts the number of workers or any Parallel gem acceptable options
|
|
74
74
|
# @return [true, false] false in case of errors
|
|
75
|
-
|
|
75
|
+
def import(*args)
|
|
76
76
|
intercept_import_using_strategy(*args).blank?
|
|
77
77
|
end
|
|
78
78
|
|
|
@@ -83,7 +83,7 @@ module Chewy
|
|
|
83
83
|
# in case of any import errors.
|
|
84
84
|
#
|
|
85
85
|
# @raise [Chewy::ImportFailed] in case of errors
|
|
86
|
-
|
|
86
|
+
def import!(*args)
|
|
87
87
|
errors = intercept_import_using_strategy(*args)
|
|
88
88
|
|
|
89
89
|
raise Chewy::ImportFailed.new(self, errors) if errors.present?
|
|
@@ -71,7 +71,7 @@ module Chewy
|
|
|
71
71
|
end
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
def update_index(type_name, *args, &block)
|
|
75
75
|
callback_options = Observe.extract_callback_options!(args)
|
|
76
76
|
update_proc = Observe.update_proc(type_name, *args, &block)
|
|
77
77
|
callback = Chewy::Index::Observe::Callback.new(update_proc, callback_options)
|
data/lib/chewy/index/syncer.rb
CHANGED
|
@@ -27,7 +27,7 @@ module Chewy
|
|
|
27
27
|
# @see Chewy::Index::Actions::ClassMethods#sync
|
|
28
28
|
class Syncer
|
|
29
29
|
DEFAULT_SYNC_BATCH_SIZE = 20_000
|
|
30
|
-
ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z
|
|
30
|
+
ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/
|
|
31
31
|
OUTDATED_IDS_WORKER = lambda do |outdated_sync_field_type, source_data_hash, index, total, index_data|
|
|
32
32
|
::Process.setproctitle("chewy [#{index}]: sync outdated calculation (#{::Parallel.worker_number + 1}/#{total})") if index
|
|
33
33
|
index_data.each_with_object([]) do |(id, index_sync_value), result|
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
# The class will capture the data from the *param on the Chewy::Index.bulk method and
|
|
7
7
|
# aggregate the data for test analysis.
|
|
8
8
|
class SearchIndexReceiver
|
|
9
|
+
MUTATION_FOR_CLASS = Struct.new(:indexes, :deletes, keyword_init: true)
|
|
10
|
+
|
|
9
11
|
def initialize
|
|
10
12
|
@mutations = {}
|
|
11
13
|
end
|
|
@@ -71,6 +73,6 @@ private
|
|
|
71
73
|
# @param index [Chewy::Index] the index to fetch.
|
|
72
74
|
# @return [#indexes, #deletes] an object with a list of indexes and a list of deletes.
|
|
73
75
|
def mutation_for(index)
|
|
74
|
-
@mutations[index] ||=
|
|
76
|
+
@mutations[index] ||= MUTATION_FOR_CLASS.new(indexes: [], deletes: [])
|
|
75
77
|
end
|
|
76
78
|
end
|
data/lib/chewy/rake_helper.rb
CHANGED
|
@@ -347,9 +347,9 @@ module Chewy
|
|
|
347
347
|
return if journal_exists?
|
|
348
348
|
|
|
349
349
|
output.puts "############################################################\n" \
|
|
350
|
-
"WARN: You are risking to lose some changes during the reset.\n" \
|
|
351
|
-
"
|
|
352
|
-
"
|
|
350
|
+
"WARN: You are risking to lose some changes during the reset.\n " \
|
|
351
|
+
"Please consider enabling journaling.\n " \
|
|
352
|
+
"See https://github.com/toptal/chewy#journaling\n" \
|
|
353
353
|
'############################################################'
|
|
354
354
|
end
|
|
355
355
|
|
|
@@ -108,7 +108,7 @@ RSpec::Matchers.define :update_index do |index_name, options = {}| # rubocop:dis
|
|
|
108
108
|
params_matcher = @no_refresh ? has_entry(refresh: false) : any_parameters
|
|
109
109
|
Chewy::Index::Import::BulkRequest.stubs(:new).with(index, params_matcher).returns(mock_bulk_request)
|
|
110
110
|
else
|
|
111
|
-
mocked_already =
|
|
111
|
+
mocked_already = RSpec::Mocks.space.proxy_for(Chewy::Index::Import::BulkRequest).method_double_if_exists_for_message(:new)
|
|
112
112
|
allow(Chewy::Index::Import::BulkRequest).to receive(:new).and_call_original unless mocked_already
|
|
113
113
|
params_matcher = @no_refresh ? hash_including(refresh: false) : any_args
|
|
114
114
|
allow(Chewy::Index::Import::BulkRequest).to receive(:new).with(index, params_matcher).and_return(mock_bulk_request)
|
|
@@ -220,7 +220,7 @@ RSpec::Matchers.define :update_index do |index_name, options = {}| # rubocop:dis
|
|
|
220
220
|
expected_count = options[:times] || options[:count]
|
|
221
221
|
expected_attributes = (options[:with] || options[:attributes] || {}).deep_symbolize_keys
|
|
222
222
|
|
|
223
|
-
args.flatten.
|
|
223
|
+
args.flatten.to_h do |document|
|
|
224
224
|
id = document.respond_to?(:id) ? document.id.to_s : document.to_s
|
|
225
225
|
[id, {
|
|
226
226
|
document: document,
|
|
@@ -229,7 +229,7 @@ RSpec::Matchers.define :update_index do |index_name, options = {}| # rubocop:dis
|
|
|
229
229
|
real_count: 0,
|
|
230
230
|
real_attributes: {}
|
|
231
231
|
}]
|
|
232
|
-
end
|
|
232
|
+
end
|
|
233
233
|
end
|
|
234
234
|
|
|
235
235
|
def compare_attributes(expected, real)
|
|
@@ -5,7 +5,7 @@ module Chewy
|
|
|
5
5
|
attr_reader :major, :minor, :patch
|
|
6
6
|
|
|
7
7
|
def initialize(version)
|
|
8
|
-
@major, @minor, @patch = *(version.to_s.split('.', 3) + [0] * 3).first(3).map(&:to_i)
|
|
8
|
+
@major, @minor, @patch = *(version.to_s.split('.', 3) + ([0] * 3)).first(3).map(&:to_i)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def to_s
|
|
@@ -17,7 +17,7 @@ module Chewy
|
|
|
17
17
|
# @param other [Chewy::Search::Parameters::Storage] any storage instance
|
|
18
18
|
# @return [true, false] the result of comparison
|
|
19
19
|
def ==(other)
|
|
20
|
-
super || other.class == self.class && other.render == render
|
|
20
|
+
super || (other.class == self.class && other.render == render)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
# Just adds indices to indices.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'chewy/search/parameters/storage'
|
|
2
|
+
|
|
3
|
+
module Chewy
|
|
4
|
+
module Search
|
|
5
|
+
class Parameters
|
|
6
|
+
# Just a standard hash storage. Nothing to see here.
|
|
7
|
+
#
|
|
8
|
+
# @see Chewy::Search::Parameters::HashStorage
|
|
9
|
+
# @see Chewy::Search::Request#knn
|
|
10
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/knn-search.html
|
|
11
|
+
class Knn < Storage
|
|
12
|
+
include HashStorage
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -35,7 +35,7 @@ module Chewy
|
|
|
35
35
|
# @param other [Chewy::Search::Parameters::Storage] any storage instance
|
|
36
36
|
# @return [true, false] the result of comparision
|
|
37
37
|
def ==(other)
|
|
38
|
-
super || other.class == self.class && other.value == value
|
|
38
|
+
super || (other.class == self.class && other.value == value)
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
# Replaces current value with normalized provided one. Doesn't
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
Dir.glob(File.join(File.dirname(__FILE__), 'parameters', 'concerns', '*.rb')).
|
|
2
|
-
Dir.glob(File.join(File.dirname(__FILE__), 'parameters', '*.rb')).
|
|
1
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'parameters', 'concerns', '*.rb')).each { |f| require f }
|
|
2
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'parameters', '*.rb')).each { |f| require f }
|
|
3
3
|
|
|
4
4
|
module Chewy
|
|
5
5
|
module Search
|
|
@@ -53,7 +53,7 @@ module Chewy
|
|
|
53
53
|
# @param other [Object] any object
|
|
54
54
|
# @return [true, false]
|
|
55
55
|
def ==(other)
|
|
56
|
-
super || other.is_a?(self.class) && compare_storages(other)
|
|
56
|
+
super || (other.is_a?(self.class) && compare_storages(other))
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
# Clones the specified storage, performs the operation
|
data/lib/chewy/search/request.rb
CHANGED
|
@@ -20,7 +20,7 @@ module Chewy
|
|
|
20
20
|
UNDEFINED = Class.new.freeze
|
|
21
21
|
EVERFIELDS = %w[_index _type _id _parent _routing].freeze
|
|
22
22
|
DELEGATED_METHODS = %i[
|
|
23
|
-
query filter post_filter order reorder docvalue_fields
|
|
23
|
+
query filter post_filter knn order reorder docvalue_fields
|
|
24
24
|
track_scores track_total_hits request_cache explain version profile
|
|
25
25
|
search_type preference limit offset terminate_after
|
|
26
26
|
timeout min_score source stored_fields search_after
|
|
@@ -41,7 +41,7 @@ module Chewy
|
|
|
41
41
|
EXTRA_STORAGES = %i[aggs suggest].freeze
|
|
42
42
|
# An array of storage names that are changing the returned hist collection in any way.
|
|
43
43
|
WHERE_STORAGES = %i[
|
|
44
|
-
query filter post_filter none min_score rescore indices_boost collapse
|
|
44
|
+
query filter post_filter knn none min_score rescore indices_boost collapse
|
|
45
45
|
].freeze
|
|
46
46
|
|
|
47
47
|
delegate :hits, :wrappers, :objects, :records, :documents,
|
|
@@ -520,7 +520,18 @@ module Chewy
|
|
|
520
520
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/collapse-search-results.html
|
|
521
521
|
# @param value [Hash]
|
|
522
522
|
# @return [Chewy::Search::Request]
|
|
523
|
-
|
|
523
|
+
#
|
|
524
|
+
# @!method knn(value)
|
|
525
|
+
# Replaces the value of the `knn` request part.
|
|
526
|
+
#
|
|
527
|
+
# @example
|
|
528
|
+
# PlacesIndex.knn(field: :vector, query_vector: [4, 2], k: 5, num_candidates: 50)
|
|
529
|
+
# # => <PlacesIndex::Query {..., :body=>{:knn=>{"field"=>:vector, "query_vector"=>[4, 2], "k"=>5, "num_candidates"=>50}}}>
|
|
530
|
+
# @see Chewy::Search::Parameters::Knn
|
|
531
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/knn-search.html
|
|
532
|
+
# @param value [Hash]
|
|
533
|
+
# @return [Chewy::Search::Request]
|
|
534
|
+
%i[request_cache search_type preference timeout limit offset terminate_after min_score ignore_unavailable collapse knn].each do |name|
|
|
524
535
|
define_method name do |value|
|
|
525
536
|
modify(name) { replace!(value) }
|
|
526
537
|
end
|
data/lib/chewy/search.rb
CHANGED
|
@@ -56,7 +56,7 @@ module Chewy
|
|
|
56
56
|
#
|
|
57
57
|
# @example
|
|
58
58
|
# PlacesIndex.query(match: {name: 'Moscow'})
|
|
59
|
-
|
|
59
|
+
def method_missing(name, *args, &block)
|
|
60
60
|
if search_class::DELEGATED_METHODS.include?(name)
|
|
61
61
|
all.send(name, *args, &block)
|
|
62
62
|
else
|
|
@@ -84,10 +84,12 @@ module Chewy
|
|
|
84
84
|
def delegate_scoped(source, destination, methods)
|
|
85
85
|
methods.each do |method|
|
|
86
86
|
destination.class_eval do
|
|
87
|
-
define_method method do |*args, &block|
|
|
88
|
-
scoping
|
|
87
|
+
define_method method do |*args, **kwargs, &block|
|
|
88
|
+
scoping do
|
|
89
|
+
source.public_send(method, *args, **kwargs, &block)
|
|
90
|
+
end
|
|
89
91
|
end
|
|
90
|
-
|
|
92
|
+
method
|
|
91
93
|
end
|
|
92
94
|
end
|
|
93
95
|
end
|
data/lib/chewy/version.rb
CHANGED
data/lib/chewy.rb
CHANGED
|
@@ -48,7 +48,7 @@ require 'chewy/index'
|
|
|
48
48
|
require 'chewy/fields/base'
|
|
49
49
|
require 'chewy/fields/root'
|
|
50
50
|
require 'chewy/journal'
|
|
51
|
-
require 'chewy/railtie' if defined?(
|
|
51
|
+
require 'chewy/railtie' if defined?(Rails::Railtie)
|
|
52
52
|
|
|
53
53
|
ActiveSupport.on_load(:active_record) do
|
|
54
54
|
include Chewy::Index::Observe::ActiveRecordMethods
|
|
@@ -610,7 +610,7 @@ describe Chewy::Index::Actions do
|
|
|
610
610
|
specify 'with journal application' do
|
|
611
611
|
cities
|
|
612
612
|
p 'cities created1'
|
|
613
|
-
|
|
613
|
+
ActiveRecord::Base.connection.close if defined?(ActiveRecord::Base)
|
|
614
614
|
[
|
|
615
615
|
parallel_update,
|
|
616
616
|
Thread.new do
|
|
@@ -619,7 +619,7 @@ describe Chewy::Index::Actions do
|
|
|
619
619
|
p 'end reset1'
|
|
620
620
|
end
|
|
621
621
|
].map(&:join)
|
|
622
|
-
|
|
622
|
+
ActiveRecord::Base.connection.reconnect! if defined?(ActiveRecord::Base)
|
|
623
623
|
p 'expect1'
|
|
624
624
|
expect(CitiesIndex::City.pluck(:_id, :name)).to contain_exactly(%w[1 NewName1], %w[2 Name2], %w[3 NewName3])
|
|
625
625
|
p 'end expect1'
|
|
@@ -628,7 +628,7 @@ describe Chewy::Index::Actions do
|
|
|
628
628
|
specify 'without journal application' do
|
|
629
629
|
cities
|
|
630
630
|
p 'cities created2'
|
|
631
|
-
|
|
631
|
+
ActiveRecord::Base.connection.close if defined?(ActiveRecord::Base)
|
|
632
632
|
[
|
|
633
633
|
parallel_update,
|
|
634
634
|
Thread.new do
|
|
@@ -637,7 +637,7 @@ describe Chewy::Index::Actions do
|
|
|
637
637
|
p 'end reset2'
|
|
638
638
|
end
|
|
639
639
|
].map(&:join)
|
|
640
|
-
|
|
640
|
+
ActiveRecord::Base.connection.reconnect! if defined?(ActiveRecord::Base)
|
|
641
641
|
p 'expect2'
|
|
642
642
|
expect(CitiesIndex::City.pluck(:_id, :name)).to contain_exactly(%w[1 Name1], %w[2 Name2], %w[3 Name3])
|
|
643
643
|
p 'end expect2'
|
|
@@ -132,7 +132,7 @@ describe Chewy::Index::Import::BulkBuilder do
|
|
|
132
132
|
before do
|
|
133
133
|
stub_index(:cities) do
|
|
134
134
|
crutch :names do |collection|
|
|
135
|
-
collection.
|
|
135
|
+
collection.to_h { |item| [item.id, "Name#{item.id}"] }
|
|
136
136
|
end
|
|
137
137
|
|
|
138
138
|
field :name, value: ->(o, c) { c.names[o.id] }
|
|
@@ -198,7 +198,7 @@ describe Chewy::Index::Import::BulkBuilder do
|
|
|
198
198
|
index_scope Comment
|
|
199
199
|
|
|
200
200
|
crutch :content_with_crutches do |collection| # collection here is a current batch of products
|
|
201
|
-
collection.
|
|
201
|
+
collection.to_h { |comment| [comment.id, "[crutches] #{comment.content}"] }
|
|
202
202
|
end
|
|
203
203
|
|
|
204
204
|
field :content
|
|
@@ -272,7 +272,7 @@ describe Chewy::Index::Import::BulkBuilder do
|
|
|
272
272
|
default_import_options raw_import: ->(hash) { SimpleComment.new(hash) }
|
|
273
273
|
|
|
274
274
|
crutch :content_with_crutches do |collection| # collection here is a current batch of products
|
|
275
|
-
collection.
|
|
275
|
+
collection.to_h { |comment| [comment.id, "[crutches] #{comment.content}"] }
|
|
276
276
|
end
|
|
277
277
|
|
|
278
278
|
field :content
|
|
@@ -215,8 +215,8 @@ describe Chewy::Index::Import do
|
|
|
215
215
|
payload = subscribe_notification
|
|
216
216
|
import dummy_cities, batch_size: 2
|
|
217
217
|
expect(payload).to eq(index: CitiesIndex,
|
|
218
|
-
|
|
219
|
-
|
|
218
|
+
errors: {index: {mapper_parsing_exception => %w[1 2 3]}},
|
|
219
|
+
import: {index: 3})
|
|
220
220
|
end
|
|
221
221
|
end
|
|
222
222
|
end
|
|
@@ -567,7 +567,7 @@ describe Chewy::Index::Import do
|
|
|
567
567
|
before do
|
|
568
568
|
stub_index(:cities) do
|
|
569
569
|
crutch :names do |collection|
|
|
570
|
-
collection.
|
|
570
|
+
collection.to_h { |o| [o.name, "#{o.name}42"] }
|
|
571
571
|
end
|
|
572
572
|
field :name, value: ->(o, c) { c.names[o.name] }
|
|
573
573
|
field :rating
|