Module: Chewy::Search::Parameters::QueryStorage
- Included in:
- Filter, PostFilter, Query
- Defined in:
- lib/chewy/search/parameters/concerns/query_storage.rb
Overview
This is a basic storage implementation for query, filter
and post_filter storages. It uses bool query as a root
structure for each of them. The bool root is ommited on
rendering if there is only a single query in the must or
should array. Besides the standard parameter storage
capabilities, it provides specialized methods for the bool
query component arrays separate update.
Defined Under Namespace
Classes: Bool
Instance Method Summary collapse
-
#and(other_value) ⇒ {Symbol => Array<Hash>}
Unlike #must doesn't modify
mustarray, but joins 2 queries into a singlemustarray of the new rootboolquery. -
#merge!(other) ⇒ {Symbol => Array<Hash>}
Uses
andlogic to merge storages. -
#minimum_should_match(new_value) ⇒ {Symbol => Array<Hash>}
Replaces
minimum_should_matchbool query value. -
#must(other_value) ⇒ {Symbol => Array<Hash>}
Directly modifies
mustarray of the rootboolquery. -
#must_not(other_value) ⇒ {Symbol => Array<Hash>}
Directly modifies
must_notarray of the rootboolquery. -
#not(other_value) ⇒ {Symbol => Array<Hash>}
Basically, an alias for #must_not.
-
#or(other_value) ⇒ {Symbol => Array<Hash>}
Unlike #should doesn't modify
shouldarray, but joins 2 queries into a singleshouldarray of the new rootboolquery. -
#render ⇒ {Symbol => Hash}
Almost standard rendering logic, some reduction logic is applied to the value additionally.
-
#should(other_value) ⇒ {Symbol => Array<Hash>}
Directly modifies
shouldarray of the rootboolquery. -
#update!(other_value) ⇒ {Symbol => Array<Hash>}
Every query value is a hash of arrays and each array is glued with the corresponding array from the provided value.
Instance Method Details
#and(other_value) ⇒ {Symbol => Array<Hash>}
Unlike #must doesn't modify must array, but joins 2 queries
into a single must array of the new root bool query.
If any of the used queries is a bool query from the storage
and contains a single query in must or should array, it will
be reduced to this query, so in some cases it will act exactly
the same way as #must.
144 145 146 |
# File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 144 def and(other_value) join_into(:must, other_value) end |
#merge!(other) ⇒ {Symbol => Array<Hash>}
Uses and logic to merge storages.
187 188 189 |
# File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 187 def merge!(other) self.and(other.value) end |
#minimum_should_match(new_value) ⇒ {Symbol => Array<Hash>}
Replaces minimum_should_match bool query value
177 178 179 |
# File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 177 def minimum_should_match(new_value) update!(minimum_should_match: new_value) end |
#must(other_value) ⇒ {Symbol => Array<Hash>}
Directly modifies must array of the root bool query.
Pushes the passed query to the end of the array.
110 111 112 |
# File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 110 def must(other_value) update!(must: other_value) end |
#must_not(other_value) ⇒ {Symbol => Array<Hash>}
Directly modifies must_not array of the root bool query.
Pushes the passed query to the end of the array.
130 131 132 |
# File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 130 def must_not(other_value) update!(must_not: other_value) end |
#not(other_value) ⇒ {Symbol => Array<Hash>}
Basically, an alias for #must_not.
168 169 170 |
# File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 168 def not(other_value) update!(must_not: normalize(other_value).query) end |
#or(other_value) ⇒ {Symbol => Array<Hash>}
Unlike #should doesn't modify should array, but joins 2 queries
into a single should array of the new root bool query.
If any of the used queries is a bool query from the storage
and contains a single query in must or should array, it will
be reduced to this query, so in some cases it will act exactly
the same way as #should.
158 159 160 |
# File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 158 def or(other_value) join_into(:should, other_value) end |
#render ⇒ {Symbol => Hash}
Almost standard rendering logic, some reduction logic is applied to the value additionally.
206 207 208 209 |
# File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 206 def render rendered_bool = value.query {self.class.param_name => rendered_bool} if rendered_bool.present? end |
#should(other_value) ⇒ {Symbol => Array<Hash>}
Directly modifies should array of the root bool query.
Pushes the passed query to the end of the array.
120 121 122 |
# File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 120 def should(other_value) update!(should: other_value) end |
#update!(other_value) ⇒ {Symbol => Array<Hash>}
Every query value is a hash of arrays and each array is glued with the corresponding array from the provided value.
197 198 199 |
# File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 197 def update!(other_value) @value = value.update(normalize(other_value)) end |