Class: Chewy::Query::Criteria
- Includes:
- Compose
- Defined in:
- lib/chewy/query/criteria.rb
Constant Summary collapse
- ARRAY_STORAGES =
%i[queries filters post_filters sort fields types scores].freeze
- HASH_STORAGES =
%i[options search_options request_options facets aggregations suggest script_fields].freeze
- STORAGES =
ARRAY_STORAGES + HASH_STORAGES
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(options = {}) ⇒ Criteria
constructor
A new instance of Criteria.
- #merge(other) ⇒ Object
- #merge!(other) ⇒ Object
- #none? ⇒ Boolean
- #request_body ⇒ Object
- #update_aggregations(modifier) ⇒ Object
- #update_facets(modifier) ⇒ Object
- #update_options(modifier) ⇒ Object
- #update_request_options(modifier) ⇒ Object
- #update_scores(modifier) ⇒ Object
- #update_script_fields(modifier) ⇒ Object
- #update_search_options(modifier) ⇒ Object
- #update_sort(modifier, options = {}) ⇒ Object
- #update_suggest(modifier) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Criteria
Returns a new instance of Criteria.
11 12 13 14 15 16 17 |
# File 'lib/chewy/query/criteria.rb', line 11 def initialize( = {}) @options = .merge( query_mode: Chewy.query_mode, filter_mode: Chewy.filter_mode, post_filter_mode: Chewy.post_filter_mode || Chewy.filter_mode ) end |
Instance Method Details
#==(other) ⇒ Object
19 20 21 |
# File 'lib/chewy/query/criteria.rb', line 19 def ==(other) other.is_a?(self.class) && storages == other.storages end |
#merge(other) ⇒ Object
107 108 109 |
# File 'lib/chewy/query/criteria.rb', line 107 def merge(other) clone.merge!(other) end |
#merge!(other) ⇒ Object
100 101 102 103 104 105 |
# File 'lib/chewy/query/criteria.rb', line 100 def merge!(other) STORAGES.each do |storage| send("update_#{storage}", other.send(storage)) end self end |
#none? ⇒ Boolean
39 40 41 |
# File 'lib/chewy/query/criteria.rb', line 39 def none? !![:none] end |
#request_body ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/chewy/query/criteria.rb', line 111 def request_body body = _filtered_query(_request_query, _request_filter, .slice(:strategy)) if [:simple] {body: body.presence || {query: {match_all: {}}}} else body[:post_filter] = _request_post_filter if post_filters? body[:facets] = facets if facets? body[:aggregations] = aggregations if aggregations? body[:suggest] = suggest if suggest? body[:sort] = sort if sort? body[:_source] = fields if fields? body[:script_fields] = script_fields if script_fields? body = _boost_query(body) {body: body.merge!()}.merge!() end end |
#update_aggregations(modifier) ⇒ Object
63 64 65 |
# File 'lib/chewy/query/criteria.rb', line 63 def update_aggregations(modifier) aggregations.merge!(modifier) end |
#update_facets(modifier) ⇒ Object
55 56 57 |
# File 'lib/chewy/query/criteria.rb', line 55 def update_facets(modifier) facets.merge!(modifier) end |
#update_options(modifier) ⇒ Object
43 44 45 |
# File 'lib/chewy/query/criteria.rb', line 43 def (modifier) .merge!(modifier) end |
#update_request_options(modifier) ⇒ Object
47 48 49 |
# File 'lib/chewy/query/criteria.rb', line 47 def (modifier) .merge!(modifier) end |
#update_scores(modifier) ⇒ Object
59 60 61 |
# File 'lib/chewy/query/criteria.rb', line 59 def update_scores(modifier) @scores = scores + Array.wrap(modifier).reject(&:blank?) end |
#update_script_fields(modifier) ⇒ Object
71 72 73 |
# File 'lib/chewy/query/criteria.rb', line 71 def update_script_fields(modifier) script_fields.merge!(modifier) end |
#update_search_options(modifier) ⇒ Object
51 52 53 |
# File 'lib/chewy/query/criteria.rb', line 51 def (modifier) .merge!(modifier) end |
#update_sort(modifier, options = {}) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/chewy/query/criteria.rb', line 83 def update_sort(modifier, = {}) @sort = nil if [:purge] modifier = Array.wrap(modifier).flatten.map do |element| element.is_a?(Hash) ? element.map { |k, v| {k => v} } : element end.flatten @sort = sort + modifier end |
#update_suggest(modifier) ⇒ Object
67 68 69 |
# File 'lib/chewy/query/criteria.rb', line 67 def update_suggest(modifier) suggest.merge!(modifier) end |