Class: Druid::FilterOperator
Instance Method Summary
collapse
#as_json, #to_json, #to_s
Constructor Details
#initialize(name, takes_many) ⇒ FilterOperator
Returns a new instance of FilterOperator.
143
144
145
146
147
|
# File 'lib/druid/filter.rb', line 143
def initialize(name, takes_many)
@name = name
@takes_many = takes_many
@elements = []
end
|
Instance Method Details
#! ⇒ Object
175
176
177
178
179
180
181
182
183
|
# File 'lib/druid/filter.rb', line 175
def !()
if @name == 'not'
@elements[0]
else
filter_not = FilterOperator.new('not', false)
filter_not.add(self)
filter_not
end
end
|
#&(other) ⇒ Object
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/druid/filter.rb', line 153
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
149
150
151
|
# File 'lib/druid/filter.rb', line 149
def add(element)
@elements.push element
end
|
#to_hash ⇒ Object
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/druid/filter.rb', line 185
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
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/druid/filter.rb', line 164
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
|