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 omitted 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.
| 145 146 147 | # File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 145 def and(other_value) join_into(:must, other_value) end | 
#merge!(other) ⇒ {Symbol => Array<Hash>}
Uses and logic to merge storages.
| 188 189 190 | # File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 188 def merge!(other) self.and(other.value) end | 
#minimum_should_match(new_value) ⇒ {Symbol => Array<Hash>}
Replaces minimum_should_match bool query value
| 178 179 180 | # File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 178 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.
| 111 112 113 | # File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 111 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.
| 131 132 133 | # File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 131 def must_not(other_value) update!(must_not: other_value) end | 
#not(other_value) ⇒ {Symbol => Array<Hash>}
Basically, an alias for #must_not.
| 169 170 171 | # File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 169 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.
| 159 160 161 | # File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 159 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.
| 207 208 209 210 | # File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 207 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.
| 121 122 123 | # File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 121 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.
| 198 199 200 | # File 'lib/chewy/search/parameters/concerns/query_storage.rb', line 198 def update!(other_value) @value = value.update(normalize(other_value)) end |