Class: Droonga::SingleStep

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/single_step.rb

Instance Method Summary collapse

Constructor Details

#initialize(dataset, definition) ⇒ SingleStep

Returns a new instance of SingleStep.



21
22
23
24
# File 'lib/droonga/single_step.rb', line 21

def initialize(dataset, definition)
  @dataset = dataset
  @definition = definition
end

Instance Method Details

#find_fact_input(inputs, fact, body) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/droonga/single_step.rb', line 50

def find_fact_input(inputs, fact, body)
  inputs.each do |key, input|
    if input[:type] == :table
      # for backward compatibility. We can remove the following code
      # when all our catalog.json specify "fact" parameter.
      return input if fact.nil?

      return input if body[key] == fact
    end
  end
  nil
end

#plan(message) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/droonga/single_step.rb', line 26

def plan(message)
  if message["type"] == "search"
    # XXX: workaround
    planner = Plugins::Search::Planner.new(@dataset)
    return planner.plan(message)
  end

  # XXX: Re-implement me.
  planner = Planner.new(@dataset)
  planner.write = @definition.write?
  planner.single_operation = @definition.single_operation?
  planner.use_all_replicas = @definition.use_all_replicas?
  planner.collector_class = @definition.collector_class

  body = message["body"]
  fact_input = find_fact_input(@definition.inputs, @dataset.fact, body)
  if fact_input
    record = body[fact_input[:filter]]
    planner.plan(message, :record => record)
  else
    planner.plan(message)
  end
end