Class: Droonga::Planner

Inherits:
Object
  • Object
show all
Includes:
ErrorMessages, Loggable
Defined in:
lib/droonga/planner.rb

Direct Known Subclasses

Droonga::Plugins::Search::Planner

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dataset) ⇒ Planner

Returns a new instance of Planner.



27
28
29
30
31
32
33
# File 'lib/droonga/planner.rb', line 27

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

Instance Attribute Details

#collector_class=(value) ⇒ Object (writeonly)

Sets the attribute collector_class

Parameters:

  • value

    the value to set the attribute collector_class to.



25
26
27
# File 'lib/droonga/planner.rb', line 25

def collector_class=(value)
  @collector_class = value
end

#single_operation=(value) ⇒ Object (writeonly)

Sets the attribute single_operation

Parameters:

  • value

    the value to set the attribute single_operation to.



25
26
27
# File 'lib/droonga/planner.rb', line 25

def single_operation=(value)
  @single_operation = value
end

#use_all_replicas=(value) ⇒ Object (writeonly)

Sets the attribute use_all_replicas

Parameters:

  • value

    the value to set the attribute use_all_replicas to.



25
26
27
# File 'lib/droonga/planner.rb', line 25

def use_all_replicas=(value)
  @use_all_replicas = value
end

#write=(value) ⇒ Object (writeonly)

Sets the attribute write

Parameters:

  • value

    the value to set the attribute write to.



25
26
27
# File 'lib/droonga/planner.rb', line 25

def write=(value)
  @write = value
end

Instance Method Details

#plan(message, params = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/droonga/planner.rb', line 35

def plan(message, params={})
  options = {
    :record => params[:record],
  }

  #TODO: We don't have to reduce results of the message when
  #      the message doesn't have "replyTo" information, because:
  #
  #       * Currently the "super step" mecahnism is not
  #         implemented yet.
  #       * So, reduced results won't be forwarded to other
  #         handlers directly. Results will be forwarded to
  #         the sender as the "response".
  #       * So, if "replyTo" information is not given, the
  #         reduced result will have no receiver.
  #
  #      However, in the future after the "super step" mechanism
  #      is introduced, reduced results can be required even if
  #      the request message have no "replyTo" information.
  #      Then we must update this logic.
  if @collector_class and message["replyTo"]
    reduce_key = "result"
    options[:reduce] = {
      reduce_key => @collector_class.operator,
    }
  end

  if options[:record] or single_operation?
    scatter(message, options)
  else
    broadcast(message, options)
  end
end