Class: Arelastic::Builders::Filter

Inherits:
Struct
  • Object
show all
Defined in:
lib/arelastic/builders/filter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fieldObject

Returns the value of attribute field

Returns:

  • (Object)

    the current value of field



3
4
5
# File 'lib/arelastic/builders/filter.rb', line 3

def field
  @field
end

Class Method Details

.[](field) ⇒ Object



5
6
7
# File 'lib/arelastic/builders/filter.rb', line 5

def [](field)
  new(field)
end

.ids(*ids) ⇒ Object



9
10
11
# File 'lib/arelastic/builders/filter.rb', line 9

def ids *ids
  Arelastic::Queries::Ids.new ids.flatten
end

.not(expr) ⇒ Object



13
14
15
# File 'lib/arelastic/builders/filter.rb', line 13

def not expr
  Arelastic::Queries::Bool.new must_not: expr
end

Instance Method Details

#eq(other) ⇒ Object



18
19
20
# File 'lib/arelastic/builders/filter.rb', line 18

def eq other
  Arelastic::Queries::Term.new field, other
end

#exists(options = {}) ⇒ Object



47
48
49
# File 'lib/arelastic/builders/filter.rb', line 47

def exists(options = {})
  Arelastic::Queries::Exists.new field, options
end

#gt(other) ⇒ Object



63
64
65
# File 'lib/arelastic/builders/filter.rb', line 63

def gt other
  range 'gt' => other
end

#gte(other) ⇒ Object



59
60
61
# File 'lib/arelastic/builders/filter.rb', line 59

def gte other
  range 'gte' => other
end

#in(other, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/arelastic/builders/filter.rb', line 26

def in other, options = {}
  case other
  when Range
    if other.exclude_end?
      range 'gte' => other.begin, 'lt' => other.end
    else
      range 'gte' => other.begin, 'lte' => other.end
    end
  else
    Arelastic::Queries::Terms.new field, other, options
  end
end

#lt(other) ⇒ Object



71
72
73
# File 'lib/arelastic/builders/filter.rb', line 71

def lt other
  range 'lt' => other
end

#lte(other) ⇒ Object



67
68
69
# File 'lib/arelastic/builders/filter.rb', line 67

def lte other
  range 'lte' => other
end

#missing(options = {}) ⇒ Object



51
52
53
# File 'lib/arelastic/builders/filter.rb', line 51

def missing(options = {})
  exists(options).negate
end

#not_eq(other) ⇒ Object



22
23
24
# File 'lib/arelastic/builders/filter.rb', line 22

def not_eq other
  self.class.not eq(other)
end

#not_in(other, options = {}) ⇒ Object



39
40
41
# File 'lib/arelastic/builders/filter.rb', line 39

def not_in other, options = {}
  self.class.not self.in(other, options)
end

#prefix(other) ⇒ Object



43
44
45
# File 'lib/arelastic/builders/filter.rb', line 43

def prefix other
  Arelastic::Queries::Prefix.new field, other
end

#regexp(other) ⇒ Object



55
56
57
# File 'lib/arelastic/builders/filter.rb', line 55

def regexp other
  Arelastic::Queries::Regexp.new field, other
end