Class: ElasticRecord::Relation::SearchMethods::FilterChain

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_record/relation/search_methods.rb

Instance Method Summary collapse

Constructor Details

#initialize(scope) ⇒ FilterChain

Returns a new instance of FilterChain.



5
6
7
# File 'lib/elastic_record/relation/search_methods.rb', line 5

def initialize(scope)
  @scope = scope
end

Instance Method Details

#add_filter_nodes_to_scope(filters) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/elastic_record/relation/search_methods.rb', line 21

def add_filter_nodes_to_scope(filters)
  filter_value = @scope.send(:build_filter_nodes, filters).map do |filter_node|
    yield filter_node
  end

  @scope.filter_values += filter_value
  @scope
end

#nested(path, *filters) ⇒ Object



15
16
17
18
19
# File 'lib/elastic_record/relation/search_methods.rb', line 15

def nested(path, *filters)
  add_filter_nodes_to_scope(filters) do |filter_node|
    Arelastic::Queries::Nested.new path, filter_node
  end
end

#not(*filters) ⇒ Object



9
10
11
12
13
# File 'lib/elastic_record/relation/search_methods.rb', line 9

def not(*filters)
  add_filter_nodes_to_scope(filters) do |filter_node|
    Arelastic::Queries::Bool.new must_not: filter_node
  end
end