Class: Chewy::Search::QueryProxy
- Inherits:
- 
      Object
      
        - Object
- Chewy::Search::QueryProxy
 
- Defined in:
- lib/chewy/search/query_proxy.rb
Overview
This specialized proxy class is used to provide an ability
of query, filter, post_filter parameters additional
modification.
Instance Method Summary collapse
- 
  
    
      #and(query_hash_or_scope = nil, &block)  ⇒ Chewy::Search::Request 
    
    
  
  
  
  
  
  
  
  
  
    Executes Parameters::QueryStorage#and in the scope of newly created request object. 
- 
  
    
      #initialize(parameter_name, request)  ⇒ QueryProxy 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of QueryProxy. 
- 
  
    
      #minimum_should_match(value)  ⇒ Chewy::Search::Request 
    
    
  
  
  
  
  
  
  
  
  
    Executes Parameters::QueryStorage#minimum_should_match in the scope of newly created request object. 
- 
  
    
      #must(query_hash = nil, &block)  ⇒ Chewy::Search::Request 
    
    
  
  
  
  
  
  
  
  
  
    Executes Parameters::QueryStorage#must in the scope of newly created request object. 
- 
  
    
      #must_not(query_hash = nil, &block)  ⇒ Chewy::Search::Request 
    
    
  
  
  
  
  
  
  
  
  
    Executes Parameters::QueryStorage#must_not in the scope of newly created request object. 
- 
  
    
      #not(query_hash_or_scope = nil, &block)  ⇒ Chewy::Search::Request 
    
    
  
  
  
  
  
  
  
  
  
    Executes Parameters::QueryStorage#not in the scope of newly created request object. 
- 
  
    
      #or(query_hash_or_scope = nil, &block)  ⇒ Chewy::Search::Request 
    
    
  
  
  
  
  
  
  
  
  
    Executes Parameters::QueryStorage#or in the scope of newly created request object. 
- 
  
    
      #should(query_hash = nil, &block)  ⇒ Chewy::Search::Request 
    
    
  
  
  
  
  
  
  
  
  
    Executes Parameters::QueryStorage#should in the scope of newly created request object. 
Constructor Details
#initialize(parameter_name, request) ⇒ QueryProxy
Returns a new instance of QueryProxy.
| 14 15 16 17 | # File 'lib/chewy/search/query_proxy.rb', line 14 def initialize(parameter_name, request) @parameter_name = parameter_name @request = request end | 
Instance Method Details
#and(query_hash) ⇒ Chewy::Search::Request #and(scope) ⇒ Chewy::Search::Request #and { ... } ⇒ Chewy::Search::Request
Executes Parameters::QueryStorage#and in the scope of newly created request object.
| 239 240 241 242 243 244 245 246 247 248 249 250 251 | # File 'lib/chewy/search/query_proxy.rb', line 239 %i[and or not].each do |method| define_method method do |query_hash_or_scope = nil, &block| unless query_hash_or_scope || block raise ArgumentError, "Please provide a parameter or a block to `#{method}`" end if !block && query_hash_or_scope.is_a?(Chewy::Search::Request) query_hash_or_scope = query_hash_or_scope.parameters[@parameter_name].value end @request.send(:modify, @parameter_name) { send(method, block || query_hash_or_scope) } end end | 
#minimum_should_match(value) ⇒ Chewy::Search::Request
Executes Parameters::QueryStorage#minimum_should_match in the scope of newly created request object.
| 259 260 261 | # File 'lib/chewy/search/query_proxy.rb', line 259 def minimum_should_match(value) @request.send(:modify, @parameter_name) { minimum_should_match(value) } end | 
#must(query_hash) ⇒ Chewy::Search::Request #must { ... } ⇒ Chewy::Search::Request
Executes Parameters::QueryStorage#must in the scope of newly created request object.
| 102 103 104 105 106 107 108 | # File 'lib/chewy/search/query_proxy.rb', line 102 %i[must should must_not].each do |method| define_method method do |query_hash = nil, &block| raise ArgumentError, "Please provide a parameter or a block to `#{method}`" unless query_hash || block @request.send(:modify, @parameter_name) { send(method, block || query_hash) } end end | 
#must_not(query_hash) ⇒ Chewy::Search::Request #must_not { ... } ⇒ Chewy::Search::Request
Executes Parameters::QueryStorage#must_not in the scope of newly created request object.
| 102 103 104 105 106 107 108 | # File 'lib/chewy/search/query_proxy.rb', line 102 %i[must should must_not].each do |method| define_method method do |query_hash = nil, &block| raise ArgumentError, "Please provide a parameter or a block to `#{method}`" unless query_hash || block @request.send(:modify, @parameter_name) { send(method, block || query_hash) } end end | 
#not(query_hash) ⇒ Chewy::Search::Request #not(scope) ⇒ Chewy::Search::Request #not { ... } ⇒ Chewy::Search::Request
Executes Parameters::QueryStorage#not in the scope of newly created request object. The only difference from #must_not is that is accepts another scope additionally.
| 239 240 241 242 243 244 245 246 247 248 249 250 251 | # File 'lib/chewy/search/query_proxy.rb', line 239 %i[and or not].each do |method| define_method method do |query_hash_or_scope = nil, &block| unless query_hash_or_scope || block raise ArgumentError, "Please provide a parameter or a block to `#{method}`" end if !block && query_hash_or_scope.is_a?(Chewy::Search::Request) query_hash_or_scope = query_hash_or_scope.parameters[@parameter_name].value end @request.send(:modify, @parameter_name) { send(method, block || query_hash_or_scope) } end end | 
#or(query_hash) ⇒ Chewy::Search::Request #or(scope) ⇒ Chewy::Search::Request #or { ... } ⇒ Chewy::Search::Request
Executes Parameters::QueryStorage#or in the scope of newly created request object.
| 239 240 241 242 243 244 245 246 247 248 249 250 251 | # File 'lib/chewy/search/query_proxy.rb', line 239 %i[and or not].each do |method| define_method method do |query_hash_or_scope = nil, &block| unless query_hash_or_scope || block raise ArgumentError, "Please provide a parameter or a block to `#{method}`" end if !block && query_hash_or_scope.is_a?(Chewy::Search::Request) query_hash_or_scope = query_hash_or_scope.parameters[@parameter_name].value end @request.send(:modify, @parameter_name) { send(method, block || query_hash_or_scope) } end end | 
#should(query_hash) ⇒ Chewy::Search::Request #should { ... } ⇒ Chewy::Search::Request
Executes Parameters::QueryStorage#should in the scope of newly created request object.
| 102 103 104 105 106 107 108 | # File 'lib/chewy/search/query_proxy.rb', line 102 %i[must should must_not].each do |method| define_method method do |query_hash = nil, &block| raise ArgumentError, "Please provide a parameter or a block to `#{method}`" unless query_hash || block @request.send(:modify, @parameter_name) { send(method, block || query_hash) } end end |