Navigation Menu

Skip to content

Commit

Permalink
Move codes to construct plan from single step definition to planner
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 14, 2015
1 parent 8de910b commit 41f3bb8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
37 changes: 35 additions & 2 deletions lib/droonga/planner.rb
Expand Up @@ -22,15 +22,48 @@ class Planner
include Loggable
include ErrorMessages

attr_writer :write, :random, :collector_class

def initialize(dataset)
@dataset = dataset
@write = false
@ramdom = nil
@collector_class = nil
end

def plan(message)
raise NotImplemented, "#{self.class.name}\##{__method__} must implement."
def plan(message, params={})
options = {
:write => write?,
:random => random?,
}
if @collector_class
reduce_key = "result"
options[:reduce] = {
reduce_key => @collector_class.operator,
}
end

record = params[:record]
if record
scatter(message, record, options)
else
broadcast(message, options)
end
end

private
def write?
@write
end

def random?
unless @random.nil?
@random
else
not write?
end
end

def scatter(message, record, options={})
planner = DistributedCommandPlanner.new(@dataset, message)
scatter_options = {
Expand Down
17 changes: 5 additions & 12 deletions lib/droonga/single_step.rb
Expand Up @@ -32,24 +32,17 @@ def plan(message)

# XXX: Re-implement me.
planner = Planner.new(@dataset)
options = {}
options[:write] = @definition.write?
options[:random] = @definition.random?
collector_class = @definition.collector_class
if collector_class
reduce_key = "result"
options[:reduce] = {
reduce_key => collector_class.operator,
}
end
planner.write = @definition.write?
planner.random = @definition.random?
planner.collector_class = @sdefinition.collector_class

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

Expand Down
1 change: 1 addition & 0 deletions test/unit/plugins/search/test_planner.rb
Expand Up @@ -174,6 +174,7 @@ def test_distribute
"query2",
],
"replica" => "random",
"post" => false,
}
message << searcher

Expand Down

0 comments on commit 41f3bb8

Please sign in to comment.