Module: Chewy::Search::Scoping

Extended by:
ActiveSupport::Concern
Included in:
Request
Defined in:
lib/chewy/search/scoping.rb

Overview

This module along with Chewy::Search provides an ability to use names scopes.

Examples:

class UsersIndex < Chewy::Index
  def self.by_name(name)
    query(match: {name: name})
  end

  def self.by_age(age)
    filter(term: {age: age})
  end
end

UsersIndex.limit(10).by_name('Martin')
# => <UsersIndex::Query {..., :body=>{:size=>10, :query=>{:match=>{:name=>"Martin"}}}}>
UsersIndex.limit(10).by_name('Martin').by_age(42)
# => <UsersIndex::Query {..., :body=>{:size=>10, :query=>{:bool=>{
#      :must=>{:match=>{:name=>"Martin"}},
#      :filter=>{:term=>{:age=>42}}}}}}>

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#scoping { ... } ⇒ Object

Wraps any method to make it contents be executed inside the current request scope.

Yields:

  • executes the block after the current context is put at the top of the scope stack

See Also:



41
42
43
44
45
46
# File 'lib/chewy/search/scoping.rb', line 41

def scoping
  self.class.scopes.push(self)
  yield
ensure
  self.class.scopes.pop
end