Class: ChewyQuery::Builder::Criteria
- Inherits:
-
Object
- Object
- ChewyQuery::Builder::Criteria
- Includes:
- Compose
- Defined in:
- lib/chewy_query/builder/criteria.rb
Constant Summary collapse
- ARRAY_STORAGES =
[:queries, :filters, :post_filters, :sort, :fields, :types, :scores]
- HASH_STORAGES =
[:options, :request_options, :facets, :aggregations, :suggest]
- STORAGES =
ARRAY_STORAGES + HASH_STORAGES
Instance Method Summary collapse
- #==(other) ⇒ Object
- #delete_all_request_body ⇒ Object
-
#initialize(options = {}) ⇒ Criteria
constructor
A new instance of Criteria.
- #merge(other) ⇒ Object
- #merge!(other) ⇒ Object
- #none? ⇒ Boolean
- #request_body ⇒ Object
- #update_aggregations(modifer) ⇒ Object
- #update_facets(modifer) ⇒ Object
- #update_options(modifer) ⇒ Object
- #update_request_options(modifer) ⇒ Object
- #update_scores(modifer) ⇒ Object
- #update_sort(modifer, options = {}) ⇒ Object
- #update_suggest(modifier) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Criteria
Returns a new instance of Criteria.
12 13 14 15 |
# File 'lib/chewy_query/builder/criteria.rb', line 12 def initialize( = {}) @options = { query_mode: :must, filter_mode: :and, post_filter_mode: nil }.merge() @options[:post_filter_mode] = @options[:filter_mode] unless @options[:post_filter_mode] end |
Instance Method Details
#==(other) ⇒ Object
17 18 19 |
# File 'lib/chewy_query/builder/criteria.rb', line 17 def ==(other) other.is_a?(self.class) && storages == other.storages end |
#delete_all_request_body ⇒ Object
117 118 119 120 |
# File 'lib/chewy_query/builder/criteria.rb', line 117 def delete_all_request_body filtered_query = _filtered_query(_request_query, _request_filter, .slice(:strategy)) { body: filtered_query.presence || { query: { match_all: {} } } } end |
#merge(other) ⇒ Object
97 98 99 |
# File 'lib/chewy_query/builder/criteria.rb', line 97 def merge(other) clone.merge!(other) end |
#merge!(other) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/chewy_query/builder/criteria.rb', line 90 def merge!(other) STORAGES.each do |storage| send("update_#{storage}", other.send(storage)) end self end |
#none? ⇒ Boolean
37 38 39 |
# File 'lib/chewy_query/builder/criteria.rb', line 37 def none? !![:none] end |
#request_body ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/chewy_query/builder/criteria.rb', line 101 def request_body body = {} body.merge!(_filtered_query(_request_query, _request_filter, .slice(:strategy))) body.merge!(post_filter: _request_post_filter) if post_filters? body.merge!(facets: facets) if facets? body.merge!(aggregations: aggregations) if aggregations? body.merge!(suggest: suggest) if suggest? body.merge!(sort: sort) if sort? body.merge!(_source: fields) if fields? body = _boost_query(body) { body: body.merge!() } end |
#update_aggregations(modifer) ⇒ Object
57 58 59 |
# File 'lib/chewy_query/builder/criteria.rb', line 57 def update_aggregations(modifer) aggregations.merge!(modifer) end |
#update_facets(modifer) ⇒ Object
49 50 51 |
# File 'lib/chewy_query/builder/criteria.rb', line 49 def update_facets(modifer) facets.merge!(modifer) end |
#update_options(modifer) ⇒ Object
41 42 43 |
# File 'lib/chewy_query/builder/criteria.rb', line 41 def (modifer) .merge!(modifer) end |
#update_request_options(modifer) ⇒ Object
45 46 47 |
# File 'lib/chewy_query/builder/criteria.rb', line 45 def (modifer) .merge!(modifer) end |
#update_scores(modifer) ⇒ Object
53 54 55 |
# File 'lib/chewy_query/builder/criteria.rb', line 53 def update_scores(modifer) @scores = scores + Array.wrap(modifer).reject(&:blank?) end |
#update_sort(modifer, options = {}) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/chewy_query/builder/criteria.rb', line 73 def update_sort(modifer, = {}) @sort = nil if [:purge] modifer = Array.wrap(modifer).flatten.map do |element| element.is_a?(Hash) ? element.map{|k, v| { k => v } } : element end.flatten @sort = sort + modifer end |
#update_suggest(modifier) ⇒ Object
61 62 63 |
# File 'lib/chewy_query/builder/criteria.rb', line 61 def update_suggest(modifier) suggest.merge!(modifier) end |