Class: Druid::FilterOperator

Inherits:
FilterParameter show all
Defined in:
lib/druid/filter.rb

Instance Method Summary collapse

Methods inherited from FilterParameter

#as_json, #to_json, #to_s

Constructor Details

#initialize(name, takes_many) ⇒ FilterOperator

Returns a new instance of FilterOperator.



156
157
158
159
160
# File 'lib/druid/filter.rb', line 156

def initialize(name, takes_many)
  @name = name
  @takes_many = takes_many
  @elements = []
end

Instance Method Details

#!Object



188
189
190
191
192
193
194
195
196
# File 'lib/druid/filter.rb', line 188

def !()
  if @name == 'not'
    @elements[0]
  else
    filter_not = FilterOperator.new('not', false)
    filter_not.add(self)
    filter_not
  end
end

#&(other) ⇒ Object



166
167
168
169
170
171
172
173
174
175
# File 'lib/druid/filter.rb', line 166

def &(other)
  if @name == 'and'
    filter_and = self
  else
    filter_and = FilterOperator.new('and', true)
    filter_and.add(self)
  end
  filter_and.add(other)
  filter_and
end

#add(element) ⇒ Object



162
163
164
# File 'lib/druid/filter.rb', line 162

def add(element)
  @elements.push element
end

#to_hashObject



198
199
200
201
202
203
204
205
206
207
208
# File 'lib/druid/filter.rb', line 198

def to_hash
  result = {
    :type => @name
  }
  if @takes_many
    result[:fields] = @elements.map(&:to_hash)
  else
    result[:field] = @elements[0].to_hash
  end
  result
end

#|(other) ⇒ Object



177
178
179
180
181
182
183
184
185
186
# File 'lib/druid/filter.rb', line 177

def |(other)
  if @name == 'or'
    filter_or = self
  else
    filter_or = FilterOperator.new('or', true)
    filter_or.add(self)
  end
  filter_or.add(other)
  filter_or
end