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.



151
152
153
154
155
# File 'lib/druid/filter.rb', line 151

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

Instance Method Details

#!Object



183
184
185
186
187
188
189
190
191
# File 'lib/druid/filter.rb', line 183

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

#&(other) ⇒ Object



161
162
163
164
165
166
167
168
169
170
# File 'lib/druid/filter.rb', line 161

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



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

def add(element)
  @elements.push element
end

#to_hashObject



193
194
195
196
197
198
199
200
201
202
203
# File 'lib/druid/filter.rb', line 193

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



172
173
174
175
176
177
178
179
180
181
# File 'lib/druid/filter.rb', line 172

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