Class: Eson::Search::Bool

Inherits:
Object
  • Object
show all
Includes:
Filter, Query
Defined in:
lib/eson/search/bool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Query

included, #method_missing

Methods included from Filter

included, #method_missing

Constructor Details

#initialize(options = {}) ⇒ Bool

Returns a new instance of Bool.



13
14
15
# File 'lib/eson/search/bool.rb', line 13

def initialize(options = {})
  self.options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Eson::Search::Query

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions.



11
12
13
# File 'lib/eson/search/bool.rb', line 11

def conditions
  @conditions
end

#optionsObject

Returns the value of attribute options.



11
12
13
# File 'lib/eson/search/bool.rb', line 11

def options
  @options
end

Instance Method Details

#bool { ... } ⇒ self #bool { ... } ⇒ self

Overloads:

  • #bool { ... } ⇒ self

    Generates a ‘bool` filter in a filter context.

    Yields:

    • the block containing further options and subfilters

    Returns:

    • (self)

      the generated facet

  • #bool { ... } ⇒ self

    Generates a ‘bool` query in a query context.

    Yields:

    • the block containing further options and subqueries

    Returns:

    • (self)

      the generated facet



9
# File 'lib/eson/search/bool.rb', line 9

short_name :bool

#must(&block) ⇒ Object



21
22
23
24
# File 'lib/eson/search/bool.rb', line 21

def must(&block)
  q = (conditions[:must] ||= SubQuery.new(args))
  q.send(context, &block)
end

#must_not(&block) ⇒ Object



26
27
28
29
# File 'lib/eson/search/bool.rb', line 26

def must_not(&block)
  q = (conditions[:must_not] ||= SubQuery.new(args))
  q.send(context, &block)
end

#should(&block) ⇒ Object



31
32
33
34
# File 'lib/eson/search/bool.rb', line 31

def should(&block)
  q = (conditions[:should] ||= SubQuery.new(args))
  q.send(context, &block)
end

#to_query_hashObject



36
37
38
39
40
41
42
43
44
# File 'lib/eson/search/bool.rb', line 36

def to_query_hash
  result = {}

  conditions.each do |k,v|
    result[k] = v.to_query_hash
  end

  {name => result.merge(options)}
end