chewy 7.2.2 → 7.2.3
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 -2
- data/CHANGELOG.md +20 -0
- data/chewy.gemspec +1 -1
- data/lib/chewy/config.rb +1 -1
- data/lib/chewy/rake_helper.rb +21 -1
- data/lib/chewy/runtime.rb +1 -1
- data/lib/chewy/search/parameters/ignore_unavailable.rb +27 -0
- data/lib/chewy/search/parameters/track_total_hits.rb +16 -0
- data/lib/chewy/search/parameters.rb +1 -1
- data/lib/chewy/search/request.rb +28 -4
- data/lib/chewy/search/scoping.rb +1 -1
- data/lib/chewy/version.rb +1 -1
- data/lib/chewy.rb +15 -5
- data/spec/chewy/rake_helper_spec.rb +19 -0
- data/spec/chewy/search/parameters/ignore_unavailable_spec.rb +67 -0
- data/spec/chewy/search/parameters/track_total_hits_spec.rb +5 -0
- data/spec/chewy/search/parameters_spec.rb +5 -0
- data/spec/chewy/search/request_spec.rb +20 -8
- data/spec/chewy_spec.rb +3 -3
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a027fc99d931ad37a70f2cdf906363917af16afc6dd82bbc1da8066e63dad9ee
|
4
|
+
data.tar.gz: 602bbb699c4971f8653207bb52d8bb7c40899128b1c6034c89f0f4481207f569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 444a1e44ad27a6d066daf31ceee258ee51e4ef1398fe6af4bf7294090b2391d2f136aa1726d5eb9f1c22f1c87abfd16f4a05c1198a0496e2062a13f8f31340db
|
7
|
+
data.tar.gz: 5f484506393af6b6959593850c9c7cb73307628076eb9676bd72e53b7fa02a987986d79443c35c2c7a0efd652615fb7ccf6ed418ab7bdf85eb69fbe6b2b02c24
|
data/.github/workflows/ruby.yml
CHANGED
@@ -22,7 +22,7 @@ jobs:
|
|
22
22
|
ruby-version: ${{ matrix.ruby }}
|
23
23
|
bundler-cache: true
|
24
24
|
- name: Run Elasticsearch
|
25
|
-
uses: elastic/elastic-github-actions/elasticsearch@
|
25
|
+
uses: elastic/elastic-github-actions/elasticsearch@9de0f78f306e4ebc0838f057e6b754364685e759
|
26
26
|
with:
|
27
27
|
stack-version: 7.10.1
|
28
28
|
port: 9250
|
@@ -40,7 +40,7 @@ jobs:
|
|
40
40
|
ruby-version: '3.0'
|
41
41
|
bundler-cache: true
|
42
42
|
- name: Run Elasticsearch
|
43
|
-
uses: elastic/elastic-github-actions/elasticsearch@
|
43
|
+
uses: elastic/elastic-github-actions/elasticsearch@9de0f78f306e4ebc0838f057e6b754364685e759
|
44
44
|
with:
|
45
45
|
stack-version: 7.10.1
|
46
46
|
port: 9250
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,22 @@
|
|
8
8
|
|
9
9
|
### Bugs Fixed
|
10
10
|
|
11
|
+
## 7.2.3 (2021-10-29)
|
12
|
+
|
13
|
+
### New Features
|
14
|
+
|
15
|
+
* [#801](https://github.com/toptal/chewy/pull/801): Add the [`track_total_hits`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-your-data.html#track-total-hits) option to the query. ([@milk1000cc][])
|
16
|
+
* [#810](https://github.com/toptal/chewy/pull/810): Use `unsafe_load` when loading config to support Psych 4.
|
17
|
+
* [#819](https://github.com/toptal/chewy/pull/819): Add the [`ignore_unavailable`](https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-index.html#multi-index) option to the request. ([@kolauren][])
|
18
|
+
|
19
|
+
### Changes
|
20
|
+
|
21
|
+
* [#817](https://github.com/toptal/chewy/pull/817): Show warning message during rake chewy:reset or chewy:upgrade if journaling is disabled. ([@konalegi][])
|
22
|
+
|
23
|
+
### Bugs Fixed
|
24
|
+
|
25
|
+
* [#816](https://github.com/toptal/chewy/pull/816): Move query [`preference`](https://www.elastic.co/guide/en/elasticsearch/reference/7.x/search-search.html#search-preference) from body to query parameters. ([@afg419][])
|
26
|
+
|
11
27
|
## 7.2.2 (2021-05-24)
|
12
28
|
|
13
29
|
### Changes
|
@@ -621,6 +637,7 @@
|
|
621
637
|
[@aglushkov]: https://github.com/aglushkov
|
622
638
|
[@AlexVPopov]: https://github.com/AlexVPopov
|
623
639
|
[@AndreySavelyev]: https://github.com/AndreySavelyev
|
640
|
+
[@afg419]: https://github.com/afg419
|
624
641
|
[@arion]: https://github.com/arion
|
625
642
|
[@arturtr]: https://github.com/arturtr
|
626
643
|
[@averell23]: https://github.com/averell23
|
@@ -661,6 +678,7 @@
|
|
661
678
|
[@josephchoe]: https://github.com/josephchoe
|
662
679
|
[@jshirley]: https://github.com/jshirley
|
663
680
|
[@ka8725]: https://github.com/ka8725
|
681
|
+
[@kolauren]: https://github.com/kolauren
|
664
682
|
[@konalegi]: https://github.com/konalegi
|
665
683
|
[@lardawge]: https://github.com/lardawge
|
666
684
|
[@leemhenson]: https://github.com/leemhenson
|
@@ -674,6 +692,7 @@
|
|
674
692
|
[@mattzollinhofer]: https://github.com/mattzollinhofer
|
675
693
|
[@menglewis]: https://github.com/menglewis
|
676
694
|
[@mikeyhogarth]: https://github.com/mikeyhogarth
|
695
|
+
[@milk1000cc]: https://github.com/milk1000cc
|
677
696
|
[@mkcode]: https://github.com/mkcode
|
678
697
|
[@mpeychich]: https://github.com/mpeychich
|
679
698
|
[@mrbrdo]: https://github.com/mrbrdo
|
@@ -701,3 +720,4 @@
|
|
701
720
|
[@Vitalina-Vakulchyk]: https://github.com/Vitalina-Vakulchyk
|
702
721
|
[@webgago]: https://github.com/webgago
|
703
722
|
[@yahooguntu]: https://github.com/yahooguntu
|
723
|
+
|
data/chewy.gemspec
CHANGED
@@ -31,6 +31,6 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
|
31
31
|
spec.add_development_dependency 'unparser'
|
32
32
|
|
33
33
|
spec.add_dependency 'activesupport', '>= 5.2'
|
34
|
-
spec.add_dependency 'elasticsearch', '>= 7.12.0'
|
34
|
+
spec.add_dependency 'elasticsearch', '>= 7.12.0', '< 7.14.0'
|
35
35
|
spec.add_dependency 'elasticsearch-dsl'
|
36
36
|
end
|
data/lib/chewy/config.rb
CHANGED
@@ -133,7 +133,7 @@ module Chewy
|
|
133
133
|
|
134
134
|
if File.exist?(file)
|
135
135
|
yaml = ERB.new(File.read(file)).result
|
136
|
-
hash = YAML.load(yaml) # rubocop:disable Security/YAMLLoad
|
136
|
+
hash = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(yaml) : YAML.load(yaml) # rubocop:disable Security/YAMLLoad
|
137
137
|
hash[Rails.env].try(:deep_symbolize_keys) if hash
|
138
138
|
end
|
139
139
|
end || {}
|
data/lib/chewy/rake_helper.rb
CHANGED
@@ -35,6 +35,8 @@ module Chewy
|
|
35
35
|
# @param output [IO] output io for logging
|
36
36
|
# @return [Array<Chewy::Index>] indexes that were reset
|
37
37
|
def reset(only: nil, except: nil, parallel: nil, output: $stdout)
|
38
|
+
warn_missing_index(output)
|
39
|
+
|
38
40
|
subscribed_task_stats(output) do
|
39
41
|
indexes_from(only: only, except: except).each do |index|
|
40
42
|
reset_one(index, output, parallel: parallel)
|
@@ -58,6 +60,8 @@ module Chewy
|
|
58
60
|
# @param output [IO] output io for logging
|
59
61
|
# @return [Array<Chewy::Index>] indexes that were actually reset
|
60
62
|
def upgrade(only: nil, except: nil, parallel: nil, output: $stdout)
|
63
|
+
warn_missing_index(output)
|
64
|
+
|
61
65
|
subscribed_task_stats(output) do
|
62
66
|
indexes = indexes_from(only: only, except: except)
|
63
67
|
|
@@ -271,7 +275,23 @@ module Chewy
|
|
271
275
|
|
272
276
|
def reset_one(index, output, parallel: false)
|
273
277
|
output.puts "Resetting #{index}"
|
274
|
-
index.reset!((Time.now.to_f * 1000).round, parallel: parallel)
|
278
|
+
index.reset!((Time.now.to_f * 1000).round, parallel: parallel, apply_journal: journal_exists?)
|
279
|
+
end
|
280
|
+
|
281
|
+
def warn_missing_index(output)
|
282
|
+
return if journal_exists?
|
283
|
+
|
284
|
+
output.puts "############################################################\n" \
|
285
|
+
"WARN: You are risking to lose some changes during the reset.\n" \
|
286
|
+
" Please consider enabling journaling.\n" \
|
287
|
+
" See https://github.com/toptal/chewy#journaling\n" \
|
288
|
+
'############################################################'
|
289
|
+
end
|
290
|
+
|
291
|
+
def journal_exists?
|
292
|
+
@journal_exists = Chewy::Stash::Journal.exists? if @journal_exists.nil?
|
293
|
+
|
294
|
+
@journal_exists
|
275
295
|
end
|
276
296
|
end
|
277
297
|
end
|
data/lib/chewy/runtime.rb
CHANGED
@@ -3,7 +3,7 @@ require 'chewy/runtime/version'
|
|
3
3
|
module Chewy
|
4
4
|
module Runtime
|
5
5
|
def self.version
|
6
|
-
|
6
|
+
Chewy.current[:chewy_runtime_version] ||= Version.new(Chewy.client.info['version']['number'])
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'chewy/search/parameters/storage'
|
2
|
+
|
3
|
+
module Chewy
|
4
|
+
module Search
|
5
|
+
class Parameters
|
6
|
+
# Stores boolean value, but has 3 states: `true`, `false` and `nil`.
|
7
|
+
#
|
8
|
+
# @see Chewy::Search::Request#ignore_unavailable
|
9
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-index.html#multi-index
|
10
|
+
class IgnoreUnavailable < Storage
|
11
|
+
# We don't want to render `nil`, but render `true` and `false` values.
|
12
|
+
#
|
13
|
+
# @see Chewy::Search::Parameters::Storage#render
|
14
|
+
# @return [{Symbol => Object}, nil]
|
15
|
+
def render
|
16
|
+
{self.class.param_name => value} unless value.nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def normalize(value)
|
22
|
+
!!value unless value.nil?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'chewy/search/parameters/storage'
|
2
|
+
|
3
|
+
module Chewy
|
4
|
+
module Search
|
5
|
+
class Parameters
|
6
|
+
# Just a standard boolean storage, nothing to see here.
|
7
|
+
#
|
8
|
+
# @see Chewy::Search::Parameters::BoolStorage
|
9
|
+
# @see Chewy::Search::Request#track_total_hits
|
10
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-your-data.html#track-total-hits
|
11
|
+
class TrackTotalHits < Storage
|
12
|
+
include BoolStorage
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -10,7 +10,7 @@ module Chewy
|
|
10
10
|
# @see Chewy::Search::Request#parameters
|
11
11
|
# @see Chewy::Search::Parameters::Storage
|
12
12
|
class Parameters
|
13
|
-
QUERY_STRING_STORAGES = %i[indices search_type request_cache allow_partial_search_results].freeze
|
13
|
+
QUERY_STRING_STORAGES = %i[indices preference search_type request_cache allow_partial_search_results ignore_unavailable].freeze
|
14
14
|
|
15
15
|
# Default storage classes warehouse. It is probably possible to
|
16
16
|
# add your own classes here if necessary, but I'm not sure it will work.
|
data/lib/chewy/search/request.rb
CHANGED
@@ -21,14 +21,14 @@ module Chewy
|
|
21
21
|
EVERFIELDS = %w[_index _type _id _parent].freeze
|
22
22
|
DELEGATED_METHODS = %i[
|
23
23
|
query filter post_filter order reorder docvalue_fields
|
24
|
-
track_scores request_cache explain version profile
|
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
|
27
27
|
load script_fields suggest aggs aggregations none
|
28
28
|
indices_boost rescore highlight total total_count
|
29
29
|
total_entries indices types delete_all count exists?
|
30
30
|
exist? find pluck scroll_batches scroll_hits
|
31
|
-
scroll_results scroll_wrappers
|
31
|
+
scroll_results scroll_wrappers ignore_unavailable
|
32
32
|
].to_set.freeze
|
33
33
|
DEFAULT_BATCH_SIZE = 1000
|
34
34
|
DEFAULT_PLUCK_BATCH_SIZE = 10_000
|
@@ -336,6 +336,19 @@ module Chewy
|
|
336
336
|
# @param value [true, false]
|
337
337
|
# @return [Chewy::Search::Request]
|
338
338
|
#
|
339
|
+
# @!method track_total_hits(value = true)
|
340
|
+
# Replaces the value of the `track_total_hits` parameter with the provided value.
|
341
|
+
#
|
342
|
+
# @example
|
343
|
+
# PlacesIndex.track_total_hits
|
344
|
+
# # => <PlacesIndex::Query {..., :body=>{:track_total_hits=>true}}>
|
345
|
+
# PlacesIndex.track_total_hits.track_total_hits(false)
|
346
|
+
# # => <PlacesIndex::Query {:index=>["places"]}>
|
347
|
+
# @see Chewy::Search::Parameters::TrackTotalHits
|
348
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-your-data.html#track-total-hits
|
349
|
+
# @param value [true, false]
|
350
|
+
# @return [Chewy::Search::Request]
|
351
|
+
#
|
339
352
|
# @!method explain(value = true)
|
340
353
|
# Replaces the value of the `explain` parameter with the provided value.
|
341
354
|
#
|
@@ -388,7 +401,7 @@ module Chewy
|
|
388
401
|
# @see https://en.wikipedia.org/wiki/Null_Object_pattern
|
389
402
|
# @param value [true, false]
|
390
403
|
# @return [Chewy::Search::Request]
|
391
|
-
%i[track_scores explain version profile none].each do |name|
|
404
|
+
%i[track_scores track_total_hits explain version profile none].each do |name|
|
392
405
|
define_method name do |value = true|
|
393
406
|
modify(name) { replace!(value) }
|
394
407
|
end
|
@@ -485,7 +498,18 @@ module Chewy
|
|
485
498
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html#search-api-min-score
|
486
499
|
# @param value [String, Integer, Float]
|
487
500
|
# @return [Chewy::Search::Request]
|
488
|
-
|
501
|
+
#
|
502
|
+
# @!method ignore_unavailable(value)
|
503
|
+
# Replaces the value of the `ignore_unavailable` request part.
|
504
|
+
#
|
505
|
+
# @example
|
506
|
+
# PlacesIndex.ignore_unavailable(true)
|
507
|
+
# <PlacesIndex::Query {..., :ignore_unavailable => true, :body=>{ ... }}>
|
508
|
+
# @see Chewy::Search::Parameters::IgnoreUnavailable
|
509
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-index.html#multi-index
|
510
|
+
# @param value [true, false, nil]
|
511
|
+
# @return [Chewy::Search::Request]
|
512
|
+
%i[request_cache search_type preference timeout limit offset terminate_after min_score ignore_unavailable].each do |name|
|
489
513
|
define_method name do |value|
|
490
514
|
modify(name) { replace!(value) }
|
491
515
|
end
|
data/lib/chewy/search/scoping.rb
CHANGED
data/lib/chewy/version.rb
CHANGED
data/lib/chewy.rb
CHANGED
@@ -62,6 +62,16 @@ module Chewy
|
|
62
62
|
class << self
|
63
63
|
attr_accessor :adapters
|
64
64
|
|
65
|
+
# A thread-local variables accessor
|
66
|
+
# @return [Hash]
|
67
|
+
def current
|
68
|
+
unless Thread.current.thread_variable?(:chewy)
|
69
|
+
Thread.current.thread_variable_set(:chewy, {})
|
70
|
+
end
|
71
|
+
|
72
|
+
Thread.current.thread_variable_get(:chewy)
|
73
|
+
end
|
74
|
+
|
65
75
|
# Derives an index for the passed string identifier if possible.
|
66
76
|
#
|
67
77
|
# @example
|
@@ -86,7 +96,7 @@ module Chewy
|
|
86
96
|
# Main elasticsearch-ruby client instance
|
87
97
|
#
|
88
98
|
def client
|
89
|
-
|
99
|
+
Chewy.current[:chewy_client] ||= begin
|
90
100
|
client_configuration = configuration.deep_dup
|
91
101
|
client_configuration.delete(:prefix) # used by Chewy, not relevant to Elasticsearch::Client
|
92
102
|
block = client_configuration[:transport_options].try(:delete, :proc)
|
@@ -138,15 +148,15 @@ module Chewy
|
|
138
148
|
# city3.do_update! # index updated again
|
139
149
|
#
|
140
150
|
def strategy(name = nil, &block)
|
141
|
-
|
151
|
+
Chewy.current[:chewy_strategy] ||= Chewy::Strategy.new
|
142
152
|
if name
|
143
153
|
if block
|
144
|
-
|
154
|
+
Chewy.current[:chewy_strategy].wrap name, &block
|
145
155
|
else
|
146
|
-
|
156
|
+
Chewy.current[:chewy_strategy].push name
|
147
157
|
end
|
148
158
|
else
|
149
|
-
|
159
|
+
Chewy.current[:chewy_strategy]
|
150
160
|
end
|
151
161
|
end
|
152
162
|
|
@@ -4,6 +4,8 @@ describe Chewy::RakeHelper, :orm do
|
|
4
4
|
before { Chewy.massacre }
|
5
5
|
|
6
6
|
before do
|
7
|
+
described_class.instance_variable_set(:@journal_exists, journal_exists)
|
8
|
+
|
7
9
|
stub_model(:city)
|
8
10
|
stub_model(:country)
|
9
11
|
|
@@ -20,6 +22,7 @@ describe Chewy::RakeHelper, :orm do
|
|
20
22
|
allow(described_class).to receive(:all_indexes) { [CitiesIndex, CountriesIndex, UsersIndex] }
|
21
23
|
end
|
22
24
|
|
25
|
+
let(:journal_exists) { true }
|
23
26
|
let!(:cities) { Array.new(3) { |i| City.create!(name: "Name#{i + 1}") } }
|
24
27
|
let!(:countries) { Array.new(2) { |i| Country.create!(name: "Name#{i + 1}") } }
|
25
28
|
let(:journal) do
|
@@ -92,6 +95,22 @@ Total: \\d+s\\Z
|
|
92
95
|
Total: \\d+s\\Z
|
93
96
|
OUTPUT
|
94
97
|
end
|
98
|
+
|
99
|
+
context 'when journal is missing' do
|
100
|
+
let(:journal_exists) { false }
|
101
|
+
|
102
|
+
specify do
|
103
|
+
output = StringIO.new
|
104
|
+
expect { described_class.reset(only: [CitiesIndex], output: output) }
|
105
|
+
.to update_index(CitiesIndex)
|
106
|
+
expect(output.string).to include(
|
107
|
+
"############################################################\n"\
|
108
|
+
"WARN: You are risking to lose some changes during the reset.\n" \
|
109
|
+
" Please consider enabling journaling.\n" \
|
110
|
+
' See https://github.com/toptal/chewy#journaling'
|
111
|
+
)
|
112
|
+
end
|
113
|
+
end
|
95
114
|
end
|
96
115
|
|
97
116
|
describe '.upgrade' do
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chewy::Search::Parameters::IgnoreUnavailable do
|
4
|
+
subject { described_class.new(true) }
|
5
|
+
|
6
|
+
describe '#initialize' do
|
7
|
+
specify { expect(subject.value).to eq(true) }
|
8
|
+
specify { expect(described_class.new.value).to eq(nil) }
|
9
|
+
specify { expect(described_class.new(42).value).to eq(true) }
|
10
|
+
specify { expect(described_class.new(false).value).to eq(false) }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#replace!' do
|
14
|
+
specify { expect { subject.replace!(false) }.to change { subject.value }.from(true).to(false) }
|
15
|
+
specify { expect { subject.replace!(nil) }.to change { subject.value }.from(true).to(nil) }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#update!' do
|
19
|
+
specify { expect { subject.update!(nil) }.not_to change { subject.value }.from(true) }
|
20
|
+
specify { expect { subject.update!(false) }.to change { subject.value }.from(true).to(false) }
|
21
|
+
specify { expect { subject.update!(true) }.not_to change { subject.value }.from(true) }
|
22
|
+
|
23
|
+
context do
|
24
|
+
subject { described_class.new(false) }
|
25
|
+
|
26
|
+
specify { expect { subject.update!(nil) }.not_to change { subject.value }.from(false) }
|
27
|
+
specify { expect { subject.update!(false) }.not_to change { subject.value }.from(false) }
|
28
|
+
specify { expect { subject.update!(true) }.to change { subject.value }.from(false).to(true) }
|
29
|
+
end
|
30
|
+
|
31
|
+
context do
|
32
|
+
subject { described_class.new }
|
33
|
+
|
34
|
+
specify { expect { subject.update!(nil) }.not_to change { subject.value }.from(nil) }
|
35
|
+
specify { expect { subject.update!(false) }.to change { subject.value }.from(nil).to(false) }
|
36
|
+
specify { expect { subject.update!(true) }.to change { subject.value }.from(nil).to(true) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#merge!' do
|
41
|
+
specify { expect { subject.merge!(described_class.new) }.not_to change { subject.value }.from(true) }
|
42
|
+
specify { expect { subject.merge!(described_class.new(false)) }.to change { subject.value }.from(true).to(false) }
|
43
|
+
specify { expect { subject.merge!(described_class.new(true)) }.not_to change { subject.value }.from(true) }
|
44
|
+
|
45
|
+
context do
|
46
|
+
subject { described_class.new(false) }
|
47
|
+
|
48
|
+
specify { expect { subject.merge!(described_class.new) }.not_to change { subject.value }.from(false) }
|
49
|
+
specify { expect { subject.merge!(described_class.new(false)) }.not_to change { subject.value }.from(false) }
|
50
|
+
specify { expect { subject.merge!(described_class.new(true)) }.to change { subject.value }.from(false).to(true) }
|
51
|
+
end
|
52
|
+
|
53
|
+
context do
|
54
|
+
subject { described_class.new }
|
55
|
+
|
56
|
+
specify { expect { subject.merge!(described_class.new) }.not_to change { subject.value }.from(nil) }
|
57
|
+
specify { expect { subject.merge!(described_class.new(false)) }.to change { subject.value }.from(nil).to(false) }
|
58
|
+
specify { expect { subject.merge!(described_class.new(true)) }.to change { subject.value }.from(nil).to(true) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#render' do
|
63
|
+
specify { expect(described_class.new.render).to be_nil }
|
64
|
+
specify { expect(described_class.new(false).render).to eq(ignore_unavailable: false) }
|
65
|
+
specify { expect(subject.render).to eq(ignore_unavailable: true) }
|
66
|
+
end
|
67
|
+
end
|
@@ -128,6 +128,11 @@ describe Chewy::Search::Parameters do
|
|
128
128
|
specify { expect(subject.render).to eq(body: {}, allow_partial_search_results: true) }
|
129
129
|
end
|
130
130
|
|
131
|
+
context do
|
132
|
+
subject { described_class.new(ignore_unavailable: true) }
|
133
|
+
specify { expect(subject.render).to eq(body: {}, ignore_unavailable: true) }
|
134
|
+
end
|
135
|
+
|
131
136
|
context do
|
132
137
|
subject { described_class.new(query: {foo: 'bar'}, filter: {moo: 'baz'}) }
|
133
138
|
specify { expect(subject.render).to eq(body: {query: {bool: {must: {foo: 'bar'}, filter: {moo: 'baz'}}}}) }
|
@@ -192,7 +192,7 @@ describe Chewy::Search::Request do
|
|
192
192
|
specify { expect { subject.reorder(:foo) }.not_to change { subject.render } }
|
193
193
|
end
|
194
194
|
|
195
|
-
%i[track_scores explain version profile].each do |name|
|
195
|
+
%i[track_scores track_total_hits explain version profile].each do |name|
|
196
196
|
describe "##{name}" do
|
197
197
|
specify { expect(subject.send(name).render[:body]).to include(name => true) }
|
198
198
|
specify { expect(subject.send(name).send(name, false).render[:body]).to be_blank }
|
@@ -214,13 +214,18 @@ describe Chewy::Search::Request do
|
|
214
214
|
specify { expect { subject.search_type('foo') }.not_to change { subject.render } }
|
215
215
|
end
|
216
216
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
217
|
+
describe '#preference' do
|
218
|
+
specify { expect(subject.preference('foo').render).to include(preference: 'foo') }
|
219
|
+
specify { expect(subject.preference('foo').preference('bar').render).to include(preference: 'bar') }
|
220
|
+
specify { expect(subject.preference('foo').preference(nil).render[:preference]).to be_blank }
|
221
|
+
specify { expect { subject.preference('foo') }.not_to change { subject.render } }
|
222
|
+
end
|
223
|
+
|
224
|
+
describe '#timeout' do
|
225
|
+
specify { expect(subject.timeout(:foo).render[:body]).to include(timeout: 'foo') }
|
226
|
+
specify { expect(subject.timeout(:foo).timeout(:bar).render[:body]).to include(timeout: 'bar') }
|
227
|
+
specify { expect(subject.timeout(:foo).timeout(nil).render[:body]).to be_blank }
|
228
|
+
specify { expect { subject.timeout(:foo) }.not_to change { subject.render } }
|
224
229
|
end
|
225
230
|
|
226
231
|
describe '#source' do
|
@@ -361,6 +366,13 @@ describe Chewy::Search::Request do
|
|
361
366
|
specify { expect { subject.min_score(1.2) }.not_to change { subject.render } }
|
362
367
|
end
|
363
368
|
|
369
|
+
describe '#ignore_unavailable' do
|
370
|
+
specify { expect(subject.ignore_unavailable(true).render).to include(ignore_unavailable: true) }
|
371
|
+
specify { expect(subject.ignore_unavailable(true).ignore_unavailable(false).render).to include(ignore_unavailable: false) }
|
372
|
+
specify { expect(subject.ignore_unavailable(true).ignore_unavailable(nil).render[:ignore_unavailable]).to be_blank }
|
373
|
+
specify { expect { subject.ignore_unavailable(true) }.not_to change { subject.render } }
|
374
|
+
end
|
375
|
+
|
364
376
|
describe '#search_after' do
|
365
377
|
specify { expect(subject.search_after(:foo, :bar).render[:body]).to include(search_after: %i[foo bar]) }
|
366
378
|
specify do
|
data/spec/chewy_spec.rb
CHANGED
@@ -50,13 +50,13 @@ describe Chewy do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
describe '.client' do
|
53
|
-
let!(:initial_client) {
|
53
|
+
let!(:initial_client) { Chewy.current[:chewy_client] }
|
54
54
|
let(:faraday_block) { proc {} }
|
55
55
|
let(:mock_client) { double(:client) }
|
56
56
|
let(:expected_client_config) { {transport_options: {}} }
|
57
57
|
|
58
58
|
before do
|
59
|
-
|
59
|
+
Chewy.current[:chewy_client] = nil
|
60
60
|
allow(Chewy).to receive_messages(configuration: {transport_options: {proc: faraday_block}})
|
61
61
|
|
62
62
|
allow(::Elasticsearch::Client).to receive(:new).with(expected_client_config) do |*_args, &passed_block|
|
@@ -70,7 +70,7 @@ describe Chewy do
|
|
70
70
|
|
71
71
|
its(:client) { is_expected.to eq(mock_client) }
|
72
72
|
|
73
|
-
after {
|
73
|
+
after { Chewy.current[:chewy_client] = initial_client }
|
74
74
|
end
|
75
75
|
|
76
76
|
describe '.create_indices' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chewy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.2.
|
4
|
+
version: 7.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toptal, LLC
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-10-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: database_cleaner
|
@@ -186,6 +186,9 @@ dependencies:
|
|
186
186
|
- - ">="
|
187
187
|
- !ruby/object:Gem::Version
|
188
188
|
version: 7.12.0
|
189
|
+
- - "<"
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: 7.14.0
|
189
192
|
type: :runtime
|
190
193
|
prerelease: false
|
191
194
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -193,6 +196,9 @@ dependencies:
|
|
193
196
|
- - ">="
|
194
197
|
- !ruby/object:Gem::Version
|
195
198
|
version: 7.12.0
|
199
|
+
- - "<"
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: 7.14.0
|
196
202
|
- !ruby/object:Gem::Dependency
|
197
203
|
name: elasticsearch-dsl
|
198
204
|
requirement: !ruby/object:Gem::Requirement
|
@@ -296,6 +302,7 @@ files:
|
|
296
302
|
- lib/chewy/search/parameters/explain.rb
|
297
303
|
- lib/chewy/search/parameters/filter.rb
|
298
304
|
- lib/chewy/search/parameters/highlight.rb
|
305
|
+
- lib/chewy/search/parameters/ignore_unavailable.rb
|
299
306
|
- lib/chewy/search/parameters/indices.rb
|
300
307
|
- lib/chewy/search/parameters/indices_boost.rb
|
301
308
|
- lib/chewy/search/parameters/limit.rb
|
@@ -320,6 +327,7 @@ files:
|
|
320
327
|
- lib/chewy/search/parameters/terminate_after.rb
|
321
328
|
- lib/chewy/search/parameters/timeout.rb
|
322
329
|
- lib/chewy/search/parameters/track_scores.rb
|
330
|
+
- lib/chewy/search/parameters/track_total_hits.rb
|
323
331
|
- lib/chewy/search/parameters/version.rb
|
324
332
|
- lib/chewy/search/query_proxy.rb
|
325
333
|
- lib/chewy/search/request.rb
|
@@ -381,6 +389,7 @@ files:
|
|
381
389
|
- spec/chewy/search/parameters/filter_spec.rb
|
382
390
|
- spec/chewy/search/parameters/hash_storage_examples.rb
|
383
391
|
- spec/chewy/search/parameters/highlight_spec.rb
|
392
|
+
- spec/chewy/search/parameters/ignore_unavailable_spec.rb
|
384
393
|
- spec/chewy/search/parameters/indices_spec.rb
|
385
394
|
- spec/chewy/search/parameters/integer_storage_examples.rb
|
386
395
|
- spec/chewy/search/parameters/limit_spec.rb
|
@@ -408,6 +417,7 @@ files:
|
|
408
417
|
- spec/chewy/search/parameters/terminate_after_spec.rb
|
409
418
|
- spec/chewy/search/parameters/timeout_spec.rb
|
410
419
|
- spec/chewy/search/parameters/track_scores_spec.rb
|
420
|
+
- spec/chewy/search/parameters/track_total_hits_spec.rb
|
411
421
|
- spec/chewy/search/parameters/version_spec.rb
|
412
422
|
- spec/chewy/search/parameters_spec.rb
|
413
423
|
- spec/chewy/search/query_proxy_spec.rb
|
@@ -491,6 +501,7 @@ test_files:
|
|
491
501
|
- spec/chewy/search/parameters/filter_spec.rb
|
492
502
|
- spec/chewy/search/parameters/hash_storage_examples.rb
|
493
503
|
- spec/chewy/search/parameters/highlight_spec.rb
|
504
|
+
- spec/chewy/search/parameters/ignore_unavailable_spec.rb
|
494
505
|
- spec/chewy/search/parameters/indices_spec.rb
|
495
506
|
- spec/chewy/search/parameters/integer_storage_examples.rb
|
496
507
|
- spec/chewy/search/parameters/limit_spec.rb
|
@@ -518,6 +529,7 @@ test_files:
|
|
518
529
|
- spec/chewy/search/parameters/terminate_after_spec.rb
|
519
530
|
- spec/chewy/search/parameters/timeout_spec.rb
|
520
531
|
- spec/chewy/search/parameters/track_scores_spec.rb
|
532
|
+
- spec/chewy/search/parameters/track_total_hits_spec.rb
|
521
533
|
- spec/chewy/search/parameters/version_spec.rb
|
522
534
|
- spec/chewy/search/parameters_spec.rb
|
523
535
|
- spec/chewy/search/query_proxy_spec.rb
|