Class: Droonga::Plugins::Search::ReduceCollector

Inherits:
Collector
  • Object
show all
Defined in:
lib/droonga/plugins/search.rb

Instance Method Summary collapse

Methods inherited from Collector

#initialize, message

Methods included from Droonga::Pluggable

#find_sub_classes, #options

Constructor Details

This class inherits a constructor from Droonga::Collector

Instance Method Details

#collect(message) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/droonga/plugins/search.rb', line 142

def collect(message)
  #XXX This is just a workaround. Errors should be handled by the framework itself.
  if message.name == "errors"
    basic_reduce_collector = Basic::ReduceCollector.new
    return basic_reduce_collector.collect(message)
  end

  message.input.each do |output_name, elements|
    old_value = message.values[output_name]
    if old_value
      value = reduce_elements(elements, old_value, message.value)
    else
      value = message.value
    end
    message.values[output_name] = value
  end
end

#reduce_elements(elements, left_values, right_values) ⇒ Object



160
161
162
163
164
165
166
167
# File 'lib/droonga/plugins/search.rb', line 160

def reduce_elements(elements, left_values, right_values)
  result = {}
  elements.each do |key, deal|
    reducer = Reducer.new(deal)
    result[key] = reducer.reduce(left_values[key], right_values[key])
  end
  result
end