chewy 0.8.4 → 7.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/CODEOWNERS +1 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +16 -0
- data/.github/workflows/ruby.yml +74 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +61 -0
- data/.rubocop_todo.yml +132 -0
- data/.yardopts +5 -0
- data/CHANGELOG.md +554 -245
- data/CODE_OF_CONDUCT.md +14 -0
- data/CONTRIBUTING.md +63 -0
- data/Gemfile +14 -11
- data/Guardfile +8 -6
- data/LICENSE.txt +1 -1
- data/README.md +748 -623
- data/Rakefile +11 -1
- data/chewy.gemspec +15 -19
- data/gemfiles/rails.5.2.activerecord.gemfile +11 -0
- data/gemfiles/rails.6.0.activerecord.gemfile +11 -0
- data/gemfiles/rails.6.1.activerecord.gemfile +13 -0
- data/gemfiles/rails.7.0.activerecord.gemfile +13 -0
- data/lib/chewy/config.rb +64 -50
- data/lib/chewy/errors.rb +10 -16
- data/lib/chewy/fields/base.rb +122 -32
- data/lib/chewy/fields/root.rb +48 -23
- data/lib/chewy/index/actions.rb +140 -54
- data/lib/chewy/index/adapter/active_record.rb +112 -0
- data/lib/chewy/{type → index}/adapter/base.rb +31 -12
- data/lib/chewy/index/adapter/object.rb +249 -0
- data/lib/chewy/index/adapter/orm.rb +194 -0
- data/lib/chewy/index/aliases.rb +14 -4
- data/lib/chewy/index/crutch.rb +40 -0
- data/lib/chewy/index/import/bulk_builder.rb +311 -0
- data/lib/chewy/index/import/bulk_request.rb +77 -0
- data/lib/chewy/index/import/journal_builder.rb +44 -0
- data/lib/chewy/index/import/routine.rb +139 -0
- data/lib/chewy/index/import.rb +243 -0
- data/lib/chewy/{type → index}/mapping.rb +79 -68
- data/lib/chewy/index/observe/active_record_methods.rb +87 -0
- data/lib/chewy/index/observe/callback.rb +34 -0
- data/lib/chewy/index/observe.rb +17 -0
- data/lib/chewy/index/settings.rb +10 -5
- data/lib/chewy/index/specification.rb +61 -0
- data/lib/chewy/index/syncer.rb +221 -0
- data/lib/chewy/{type → index}/witchcraft.rb +100 -39
- data/lib/chewy/index/wrapper.rb +95 -0
- data/lib/chewy/index.rb +216 -140
- data/lib/chewy/journal.rb +66 -0
- data/lib/chewy/log_subscriber.rb +8 -8
- data/lib/chewy/minitest/helpers.rb +150 -0
- data/lib/chewy/minitest/search_index_receiver.rb +76 -0
- data/lib/chewy/minitest.rb +1 -0
- data/lib/chewy/multi_search.rb +62 -0
- data/lib/chewy/railtie.rb +12 -25
- data/lib/chewy/rake_helper.rb +335 -37
- data/lib/chewy/repository.rb +2 -2
- data/lib/chewy/rspec/build_query.rb +12 -0
- data/lib/chewy/rspec/helpers.rb +55 -0
- data/lib/chewy/rspec/update_index.rb +106 -90
- data/lib/chewy/rspec.rb +3 -1
- data/lib/chewy/runtime/version.rb +4 -4
- data/lib/chewy/runtime.rb +1 -1
- data/lib/chewy/search/loader.rb +61 -0
- data/lib/chewy/{query → search}/pagination/kaminari.rb +13 -5
- data/lib/chewy/search/parameters/aggs.rb +16 -0
- data/lib/chewy/search/parameters/allow_partial_search_results.rb +27 -0
- data/lib/chewy/search/parameters/collapse.rb +16 -0
- data/lib/chewy/search/parameters/concerns/bool_storage.rb +24 -0
- data/lib/chewy/search/parameters/concerns/hash_storage.rb +23 -0
- data/lib/chewy/search/parameters/concerns/integer_storage.rb +14 -0
- data/lib/chewy/search/parameters/concerns/query_storage.rb +238 -0
- data/lib/chewy/search/parameters/concerns/string_array_storage.rb +23 -0
- data/lib/chewy/search/parameters/concerns/string_storage.rb +14 -0
- data/lib/chewy/search/parameters/docvalue_fields.rb +12 -0
- data/lib/chewy/search/parameters/explain.rb +16 -0
- data/lib/chewy/search/parameters/filter.rb +47 -0
- data/lib/chewy/search/parameters/highlight.rb +16 -0
- data/lib/chewy/search/parameters/ignore_unavailable.rb +27 -0
- data/lib/chewy/search/parameters/indices.rb +78 -0
- data/lib/chewy/search/parameters/indices_boost.rb +52 -0
- data/lib/chewy/search/parameters/limit.rb +17 -0
- data/lib/chewy/search/parameters/load.rb +32 -0
- data/lib/chewy/search/parameters/min_score.rb +16 -0
- data/lib/chewy/search/parameters/none.rb +25 -0
- data/lib/chewy/search/parameters/offset.rb +17 -0
- data/lib/chewy/search/parameters/order.rb +51 -0
- data/lib/chewy/search/parameters/post_filter.rb +19 -0
- data/lib/chewy/search/parameters/preference.rb +16 -0
- data/lib/chewy/search/parameters/profile.rb +16 -0
- data/lib/chewy/search/parameters/query.rb +19 -0
- data/lib/chewy/search/parameters/request_cache.rb +27 -0
- data/lib/chewy/search/parameters/rescore.rb +29 -0
- data/lib/chewy/search/parameters/script_fields.rb +16 -0
- data/lib/chewy/search/parameters/search_after.rb +20 -0
- data/lib/chewy/search/parameters/search_type.rb +16 -0
- data/lib/chewy/search/parameters/source.rb +77 -0
- data/lib/chewy/search/parameters/storage.rb +95 -0
- data/lib/chewy/search/parameters/stored_fields.rb +63 -0
- data/lib/chewy/search/parameters/suggest.rb +16 -0
- data/lib/chewy/search/parameters/terminate_after.rb +16 -0
- data/lib/chewy/search/parameters/timeout.rb +16 -0
- data/lib/chewy/search/parameters/track_scores.rb +16 -0
- data/lib/chewy/search/parameters/track_total_hits.rb +16 -0
- data/lib/chewy/search/parameters/version.rb +16 -0
- data/lib/chewy/search/parameters.rb +170 -0
- data/lib/chewy/search/query_proxy.rb +264 -0
- data/lib/chewy/search/request.rb +1071 -0
- data/lib/chewy/search/response.rb +119 -0
- data/lib/chewy/search/scoping.rb +49 -0
- data/lib/chewy/search/scrolling.rb +137 -0
- data/lib/chewy/search.rb +68 -28
- data/lib/chewy/stash.rb +68 -0
- data/lib/chewy/strategy/active_job.rb +3 -2
- data/lib/chewy/strategy/atomic.rb +2 -4
- data/lib/chewy/strategy/atomic_no_refresh.rb +18 -0
- data/lib/chewy/strategy/base.rb +13 -3
- data/lib/chewy/strategy/bypass.rb +1 -2
- data/lib/chewy/strategy/delayed_sidekiq/scheduler.rb +148 -0
- data/lib/chewy/strategy/delayed_sidekiq/worker.rb +52 -0
- data/lib/chewy/strategy/delayed_sidekiq.rb +17 -0
- data/lib/chewy/strategy/lazy_sidekiq.rb +64 -0
- data/lib/chewy/strategy/sidekiq.rb +15 -2
- data/lib/chewy/strategy/urgent.rb +1 -1
- data/lib/chewy/strategy.rb +16 -20
- data/lib/chewy/version.rb +1 -1
- data/lib/chewy.rb +81 -82
- data/lib/generators/chewy/install_generator.rb +3 -3
- data/lib/tasks/chewy.rake +99 -32
- data/migration_guide.md +56 -0
- data/spec/chewy/config_spec.rb +87 -15
- data/spec/chewy/fields/base_spec.rb +542 -233
- data/spec/chewy/fields/root_spec.rb +115 -17
- data/spec/chewy/fields/time_fields_spec.rb +13 -12
- data/spec/chewy/index/actions_spec.rb +595 -77
- data/spec/chewy/index/adapter/active_record_spec.rb +601 -0
- data/spec/chewy/index/adapter/object_spec.rb +243 -0
- data/spec/chewy/index/aliases_spec.rb +5 -5
- data/spec/chewy/index/import/bulk_builder_spec.rb +494 -0
- data/spec/chewy/index/import/bulk_request_spec.rb +95 -0
- data/spec/chewy/index/import/journal_builder_spec.rb +87 -0
- data/spec/chewy/index/import/routine_spec.rb +110 -0
- data/spec/chewy/index/import_spec.rb +615 -0
- data/spec/chewy/index/mapping_spec.rb +135 -0
- data/spec/chewy/index/observe/active_record_methods_spec.rb +68 -0
- data/spec/chewy/index/observe/callback_spec.rb +139 -0
- data/spec/chewy/index/observe_spec.rb +143 -0
- data/spec/chewy/index/settings_spec.rb +103 -50
- data/spec/chewy/index/specification_spec.rb +159 -0
- data/spec/chewy/index/syncer_spec.rb +118 -0
- data/spec/chewy/index/witchcraft_spec.rb +245 -0
- data/spec/chewy/index/wrapper_spec.rb +100 -0
- data/spec/chewy/index_spec.rb +149 -121
- data/spec/chewy/journal_spec.rb +223 -0
- data/spec/chewy/minitest/helpers_spec.rb +198 -0
- data/spec/chewy/minitest/search_index_receiver_spec.rb +118 -0
- data/spec/chewy/multi_search_spec.rb +84 -0
- data/spec/chewy/rake_helper_spec.rb +656 -0
- data/spec/chewy/repository_spec.rb +8 -8
- data/spec/chewy/rspec/build_query_spec.rb +34 -0
- data/spec/chewy/rspec/helpers_spec.rb +61 -0
- data/spec/chewy/rspec/update_index_spec.rb +220 -114
- data/spec/chewy/runtime_spec.rb +2 -2
- data/spec/chewy/search/loader_spec.rb +83 -0
- data/spec/chewy/search/pagination/kaminari_examples.rb +69 -0
- data/spec/chewy/search/pagination/kaminari_spec.rb +21 -0
- data/spec/chewy/search/parameters/aggs_spec.rb +5 -0
- data/spec/chewy/search/parameters/bool_storage_examples.rb +53 -0
- data/spec/chewy/search/parameters/collapse_spec.rb +5 -0
- data/spec/chewy/search/parameters/docvalue_fields_spec.rb +5 -0
- data/spec/chewy/search/parameters/explain_spec.rb +5 -0
- data/spec/chewy/search/parameters/filter_spec.rb +5 -0
- data/spec/chewy/search/parameters/hash_storage_examples.rb +59 -0
- data/spec/chewy/search/parameters/highlight_spec.rb +5 -0
- data/spec/chewy/search/parameters/ignore_unavailable_spec.rb +67 -0
- data/spec/chewy/search/parameters/indices_spec.rb +99 -0
- data/spec/chewy/search/parameters/integer_storage_examples.rb +32 -0
- data/spec/chewy/search/parameters/limit_spec.rb +5 -0
- data/spec/chewy/search/parameters/load_spec.rb +60 -0
- data/spec/chewy/search/parameters/min_score_spec.rb +32 -0
- data/spec/chewy/search/parameters/none_spec.rb +5 -0
- data/spec/chewy/search/parameters/offset_spec.rb +5 -0
- data/spec/chewy/search/parameters/order_spec.rb +72 -0
- data/spec/chewy/search/parameters/post_filter_spec.rb +5 -0
- data/spec/chewy/search/parameters/preference_spec.rb +5 -0
- data/spec/chewy/search/parameters/profile_spec.rb +5 -0
- data/spec/chewy/search/parameters/query_spec.rb +5 -0
- data/spec/chewy/search/parameters/query_storage_examples.rb +434 -0
- data/spec/chewy/search/parameters/request_cache_spec.rb +67 -0
- data/spec/chewy/search/parameters/rescore_spec.rb +62 -0
- data/spec/chewy/search/parameters/script_fields_spec.rb +5 -0
- data/spec/chewy/search/parameters/search_after_spec.rb +35 -0
- data/spec/chewy/search/parameters/search_type_spec.rb +5 -0
- data/spec/chewy/search/parameters/source_spec.rb +162 -0
- data/spec/chewy/search/parameters/storage_spec.rb +60 -0
- data/spec/chewy/search/parameters/stored_fields_spec.rb +126 -0
- data/spec/chewy/search/parameters/string_array_storage_examples.rb +63 -0
- data/spec/chewy/search/parameters/string_storage_examples.rb +32 -0
- data/spec/chewy/search/parameters/suggest_spec.rb +5 -0
- data/spec/chewy/search/parameters/terminate_after_spec.rb +5 -0
- data/spec/chewy/search/parameters/timeout_spec.rb +5 -0
- data/spec/chewy/search/parameters/track_scores_spec.rb +5 -0
- data/spec/chewy/search/parameters/track_total_hits_spec.rb +5 -0
- data/spec/chewy/search/parameters/version_spec.rb +5 -0
- data/spec/chewy/search/parameters_spec.rb +161 -0
- data/spec/chewy/search/query_proxy_spec.rb +119 -0
- data/spec/chewy/search/request_spec.rb +880 -0
- data/spec/chewy/search/response_spec.rb +202 -0
- data/spec/chewy/search/scrolling_spec.rb +171 -0
- data/spec/chewy/search_spec.rb +82 -55
- data/spec/chewy/stash_spec.rb +85 -0
- data/spec/chewy/strategy/active_job_spec.rb +27 -8
- data/spec/chewy/strategy/atomic_no_refresh_spec.rb +60 -0
- data/spec/chewy/strategy/atomic_spec.rb +13 -11
- data/spec/chewy/strategy/delayed_sidekiq_spec.rb +190 -0
- data/spec/chewy/strategy/lazy_sidekiq_spec.rb +214 -0
- data/spec/chewy/strategy/sidekiq_spec.rb +19 -7
- data/spec/chewy/strategy_spec.rb +19 -15
- data/spec/chewy_spec.rb +65 -88
- data/spec/spec_helper.rb +11 -20
- data/spec/support/active_record.rb +48 -6
- data/spec/support/class_helpers.rb +4 -19
- metadata +299 -183
- data/.travis.yml +0 -76
- data/Appraisals +0 -76
- data/gemfiles/rails.3.2.activerecord.gemfile +0 -15
- data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +0 -14
- data/gemfiles/rails.3.2.activerecord.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.0.activerecord.gemfile +0 -15
- data/gemfiles/rails.4.0.activerecord.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.0.activerecord.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.4.0.0.gemfile +0 -15
- data/gemfiles/rails.4.0.mongoid.4.0.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.4.0.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.5.1.0.gemfile +0 -15
- data/gemfiles/rails.4.0.mongoid.5.1.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.5.1.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
- data/gemfiles/rails.4.1.activerecord.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.activerecord.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.4.0.0.gemfile +0 -15
- data/gemfiles/rails.4.1.mongoid.4.0.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.4.0.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.5.1.0.gemfile +0 -15
- data/gemfiles/rails.4.1.mongoid.5.1.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.5.1.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.2.activerecord.gemfile +0 -16
- data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +0 -15
- data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.4.0.0.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.4.0.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.2.mongoid.4.0.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.2.mongoid.5.1.0.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.5.1.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.2.mongoid.5.1.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.5.0.0.beta3.activerecord.gemfile +0 -16
- data/gemfiles/rails.5.0.0.beta3.activerecord.kaminari.gemfile +0 -16
- data/gemfiles/rails.5.0.0.beta3.activerecord.will_paginate.gemfile +0 -15
- data/gemfiles/sequel.4.31.gemfile +0 -13
- data/lib/chewy/backports/deep_dup.rb +0 -46
- data/lib/chewy/backports/duplicable.rb +0 -90
- data/lib/chewy/query/compose.rb +0 -69
- data/lib/chewy/query/criteria.rb +0 -181
- data/lib/chewy/query/filters.rb +0 -227
- data/lib/chewy/query/loading.rb +0 -111
- data/lib/chewy/query/nodes/and.rb +0 -25
- data/lib/chewy/query/nodes/base.rb +0 -17
- data/lib/chewy/query/nodes/bool.rb +0 -32
- data/lib/chewy/query/nodes/equal.rb +0 -34
- data/lib/chewy/query/nodes/exists.rb +0 -20
- data/lib/chewy/query/nodes/expr.rb +0 -28
- data/lib/chewy/query/nodes/field.rb +0 -106
- data/lib/chewy/query/nodes/has_child.rb +0 -14
- data/lib/chewy/query/nodes/has_parent.rb +0 -14
- data/lib/chewy/query/nodes/has_relation.rb +0 -61
- data/lib/chewy/query/nodes/match_all.rb +0 -11
- data/lib/chewy/query/nodes/missing.rb +0 -20
- data/lib/chewy/query/nodes/not.rb +0 -25
- data/lib/chewy/query/nodes/or.rb +0 -25
- data/lib/chewy/query/nodes/prefix.rb +0 -18
- data/lib/chewy/query/nodes/query.rb +0 -20
- data/lib/chewy/query/nodes/range.rb +0 -63
- data/lib/chewy/query/nodes/raw.rb +0 -15
- data/lib/chewy/query/nodes/regexp.rb +0 -31
- data/lib/chewy/query/nodes/script.rb +0 -20
- data/lib/chewy/query/pagination/will_paginate.rb +0 -27
- data/lib/chewy/query/pagination.rb +0 -16
- data/lib/chewy/query/scoping.rb +0 -20
- data/lib/chewy/query.rb +0 -1026
- data/lib/chewy/strategy/resque.rb +0 -26
- data/lib/chewy/type/actions.rb +0 -19
- data/lib/chewy/type/adapter/active_record.rb +0 -72
- data/lib/chewy/type/adapter/mongoid.rb +0 -58
- data/lib/chewy/type/adapter/object.rb +0 -89
- data/lib/chewy/type/adapter/orm.rb +0 -156
- data/lib/chewy/type/adapter/sequel.rb +0 -75
- data/lib/chewy/type/crutch.rb +0 -31
- data/lib/chewy/type/import.rb +0 -224
- data/lib/chewy/type/observe.rb +0 -76
- data/lib/chewy/type/wrapper.rb +0 -53
- data/lib/chewy/type.rb +0 -89
- data/lib/sequel/plugins/chewy_observe.rb +0 -78
- data/spec/chewy/query/criteria_spec.rb +0 -433
- data/spec/chewy/query/filters_spec.rb +0 -173
- data/spec/chewy/query/loading_spec.rb +0 -86
- data/spec/chewy/query/nodes/and_spec.rb +0 -16
- data/spec/chewy/query/nodes/bool_spec.rb +0 -22
- data/spec/chewy/query/nodes/equal_spec.rb +0 -32
- data/spec/chewy/query/nodes/exists_spec.rb +0 -18
- data/spec/chewy/query/nodes/has_child_spec.rb +0 -40
- data/spec/chewy/query/nodes/has_parent_spec.rb +0 -40
- data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
- data/spec/chewy/query/nodes/missing_spec.rb +0 -15
- data/spec/chewy/query/nodes/not_spec.rb +0 -16
- data/spec/chewy/query/nodes/or_spec.rb +0 -16
- data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
- data/spec/chewy/query/nodes/query_spec.rb +0 -12
- data/spec/chewy/query/nodes/range_spec.rb +0 -32
- data/spec/chewy/query/nodes/raw_spec.rb +0 -11
- data/spec/chewy/query/nodes/regexp_spec.rb +0 -31
- data/spec/chewy/query/nodes/script_spec.rb +0 -15
- data/spec/chewy/query/pagination/kaminari_spec.rb +0 -57
- data/spec/chewy/query/pagination/will_paginage_spec.rb +0 -60
- data/spec/chewy/query/pagination_spec.rb +0 -36
- data/spec/chewy/query_spec.rb +0 -632
- data/spec/chewy/strategy/resque_spec.rb +0 -40
- data/spec/chewy/type/actions_spec.rb +0 -31
- data/spec/chewy/type/adapter/active_record_spec.rb +0 -317
- data/spec/chewy/type/adapter/mongoid_spec.rb +0 -253
- data/spec/chewy/type/adapter/object_spec.rb +0 -139
- data/spec/chewy/type/adapter/sequel_spec.rb +0 -320
- data/spec/chewy/type/import_spec.rb +0 -433
- data/spec/chewy/type/mapping_spec.rb +0 -106
- data/spec/chewy/type/observe_spec.rb +0 -127
- data/spec/chewy/type/witchcraft_spec.rb +0 -154
- data/spec/chewy/type/wrapper_spec.rb +0 -58
- data/spec/chewy/type_spec.rb +0 -33
- data/spec/support/mongoid.rb +0 -81
- data/spec/support/sequel.rb +0 -75
@@ -1,433 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Chewy::Query::Criteria do
|
4
|
-
subject { described_class.new }
|
5
|
-
|
6
|
-
its(:options) { should be_a Hash }
|
7
|
-
its(:request_options) { should be_a Hash }
|
8
|
-
its(:facets) { should == {} }
|
9
|
-
its(:scores) { should == [] }
|
10
|
-
its(:aggregations) { should == {} }
|
11
|
-
its(:script_fields) { should == {} }
|
12
|
-
its(:queries) { should == [] }
|
13
|
-
its(:filters) { should == [] }
|
14
|
-
its(:post_filters) { should == [] }
|
15
|
-
its(:sort) { should == [] }
|
16
|
-
its(:fields) { should == [] }
|
17
|
-
its(:types) { should == [] }
|
18
|
-
|
19
|
-
its(:request_options?) { should eq(false) }
|
20
|
-
its(:facets?) { should eq(false) }
|
21
|
-
its(:scores?) { should eq(false) }
|
22
|
-
its(:aggregations?) { should eq(false) }
|
23
|
-
its(:script_fields?) { should eq(false) }
|
24
|
-
its(:queries?) { should eq(false) }
|
25
|
-
its(:filters?) { should eq(false) }
|
26
|
-
its(:post_filters?) { should eq(false) }
|
27
|
-
its(:sort?) { should eq(false) }
|
28
|
-
its(:fields?) { should eq(false) }
|
29
|
-
its(:types?) { should eq(false) }
|
30
|
-
|
31
|
-
its(:none?){ should eq(false) }
|
32
|
-
|
33
|
-
describe '#update_options' do
|
34
|
-
specify { expect { subject.update_options(field: 'hello') }.to change { subject.options }.to(hash_including(field: 'hello')) }
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '#update_request_options' do
|
38
|
-
specify { expect { subject.update_request_options(field: 'hello') }.to change { subject.request_options }.to(hash_including(field: 'hello')) }
|
39
|
-
end
|
40
|
-
|
41
|
-
describe '#update_facets' do
|
42
|
-
specify { expect { subject.update_facets(field: 'hello') }.to change { subject.facets? }.to(true) }
|
43
|
-
specify { expect { subject.update_facets(field: 'hello') }.to change { subject.facets }.to(field: 'hello') }
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '#update_scores' do
|
47
|
-
specify { expect { subject.update_scores(:score) }.to change { subject.scores? }.to(true) }
|
48
|
-
specify { expect { subject.update_scores(:score) }.to change { subject.scores }.to([:score]) }
|
49
|
-
specify { expect { subject.update_scores([:score, :score2]) }.to change { subject.scores }.to([:score, :score2]) }
|
50
|
-
specify { expect { subject.tap { |s| s.update_scores(:score1) }.update_scores([:score2, :score3]) }
|
51
|
-
.to change { subject.scores }.to([:score1, :score2, :score3]) }
|
52
|
-
end
|
53
|
-
|
54
|
-
describe '#update_aggregations' do
|
55
|
-
specify { expect { subject.update_aggregations(field: 'hello') }.to change { subject.aggregations? }.to(true) }
|
56
|
-
specify { expect { subject.update_aggregations(field: 'hello') }.to change { subject.aggregations }.to(field: 'hello') }
|
57
|
-
end
|
58
|
-
|
59
|
-
describe '#update_script_fields' do
|
60
|
-
specify { expect { subject.update_script_fields(distance: {script: "doc['coordinates'].distanceInMiles(lat, lon)"}) }.to change { subject.script_fields? }.to(true) }
|
61
|
-
specify { expect { subject.update_script_fields(distance_km: {script: "doc['coordinates'].distanceInKm(lat, lon)"}) }.to change { subject.script_fields }.to(distance_km: {script: "doc['coordinates'].distanceInKm(lat, lon)"}) }
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#update_queries' do
|
65
|
-
specify { expect { subject.update_queries(field: 'hello') }.to change { subject.queries? }.to(true) }
|
66
|
-
specify { expect { subject.update_queries(field: 'hello') }.to change { subject.queries }.to([field: 'hello']) }
|
67
|
-
specify { expect { subject.update_queries(field: 'hello'); subject.update_queries(field: 'world') }
|
68
|
-
.to change { subject.queries }.to([{field: 'hello'}, {field: 'world'}]) }
|
69
|
-
specify { expect { subject.update_queries([{field: 'hello'}, {field: 'world'}, nil]) }
|
70
|
-
.to change { subject.queries }.to([{field: 'hello'}, {field: 'world'}]) }
|
71
|
-
end
|
72
|
-
|
73
|
-
describe '#update_filters' do
|
74
|
-
specify { expect { subject.update_filters(field: 'hello') }.to change { subject.filters? }.to(true) }
|
75
|
-
specify { expect { subject.update_filters(field: 'hello') }.to change { subject.filters }.to([{field: 'hello'}]) }
|
76
|
-
specify { expect { subject.update_filters(field: 'hello'); subject.update_filters(field: 'world') }
|
77
|
-
.to change { subject.filters }.to([{field: 'hello'}, {field: 'world'}]) }
|
78
|
-
specify { expect { subject.update_filters([{field: 'hello'}, {field: 'world'}, nil]) }
|
79
|
-
.to change { subject.filters }.to([{field: 'hello'}, {field: 'world'}]) }
|
80
|
-
end
|
81
|
-
|
82
|
-
describe '#update_post_filters' do
|
83
|
-
specify { expect { subject.update_post_filters(field: 'hello') }.to change { subject.post_filters? }.to(true) }
|
84
|
-
specify { expect { subject.update_post_filters(field: 'hello') }.to change { subject.post_filters }.to([{field: 'hello'}]) }
|
85
|
-
specify { expect { subject.update_post_filters(field: 'hello'); subject.update_post_filters(field: 'world') }
|
86
|
-
.to change { subject.post_filters }.to([{field: 'hello'}, {field: 'world'}]) }
|
87
|
-
specify { expect { subject.update_post_filters([{field: 'hello'}, {field: 'world'}, nil]) }
|
88
|
-
.to change { subject.post_filters }.to([{field: 'hello'}, {field: 'world'}]) }
|
89
|
-
end
|
90
|
-
|
91
|
-
describe '#update_sort' do
|
92
|
-
specify { expect { subject.update_sort(:field) }.to change { subject.sort? }.to(true) }
|
93
|
-
|
94
|
-
specify { expect { subject.update_sort([:field]) }.to change { subject.sort }.to([:field]) }
|
95
|
-
specify { expect { subject.update_sort([:field1, :field2]) }.to change { subject.sort }.to([:field1, :field2]) }
|
96
|
-
specify { expect { subject.update_sort([{field: :asc}]) }.to change { subject.sort }.to([{field: :asc}]) }
|
97
|
-
specify { expect { subject.update_sort([:field1, field2: {order: :asc}]) }.to change { subject.sort }.to([:field1, {field2: {order: :asc}}]) }
|
98
|
-
specify { expect { subject.update_sort([{field1: {order: :asc}}, :field2]) }.to change { subject.sort }.to([{field1: {order: :asc}}, :field2]) }
|
99
|
-
specify { expect { subject.update_sort([field1: :asc, field2: {order: :asc}]) }.to change { subject.sort }.to([{field1: :asc}, {field2: {order: :asc}}]) }
|
100
|
-
specify { expect { subject.update_sort([{field1: {order: :asc}}, :field2, :field3]) }.to change { subject.sort }.to([{field1: {order: :asc}}, :field2, :field3]) }
|
101
|
-
specify { expect { subject.update_sort([{field1: {order: :asc}}, [:field2, :field3]]) }.to change { subject.sort }.to([{field1: {order: :asc}}, :field2, :field3]) }
|
102
|
-
specify { expect { subject.update_sort([{field1: {order: :asc}}, [:field2], :field3]) }.to change { subject.sort }.to([{field1: {order: :asc}}, :field2, :field3]) }
|
103
|
-
specify { expect { subject.update_sort([{field1: {order: :asc}, field2: :desc}, [:field3], :field4]) }.to change { subject.sort }.to([{field1: {order: :asc}}, {field2: :desc}, :field3, :field4]) }
|
104
|
-
specify { expect { subject.tap { |s| s.update_sort([field1: {order: :asc}, field2: :desc]) }.update_sort([[:field3], :field4]) }.to change { subject.sort }.to([{field1: {order: :asc}}, {field2: :desc}, :field3, :field4]) }
|
105
|
-
specify { expect { subject.tap { |s| s.update_sort([field1: {order: :asc}, field2: :desc]) }.update_sort([[:field3], :field4], purge: true) }.to change { subject.sort }.to([:field3, :field4]) }
|
106
|
-
end
|
107
|
-
|
108
|
-
describe '#update_fields' do
|
109
|
-
specify { expect { subject.update_fields(:field) }.to change { subject.fields? }.to(true) }
|
110
|
-
specify { expect { subject.update_fields(:field) }.to change { subject.fields }.to(['field']) }
|
111
|
-
specify { expect { subject.update_fields([:field, :field]) }.to change { subject.fields }.to(['field']) }
|
112
|
-
specify { expect { subject.update_fields([:field1, :field2]) }.to change { subject.fields }.to(['field1', 'field2']) }
|
113
|
-
specify { expect { subject.tap { |s| s.update_fields(:field1) }.update_fields([:field2, :field3]) }
|
114
|
-
.to change { subject.fields }.to(['field1', 'field2', 'field3']) }
|
115
|
-
specify { expect { subject.tap { |s| s.update_fields(:field1) }.update_fields([:field2, :field3], purge: true) }
|
116
|
-
.to change { subject.fields }.to(['field2', 'field3']) }
|
117
|
-
end
|
118
|
-
|
119
|
-
describe '#update_types' do
|
120
|
-
specify { expect { subject.update_types(:type) }.to change { subject.types? }.to(true) }
|
121
|
-
specify { expect { subject.update_types(:type) }.to change { subject.types }.to(['type']) }
|
122
|
-
specify { expect { subject.update_types([:type, :type]) }.to change { subject.types }.to(['type']) }
|
123
|
-
specify { expect { subject.update_types([:type1, :type2]) }.to change { subject.types }.to(['type1', 'type2']) }
|
124
|
-
specify { expect { subject.tap { |s| s.update_types(:type1) }.update_types([:type2, :type3]) }
|
125
|
-
.to change { subject.types }.to(['type1', 'type2', 'type3']) }
|
126
|
-
specify { expect { subject.tap { |s| s.update_types(:type1) }.update_types([:type2, :type3], purge: true) }
|
127
|
-
.to change { subject.types }.to(['type2', 'type3']) }
|
128
|
-
end
|
129
|
-
|
130
|
-
describe '#merge' do
|
131
|
-
let(:criteria) { described_class.new }
|
132
|
-
|
133
|
-
specify { expect(subject.merge(criteria)).not_to be_equal subject }
|
134
|
-
specify { expect(subject.merge(criteria)).not_to be_equal criteria }
|
135
|
-
|
136
|
-
specify { expect(subject.tap { |c| c.update_options(opt1: 'hello') }
|
137
|
-
.merge(criteria.tap { |c| c.update_options(opt2: 'hello') }).options).to include(opt1: 'hello', opt2: 'hello') }
|
138
|
-
specify { expect(subject.tap { |c| c.update_request_options(opt1: 'hello') }
|
139
|
-
.merge(criteria.tap { |c| c.update_request_options(opt2: 'hello') }).request_options).to include(opt1: 'hello', opt2: 'hello') }
|
140
|
-
specify { expect(subject.tap { |c| c.update_facets(field1: 'hello') }
|
141
|
-
.merge(criteria.tap { |c| c.update_facets(field1: 'hello') }).facets).to eq({field1: 'hello'}) }
|
142
|
-
specify { expect(subject.tap { |c| c.update_script_fields(distance_m: {script: "doc['coordinates'].distanceInMiles(lat, lon)"}) }
|
143
|
-
.merge(criteria.tap { |c| c.update_script_fields(distance_km: {script: "doc['coordinates'].distanceInKm(lat, lon)"}) }).script_fields).to eq({distance_m: {script: "doc['coordinates'].distanceInMiles(lat, lon)"}, distance_km: {script: "doc['coordinates'].distanceInKm(lat, lon)"}}) }
|
144
|
-
specify { expect(subject.tap { |c| c.update_scores(script: 'hello') }
|
145
|
-
.merge(criteria.tap { |c| c.update_scores(script: 'foobar') }).scores).to eq([{script: 'hello'}, { script: 'foobar' } ]) }
|
146
|
-
specify { expect(subject.tap { |c| c.update_aggregations(field1: 'hello') }
|
147
|
-
.merge(criteria.tap { |c| c.update_aggregations(field1: 'hello') }).aggregations).to eq({field1: 'hello'}) }
|
148
|
-
specify { expect(subject.tap { |c| c.update_queries(field1: 'hello') }
|
149
|
-
.merge(criteria.tap { |c| c.update_queries(field2: 'hello') }).queries).to eq([{field1: 'hello'}, {field2: 'hello'}]) }
|
150
|
-
specify { expect(subject.tap { |c| c.update_filters(field1: 'hello') }
|
151
|
-
.merge(criteria.tap { |c| c.update_filters(field2: 'hello') }).filters).to eq([{field1: 'hello'}, {field2: 'hello'}]) }
|
152
|
-
specify { expect(subject.tap { |c| c.update_post_filters(field1: 'hello') }
|
153
|
-
.merge(criteria.tap { |c| c.update_post_filters(field2: 'hello') }).post_filters).to eq([{field1: 'hello'}, {field2: 'hello'}]) }
|
154
|
-
specify { expect(subject.tap { |c| c.update_sort(:field1) }
|
155
|
-
.merge(criteria.tap { |c| c.update_sort(:field2) }).sort).to eq([:field1, :field2]) }
|
156
|
-
specify { expect(subject.tap { |c| c.update_fields(:field1) }
|
157
|
-
.merge(criteria.tap { |c| c.update_fields(:field2) }).fields).to eq(['field1', 'field2']) }
|
158
|
-
specify { expect(subject.tap { |c| c.update_types(:type1) }
|
159
|
-
.merge(criteria.tap { |c| c.update_types(:type2) }).types).to eq(['type1', 'type2']) }
|
160
|
-
end
|
161
|
-
|
162
|
-
describe '#merge!' do
|
163
|
-
let(:criteria) { described_class.new }
|
164
|
-
|
165
|
-
specify { expect(subject.merge!(criteria)).to be_equal subject }
|
166
|
-
specify { expect(subject.merge!(criteria)).not_to be_equal criteria }
|
167
|
-
|
168
|
-
specify { expect(subject.tap { |c| c.update_options(opt1: 'hello') }
|
169
|
-
.merge!(criteria.tap { |c| c.update_options(opt2: 'hello') }).options).to include(opt1: 'hello', opt2: 'hello') }
|
170
|
-
specify { expect(subject.tap { |c| c.update_request_options(opt1: 'hello') }
|
171
|
-
.merge!(criteria.tap { |c| c.update_request_options(opt2: 'hello') }).request_options).to include(opt1: 'hello', opt2: 'hello') }
|
172
|
-
specify { expect(subject.tap { |c| c.update_facets(field1: 'hello') }
|
173
|
-
.merge!(criteria.tap { |c| c.update_facets(field1: 'hello') }).facets).to eq({field1: 'hello'}) }
|
174
|
-
specify { expect(subject.tap { |c| c.update_script_fields(distance_m: {script: "doc['coordinates'].distanceInMiles(lat, lon)"}) }
|
175
|
-
.merge(criteria.tap { |c| c.update_script_fields(distance_km: {script: "doc['coordinates'].distanceInKm(lat, lon)"}) }).script_fields).to eq({distance_m: {script: "doc['coordinates'].distanceInMiles(lat, lon)"}, distance_km: {script: "doc['coordinates'].distanceInKm(lat, lon)"}}) }
|
176
|
-
specify { expect(subject.tap { |c| c.update_aggregations(field1: 'hello') }
|
177
|
-
.merge!(criteria.tap { |c| c.update_aggregations(field1: 'hello') }).aggregations).to eq({field1: 'hello'}) }
|
178
|
-
specify { expect(subject.tap { |c| c.update_queries(field1: 'hello') }
|
179
|
-
.merge!(criteria.tap { |c| c.update_queries(field2: 'hello') }).queries).to eq([{field1: 'hello'}, {field2: 'hello'}]) }
|
180
|
-
specify { expect(subject.tap { |c| c.update_filters(field1: 'hello') }
|
181
|
-
.merge!(criteria.tap { |c| c.update_filters(field2: 'hello') }).filters).to eq([{field1: 'hello'}, {field2: 'hello'}]) }
|
182
|
-
specify { expect(subject.tap { |c| c.update_post_filters(field1: 'hello') }
|
183
|
-
.merge!(criteria.tap { |c| c.update_post_filters(field2: 'hello') }).post_filters).to eq([{field1: 'hello'}, {field2: 'hello'}]) }
|
184
|
-
specify { expect(subject.tap { |c| c.update_sort(:field1) }
|
185
|
-
.merge!(criteria.tap { |c| c.update_sort(:field2) }).sort).to eq([:field1, :field2]) }
|
186
|
-
specify { expect(subject.tap { |c| c.update_fields(:field1) }
|
187
|
-
.merge!(criteria.tap { |c| c.update_fields(:field2) }).fields).to eq(['field1', 'field2']) }
|
188
|
-
specify { expect(subject.tap { |c| c.update_types(:type1) }
|
189
|
-
.merge!(criteria.tap { |c| c.update_types(:type2) }).types).to eq(['type1', 'type2']) }
|
190
|
-
end
|
191
|
-
|
192
|
-
describe '#request_body' do
|
193
|
-
def request_body &block
|
194
|
-
subject.instance_exec(&block) if block
|
195
|
-
subject.request_body
|
196
|
-
end
|
197
|
-
|
198
|
-
specify { expect(request_body).to eq({body: {}}) }
|
199
|
-
specify { expect(request_body { update_request_options(size: 10) }).to eq({body: {size: 10}}) }
|
200
|
-
specify { expect(request_body { update_request_options(from: 10) }).to eq({body: {from: 10}}) }
|
201
|
-
specify { expect(request_body { update_request_options(explain: true) }).to eq({body: {explain: true}}) }
|
202
|
-
specify { expect(request_body { update_queries(:query) }).to eq({body: {query: :query}}) }
|
203
|
-
specify { expect(request_body {
|
204
|
-
update_scores(script_score: { script: '_score'})
|
205
|
-
}).to eq({body: {query: { function_score: { functions: [{ script_score: {script: '_score' }}] }}}}) }
|
206
|
-
specify { expect(request_body {
|
207
|
-
update_scores(script_score: { script: "boost_me" })
|
208
|
-
update_queries(:query)
|
209
|
-
update_options(boost_mode: :add)
|
210
|
-
update_options(score_mode: :avg)
|
211
|
-
}).to eq({body: {query: {
|
212
|
-
function_score: {
|
213
|
-
functions: [{
|
214
|
-
script_score: {script: 'boost_me' }
|
215
|
-
}],
|
216
|
-
query: :query,
|
217
|
-
boost_mode: :add,
|
218
|
-
score_mode: :avg
|
219
|
-
}}}})
|
220
|
-
}
|
221
|
-
specify { expect(request_body {
|
222
|
-
update_request_options(from: 10); update_sort(:field); update_fields(:field); update_queries(:query)
|
223
|
-
}).to eq({body: {query: :query, from: 10, sort: [:field], _source: ['field']}}) }
|
224
|
-
|
225
|
-
specify { expect(request_body {
|
226
|
-
update_queries(:query); update_filters(:filters);
|
227
|
-
}).to eq({body: {query: {filtered: {query: :query, filter: :filters}}}}) }
|
228
|
-
specify { expect(request_body {
|
229
|
-
update_queries(:query); update_post_filters(:post_filter);
|
230
|
-
}).to eq({body: {query: :query, post_filter: :post_filter}}) }
|
231
|
-
specify { expect(request_body {
|
232
|
-
update_script_fields(distance_m: {script: "doc['coordinates'].distanceInMiles(lat, lon)"})
|
233
|
-
}).to eq({:body=>{:script_fields=>{:distance_m=>{:script=>"doc['coordinates'].distanceInMiles(lat, lon)"}}}}) }
|
234
|
-
end
|
235
|
-
|
236
|
-
describe '#_filtered_query' do
|
237
|
-
def _filtered_query options = {}, &block
|
238
|
-
subject.instance_exec(&block) if block
|
239
|
-
subject.send(:_filtered_query, subject.send(:_request_query), subject.send(:_request_filter), options)
|
240
|
-
end
|
241
|
-
|
242
|
-
specify { expect(_filtered_query).to eq({}) }
|
243
|
-
specify { expect(_filtered_query { update_queries(:query) }).to eq({query: :query}) }
|
244
|
-
specify { expect(_filtered_query(strategy: 'query_first') { update_queries(:query) }).to eq({query: :query}) }
|
245
|
-
specify { expect(_filtered_query { update_queries([:query1, :query2]) })
|
246
|
-
.to eq({query: {bool: {must: [:query1, :query2]}}}) }
|
247
|
-
specify { expect(_filtered_query { update_options(query_mode: :should); update_queries([:query1, :query2]) })
|
248
|
-
.to eq({query: {bool: {should: [:query1, :query2]}}}) }
|
249
|
-
specify { expect(_filtered_query { update_options(query_mode: :dis_max); update_queries([:query1, :query2]) })
|
250
|
-
.to eq({query: {dis_max: {queries: [:query1, :query2]}}}) }
|
251
|
-
|
252
|
-
specify { expect(_filtered_query(strategy: 'query_first') { update_filters([:filter1, :filter2]) })
|
253
|
-
.to eq({query: {filtered: {query: {match_all: {}}, filter: {and: [:filter1, :filter2]}, strategy: 'query_first'}}}) }
|
254
|
-
specify { expect(_filtered_query { update_filters([:filter1, :filter2]) })
|
255
|
-
.to eq({query: {filtered: {query: {match_all: {}}, filter: {and: [:filter1, :filter2]}}}}) }
|
256
|
-
|
257
|
-
specify { expect(_filtered_query { update_filters([:filter1, :filter2]); update_queries([:query1, :query2]) })
|
258
|
-
.to eq({query: {filtered: {
|
259
|
-
query: {bool: {must: [:query1, :query2]}},
|
260
|
-
filter: {and: [:filter1, :filter2]}
|
261
|
-
}}})
|
262
|
-
}
|
263
|
-
specify { expect(_filtered_query(strategy: 'query_first') { update_filters([:filter1, :filter2]); update_queries([:query1, :query2]) })
|
264
|
-
.to eq({query: {filtered: {
|
265
|
-
query: {bool: {must: [:query1, :query2]}},
|
266
|
-
filter: {and: [:filter1, :filter2]},
|
267
|
-
strategy: 'query_first'
|
268
|
-
}}})
|
269
|
-
}
|
270
|
-
specify { expect(_filtered_query {
|
271
|
-
update_options(query_mode: :should); update_options(filter_mode: :or);
|
272
|
-
update_filters([:filter1, :filter2]); update_queries([:query1, :query2])
|
273
|
-
}).to eq({query: {filtered: {
|
274
|
-
query: {bool: {should: [:query1, :query2]}},
|
275
|
-
filter: {or: [:filter1, :filter2]}
|
276
|
-
}}})
|
277
|
-
}
|
278
|
-
end
|
279
|
-
|
280
|
-
describe "#_boost_query" do
|
281
|
-
specify { expect(subject.send(:_boost_query, query: :query)).to eq(query: :query) }
|
282
|
-
specify {
|
283
|
-
subject.update_scores({ boost_factor: 5 })
|
284
|
-
expect(subject.send(:_boost_query, query: :query)).to eq(query: { function_score: { functions: [{ boost_factor: 5 }], query: :query } })
|
285
|
-
}
|
286
|
-
specify {
|
287
|
-
subject.update_scores({ boost_factor: 5 })
|
288
|
-
subject.update_options(boost_mode: :multiply)
|
289
|
-
subject.update_options(score_mode: :add)
|
290
|
-
expect(subject.send(:_boost_query, query: :query)).to eq(query: { function_score: { functions: [{ boost_factor: 5 }], query: :query, boost_mode: :multiply, score_mode: :add } })
|
291
|
-
}
|
292
|
-
specify {
|
293
|
-
subject.update_scores({ boost_factor: 5 })
|
294
|
-
expect(subject.send(:_boost_query, query: :query, filter: :filter)).to eq(query: { function_score: { functions: [{ boost_factor: 5 }], query: { filtered: { query: :query, filter: :filter } } } })
|
295
|
-
}
|
296
|
-
end
|
297
|
-
|
298
|
-
describe '#_request_filter' do
|
299
|
-
def _request_filter &block
|
300
|
-
subject.instance_exec(&block) if block
|
301
|
-
subject.send(:_request_filter)
|
302
|
-
end
|
303
|
-
|
304
|
-
specify { expect(_request_filter).to be_nil }
|
305
|
-
|
306
|
-
specify { expect(_request_filter { update_types(:type) }).to eq({type: {value: 'type'}}) }
|
307
|
-
specify { expect(_request_filter { update_types([:type1, :type2]) })
|
308
|
-
.to eq({or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}) }
|
309
|
-
|
310
|
-
specify { expect(_request_filter { update_filters([:filter1, :filter2]) })
|
311
|
-
.to eq({and: [:filter1, :filter2]}) }
|
312
|
-
specify { expect(_request_filter { update_options(filter_mode: :or); update_filters([:filter1, :filter2]) })
|
313
|
-
.to eq({or: [:filter1, :filter2]}) }
|
314
|
-
specify { expect(_request_filter { update_options(filter_mode: :must); update_filters([:filter1, :filter2]) })
|
315
|
-
.to eq({bool: {must: [:filter1, :filter2]}}) }
|
316
|
-
specify { expect(_request_filter { update_options(filter_mode: :should); update_filters([:filter1, :filter2]) })
|
317
|
-
.to eq({bool: {should: [:filter1, :filter2]}}) }
|
318
|
-
specify { expect(_request_filter { update_options(filter_mode: :must_not); update_filters([:filter1, :filter2]) })
|
319
|
-
.to eq({bool: {must_not: [:filter1, :filter2]}}) }
|
320
|
-
|
321
|
-
specify { expect(_request_filter { update_types([:type1, :type2]); update_filters([:filter1, :filter2]) })
|
322
|
-
.to eq({and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, :filter1, :filter2]}) }
|
323
|
-
specify { expect(_request_filter { update_options(filter_mode: :or); update_types([:type1, :type2]); update_filters([:filter1, :filter2]) })
|
324
|
-
.to eq({and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, {or: [:filter1, :filter2]}]}) }
|
325
|
-
specify { expect(_request_filter { update_options(filter_mode: :must); update_types([:type1, :type2]); update_filters([:filter1, :filter2]) })
|
326
|
-
.to eq({and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, {bool: {must: [:filter1, :filter2]}}]}) }
|
327
|
-
specify { expect(_request_filter { update_options(filter_mode: :should); update_types([:type1, :type2]); update_filters([:filter1, :filter2]) })
|
328
|
-
.to eq({and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, {bool: {should: [:filter1, :filter2]}}]}) }
|
329
|
-
specify { expect(_request_filter { update_options(filter_mode: :must_not); update_types([:type1, :type2]); update_filters([:filter1, :filter2]) })
|
330
|
-
.to eq({and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, {bool: {must_not: [:filter1, :filter2]}}]}) }
|
331
|
-
end
|
332
|
-
|
333
|
-
describe '#_request_post_filter' do
|
334
|
-
def _request_post_filter &block
|
335
|
-
subject.instance_exec(&block) if block
|
336
|
-
subject.send(:_request_post_filter)
|
337
|
-
end
|
338
|
-
|
339
|
-
specify { expect(_request_post_filter).to be_nil }
|
340
|
-
|
341
|
-
specify { expect(_request_post_filter { update_post_filters([:post_filter1, :post_filter2]) })
|
342
|
-
.to eq({and: [:post_filter1, :post_filter2]}) }
|
343
|
-
specify { expect(_request_post_filter { update_options(post_filter_mode: :or); update_post_filters([:post_filter1, :post_filter2]) })
|
344
|
-
.to eq({or: [:post_filter1, :post_filter2]}) }
|
345
|
-
specify { expect(_request_post_filter { update_options(post_filter_mode: :must); update_post_filters([:post_filter1, :post_filter2]) })
|
346
|
-
.to eq({bool: {must: [:post_filter1, :post_filter2]}}) }
|
347
|
-
specify { expect(_request_post_filter { update_options(post_filter_mode: :should); update_post_filters([:post_filter1, :post_filter2]) })
|
348
|
-
.to eq({bool: {should: [:post_filter1, :post_filter2]}}) }
|
349
|
-
|
350
|
-
context do
|
351
|
-
before { allow(Chewy).to receive_messages(filter_mode: :or) }
|
352
|
-
|
353
|
-
specify { expect(_request_post_filter { update_post_filters([:post_filter1, :post_filter2]) })
|
354
|
-
.to eq({or: [:post_filter1, :post_filter2]}) }
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
describe '#_request_types' do
|
359
|
-
def _request_types &block
|
360
|
-
subject.instance_exec(&block) if block
|
361
|
-
subject.send(:_request_types)
|
362
|
-
end
|
363
|
-
|
364
|
-
specify { expect(_request_types).to be_nil }
|
365
|
-
specify { expect(_request_types { update_types(:type1) }).to eq({type: {value: 'type1'}}) }
|
366
|
-
specify { expect(_request_types { update_types([:type1, :type2]) })
|
367
|
-
.to eq({or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}) }
|
368
|
-
end
|
369
|
-
|
370
|
-
describe '#_queries_join' do
|
371
|
-
def _queries_join *args
|
372
|
-
subject.send(:_queries_join, *args)
|
373
|
-
end
|
374
|
-
|
375
|
-
let(:query) { {term: {field: 'value'}} }
|
376
|
-
|
377
|
-
specify { expect(_queries_join([], :dis_max)).to be_nil }
|
378
|
-
specify { expect(_queries_join([query], :dis_max)).to eq(query) }
|
379
|
-
specify { expect(_queries_join([query, query], :dis_max)).to eq({dis_max: {queries: [query, query]}}) }
|
380
|
-
|
381
|
-
specify { expect(_queries_join([], 0.7)).to be_nil }
|
382
|
-
specify { expect(_queries_join([query], 0.7)).to eq(query) }
|
383
|
-
specify { expect(_queries_join([query, query], 0.7)).to eq({dis_max: {queries: [query, query], tie_breaker: 0.7}}) }
|
384
|
-
|
385
|
-
specify { expect(_queries_join([], :must)).to be_nil }
|
386
|
-
specify { expect(_queries_join([query], :must)).to eq(query) }
|
387
|
-
specify { expect(_queries_join([query, query], :must)).to eq({bool: {must: [query, query]}}) }
|
388
|
-
|
389
|
-
specify { expect(_queries_join([], :should)).to be_nil }
|
390
|
-
specify { expect(_queries_join([query], :should)).to eq(query) }
|
391
|
-
specify { expect(_queries_join([query, query], :should)).to eq({bool: {should: [query, query]}}) }
|
392
|
-
|
393
|
-
specify { expect(_queries_join([], :must_not)).to be_nil }
|
394
|
-
specify { expect(_queries_join([query], :must_not)).to eq({bool: {must_not: [query]}}) }
|
395
|
-
specify { expect(_queries_join([query, query], :must_not)).to eq({bool: {must_not: [query, query]}}) }
|
396
|
-
|
397
|
-
specify { expect(_queries_join([], '25%')).to be_nil }
|
398
|
-
specify { expect(_queries_join([query], '25%')).to eq(query) }
|
399
|
-
specify { expect(_queries_join([query, query], '25%')).to eq({bool: {should: [query, query], minimum_should_match: '25%'}}) }
|
400
|
-
end
|
401
|
-
|
402
|
-
describe '#_filters_join' do
|
403
|
-
def _filters_join *args
|
404
|
-
subject.send(:_filters_join, *args)
|
405
|
-
end
|
406
|
-
|
407
|
-
let(:filter) { {term: {field: 'value'}} }
|
408
|
-
|
409
|
-
specify { expect(_filters_join([], :and)).to be_nil }
|
410
|
-
specify { expect(_filters_join([filter], :and)).to eq(filter) }
|
411
|
-
specify { expect(_filters_join([filter, filter], :and)).to eq({and: [filter, filter]}) }
|
412
|
-
|
413
|
-
specify { expect(_filters_join([], :or)).to be_nil }
|
414
|
-
specify { expect(_filters_join([filter], :or)).to eq(filter) }
|
415
|
-
specify { expect(_filters_join([filter, filter], :or)).to eq({or: [filter, filter]}) }
|
416
|
-
|
417
|
-
specify { expect(_filters_join([], :must)).to be_nil }
|
418
|
-
specify { expect(_filters_join([filter], :must)).to eq(filter) }
|
419
|
-
specify { expect(_filters_join([filter, filter], :must)).to eq({bool: {must: [filter, filter]}}) }
|
420
|
-
|
421
|
-
specify { expect(_filters_join([], :should)).to be_nil }
|
422
|
-
specify { expect(_filters_join([filter], :should)).to eq(filter) }
|
423
|
-
specify { expect(_filters_join([filter, filter], :should)).to eq({bool: {should: [filter, filter]}}) }
|
424
|
-
|
425
|
-
specify { expect(_filters_join([], :must_not)).to be_nil }
|
426
|
-
specify { expect(_filters_join([filter], :must_not)).to eq({bool: {must_not: [filter]}}) }
|
427
|
-
specify { expect(_filters_join([filter, filter], :must_not)).to eq({bool: {must_not: [filter, filter]}}) }
|
428
|
-
|
429
|
-
specify { expect(_filters_join([], '25%')).to be_nil }
|
430
|
-
specify { expect(_filters_join([filter], '25%')).to eq(filter) }
|
431
|
-
specify { expect(_filters_join([filter, filter], '25%')).to eq({bool: {should: [filter, filter], minimum_should_match: '25%'}}) }
|
432
|
-
end
|
433
|
-
end
|
@@ -1,173 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Chewy::Query::Filters do
|
4
|
-
def Bool options
|
5
|
-
Chewy::Query::Nodes::Bool.new.tap do |bool|
|
6
|
-
bool.must(*options[:must]) if options[:must].present?
|
7
|
-
bool.must_not(*options[:must_not]) if options[:must_not].present?
|
8
|
-
bool.should(*options[:should]) if options[:should].present?
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
%w(field group and or not raw exists missing prefix regexp range equal query script).each do |method|
|
13
|
-
define_method method.camelize do |*args|
|
14
|
-
"Chewy::Query::Nodes::#{method.camelize}".constantize.new *args
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def query &block
|
19
|
-
Chewy::Query::Filters.new(&block).__result__
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'outer scope' do
|
23
|
-
let(:email) { 'email' }
|
24
|
-
specify { expect(query { email }).to be_eql Field(:email) }
|
25
|
-
specify { expect(query { o{email} }).to eq('email') }
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'field' do
|
29
|
-
let(:email) { 'email' }
|
30
|
-
specify { expect(query { f(:email) }).to be_eql Field(:email) }
|
31
|
-
specify { expect(query { f{ :email } }).to be_eql Field(:email) }
|
32
|
-
specify { expect(query { f{ email } }).to be_eql Field(:email) }
|
33
|
-
specify { expect(query { email }).to be_eql Field(:email) }
|
34
|
-
specify { expect(query { emails.first }).to be_eql Field('emails.first') }
|
35
|
-
specify { expect(query { emails.first.second }).to be_eql Field('emails.first.second') }
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'term' do
|
39
|
-
specify { expect(query { email == 'email' }).to be_eql Equal(:email, 'email') }
|
40
|
-
specify { expect(query { name != 'name' }).to be_eql Not(Equal(:name, 'name')) }
|
41
|
-
specify { expect(query { email == ['email1', 'email2'] }).to be_eql Equal(:email, ['email1', 'email2']) }
|
42
|
-
specify { expect(query { email != ['email1', 'email2'] }).to be_eql Not(Equal(:email, ['email1', 'email2'])) }
|
43
|
-
specify { expect(query { email(execution: :bool) == ['email1', 'email2'] })
|
44
|
-
.to be_eql Equal(:email, ['email1', 'email2'], execution: :bool) }
|
45
|
-
specify { expect(query { email(:bool) == ['email1', 'email2'] })
|
46
|
-
.to be_eql Equal(:email, ['email1', 'email2'], execution: :bool) }
|
47
|
-
specify { expect(query { email(:b) == ['email1', 'email2'] })
|
48
|
-
.to be_eql Equal(:email, ['email1', 'email2'], execution: :bool) }
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'bool' do
|
52
|
-
specify { query { must(email == 'email') }.should be_eql Bool(must: [Equal(:email, 'email')]) }
|
53
|
-
specify { query { must_not(email == 'email') }.should be_eql Bool(must_not: [Equal(:email, 'email')]) }
|
54
|
-
specify { query { should(email == 'email') }.should be_eql Bool(should: [Equal(:email, 'email')]) }
|
55
|
-
specify { query {
|
56
|
-
must(email == 'email').should(address != 'address', age == 42)
|
57
|
-
.must_not(sex == 'm').must(name == 'name')
|
58
|
-
}.should be_eql Bool(
|
59
|
-
must: [Equal(:email, 'email'), Equal(:name, 'name')],
|
60
|
-
must_not: [Equal(:sex, 'm')],
|
61
|
-
should: [Not(Equal(:address, 'address')), Equal(:age, 42)]
|
62
|
-
) }
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'exists' do
|
66
|
-
specify { expect(query { email? }).to be_eql Exists(:email) }
|
67
|
-
specify { expect(query { !!email? }).to be_eql Exists(:email) }
|
68
|
-
specify { expect(query { emails.first? }).to be_eql Exists('emails.first') }
|
69
|
-
specify { expect(query { !!emails.first? }).to be_eql Exists('emails.first') }
|
70
|
-
specify { expect(query { emails != nil }).to be_eql Exists('emails') }
|
71
|
-
specify { expect(query { !(emails == nil) }).to be_eql Exists('emails') }
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'missing' do
|
75
|
-
specify { expect(query { !email }).to be_eql Missing(:email) }
|
76
|
-
specify { expect(query { !email? }).to be_eql Missing(:email, null_value: true) }
|
77
|
-
specify { expect(query { !emails.first }).to be_eql Missing('emails.first') }
|
78
|
-
specify { expect(query { !emails.first? }).to be_eql Missing('emails.first', null_value: true) }
|
79
|
-
specify { expect(query { emails == nil }).to be_eql Missing('emails', existence: false, null_value: true) }
|
80
|
-
specify { expect(query { emails.first == nil }).to be_eql Missing('emails.first', existence: false, null_value: true) }
|
81
|
-
end
|
82
|
-
|
83
|
-
context 'range' do
|
84
|
-
specify { expect(query { age > 42 }).to be_eql Range(:age, gt: 42) }
|
85
|
-
specify { expect(query { age >= 42 }).to be_eql Range(:age, gt: 42, left_closed: true) }
|
86
|
-
specify { expect(query { age < 42 }).to be_eql Range(:age, lt: 42) }
|
87
|
-
specify { expect(query { age <= 42 }).to be_eql Range(:age, lt: 42, right_closed: true) }
|
88
|
-
|
89
|
-
specify { expect(query { age == (30..42) }).to be_eql Range(:age, gt: 30, lt: 42) }
|
90
|
-
specify { expect(query { age == [30..42] }).to be_eql Range(:age, gt: 30, lt: 42, left_closed: true, right_closed: true) }
|
91
|
-
specify { expect(query { (age > 30) & (age < 42) }).to be_eql Range(:age, gt: 30, lt: 42) }
|
92
|
-
specify { expect(query { (age > 30) & (age <= 42) }).to be_eql Range(:age, gt: 30, lt: 42, right_closed: true) }
|
93
|
-
specify { expect(query { (age >= 30) & (age < 42) }).to be_eql Range(:age, gt: 30, lt: 42, left_closed: true) }
|
94
|
-
specify { expect(query { (age >= 30) & (age <= 42) }).to be_eql Range(:age, gt: 30, lt: 42, right_closed: true, left_closed: true) }
|
95
|
-
specify { expect(query { (age > 30) | (age < 42) }).to be_eql Or(Range(:age, gt: 30), Range(:age, lt: 42)) }
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'prefix' do
|
99
|
-
specify { expect(query { name =~ 'nam' }).to be_eql Prefix(:name, 'nam') }
|
100
|
-
specify { expect(query { name !~ 'nam' }).to be_eql Not(Prefix(:name, 'nam')) }
|
101
|
-
end
|
102
|
-
|
103
|
-
context 'regexp' do
|
104
|
-
specify { expect(query { name =~ /name/ }).to be_eql Regexp(:name, 'name') }
|
105
|
-
specify { expect(query { name == /name/ }).to be_eql Regexp(:name, 'name') }
|
106
|
-
specify { expect(query { name !~ /name/ }).to be_eql Not(Regexp(:name, 'name')) }
|
107
|
-
specify { expect(query { name != /name/ }).to be_eql Not(Regexp(:name, 'name')) }
|
108
|
-
specify { expect(query { name(:anystring, :intersection) =~ /name/ }).to be_eql Regexp(:name, 'name', flags: %w(anystring intersection)) }
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'query' do
|
112
|
-
let(:some_query) { 'some query' }
|
113
|
-
specify { expect(query { q('some query') }).to be_eql Query('some query') }
|
114
|
-
specify { expect(query { q{'some query'} }).to be_eql Query('some query') }
|
115
|
-
specify { expect(query { q{ some_query } }).to be_eql Query('some query') }
|
116
|
-
end
|
117
|
-
|
118
|
-
context 'raw' do
|
119
|
-
let(:raw_query) { {term: {name: 'name'}} }
|
120
|
-
specify { expect(query { r(term: {name: 'name'}) }).to be_eql Raw(term: {name: 'name'}) }
|
121
|
-
specify { expect(query { r{ {term: {name: 'name'}} } }).to be_eql Raw(term: {name: 'name'}) }
|
122
|
-
specify { expect(query { r{ raw_query } }).to be_eql Raw(term: {name: 'name'}) }
|
123
|
-
end
|
124
|
-
|
125
|
-
context 'script' do
|
126
|
-
let(:some_script) { 'some script' }
|
127
|
-
specify { expect(query { s('some script') }).to be_eql Script('some script') }
|
128
|
-
specify { expect(query { s('some script', param1: 42) }).to be_eql Script('some script', param1: 42) }
|
129
|
-
specify { expect(query { s{'some script'} }).to be_eql Script('some script') }
|
130
|
-
specify { expect(query { s(param1: 42) { some_script } }).to be_eql Script('some script', param1: 42) }
|
131
|
-
end
|
132
|
-
|
133
|
-
context 'and or not' do
|
134
|
-
specify { expect(query { (email == 'email') & (name == 'name') })
|
135
|
-
.to be_eql And(Equal(:email, 'email'), Equal(:name, 'name')) }
|
136
|
-
specify { expect(query { (email == 'email') | (name == 'name') })
|
137
|
-
.to be_eql Or(Equal(:email, 'email'), Equal(:name, 'name')) }
|
138
|
-
specify { expect(query { !(email == 'email') }).to be_eql Not(Equal(:email, 'email')) }
|
139
|
-
|
140
|
-
specify { expect(query { (email == 'email') & (name == 'name') | (address != 'address') })
|
141
|
-
.to be_eql Or(
|
142
|
-
And(
|
143
|
-
Equal(:email, 'email'),
|
144
|
-
Equal(:name, 'name')
|
145
|
-
),
|
146
|
-
Not(Equal(:address, 'address'))
|
147
|
-
) }
|
148
|
-
specify { expect(query { (email == 'email') & ((name == 'name') | (address != 'address')) })
|
149
|
-
.to be_eql And(
|
150
|
-
Equal(:email, 'email'),
|
151
|
-
Or(
|
152
|
-
Equal(:name, 'name'),
|
153
|
-
Not(Equal(:address, 'address')),
|
154
|
-
)
|
155
|
-
) }
|
156
|
-
specify { expect(query { (email == 'email') & ((name == 'name') & (address != 'address')) })
|
157
|
-
.to be_eql And(
|
158
|
-
Equal(:email, 'email'),
|
159
|
-
Equal(:name, 'name'),
|
160
|
-
Not(Equal(:address, 'address')),
|
161
|
-
) }
|
162
|
-
specify { expect(query { ((email == 'email') | (name == 'name')) | (address != 'address') })
|
163
|
-
.to be_eql Or(
|
164
|
-
Equal(:email, 'email'),
|
165
|
-
Equal(:name, 'name'),
|
166
|
-
Not(Equal(:address, 'address')),
|
167
|
-
) }
|
168
|
-
specify { expect(query { !((email == 'email') | (name == 'name')) })
|
169
|
-
.to be_eql Not(Or(Equal(:email, 'email'), Equal(:name, 'name'))) }
|
170
|
-
specify { expect(query { !!((email == 'email') | (name == 'name')) })
|
171
|
-
.to be_eql Or(Equal(:email, 'email'), Equal(:name, 'name')) }
|
172
|
-
end
|
173
|
-
end
|