fluent-plugin-droonga 0.9.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dir-locals.el +3 -0
- data/.travis.yml +6 -2
- data/README.md +6 -7
- data/Rakefile +23 -6
- data/fluent-plugin-droonga.gemspec +2 -2
- data/lib/droonga/adapter.rb +12 -3
- data/lib/droonga/adapter_runner.rb +28 -23
- data/lib/droonga/catalog/base.rb +7 -111
- data/lib/droonga/catalog/dataset.rb +13 -25
- data/lib/droonga/catalog/errors.rb +94 -0
- data/lib/droonga/catalog/schema.rb +277 -0
- data/lib/droonga/catalog/version1.rb +404 -0
- data/lib/droonga/catalog/version2.rb +160 -0
- data/lib/droonga/catalog_loader.rb +27 -4
- data/lib/droonga/catalog_observer.rb +44 -6
- data/lib/droonga/collector.rb +12 -10
- data/lib/droonga/{handler_plugin.rb → collector_message.rb} +47 -20
- data/lib/droonga/collector_runner.rb +64 -0
- data/lib/droonga/collectors.rb +18 -0
- data/lib/droonga/{catalog.rb → collectors/add.rb} +9 -7
- data/lib/droonga/{command_repository.rb → collectors/and.rb} +7 -14
- data/lib/droonga/collectors/sum.rb +26 -0
- data/lib/droonga/dispatcher.rb +74 -41
- data/lib/droonga/distributed_command_planner.rb +2 -2
- data/lib/droonga/engine.rb +13 -5
- data/lib/droonga/{message_processing_error.rb → error.rb} +33 -12
- data/lib/droonga/{plugin/planner/search.rb → error_messages.rb} +12 -10
- data/lib/droonga/farm.rb +15 -14
- data/lib/droonga/fluent_message_sender.rb +15 -11
- data/lib/droonga/forwarder.rb +22 -18
- data/lib/droonga/handler.rb +8 -2
- data/lib/droonga/handler_runner.rb +47 -26
- data/lib/droonga/input_message.rb +6 -6
- data/lib/droonga/{command.rb → loggable.rb} +7 -14
- data/lib/droonga/logger.rb +56 -15
- data/lib/droonga/message_matcher.rb +12 -7
- data/lib/droonga/message_pusher.rb +8 -4
- data/lib/droonga/message_receiver.rb +11 -9
- data/lib/droonga/output_message.rb +2 -0
- data/lib/droonga/planner.rb +21 -10
- data/lib/droonga/plugin.rb +15 -0
- data/lib/droonga/plugin/metadata/{adapter_message.rb → adapter_input_message.rb} +6 -14
- data/lib/droonga/plugin/metadata/adapter_output_message.rb +39 -0
- data/lib/droonga/plugin/metadata/collector_message.rb +39 -0
- data/lib/droonga/plugin/metadata/input_message.rb +15 -0
- data/lib/droonga/plugin_loader.rb +33 -25
- data/lib/droonga/plugin_registry.rb +9 -1
- data/lib/droonga/plugins/basic.rb +54 -0
- data/lib/droonga/plugins/crud.rb +36 -15
- data/lib/droonga/plugins/error.rb +5 -4
- data/lib/droonga/plugins/groonga.rb +9 -6
- data/lib/droonga/plugins/groonga/column_create.rb +10 -5
- data/lib/droonga/plugins/groonga/generic_command.rb +2 -8
- data/lib/droonga/plugins/groonga/generic_response.rb +2 -2
- data/lib/droonga/plugins/groonga/select.rb +2 -2
- data/lib/droonga/plugins/groonga/table_create.rb +9 -4
- data/lib/droonga/plugins/groonga/table_remove.rb +10 -5
- data/lib/droonga/plugins/search.rb +106 -5
- data/lib/droonga/plugins/search/distributed_search_planner.rb +398 -0
- data/lib/droonga/plugins/watch.rb +41 -20
- data/lib/droonga/processor.rb +12 -9
- data/lib/droonga/{plugin/collector/basic.rb → reducer.rb} +36 -50
- data/lib/droonga/replier.rb +7 -4
- data/lib/droonga/searcher.rb +40 -37
- data/lib/droonga/server.rb +8 -6
- data/lib/droonga/session.rb +17 -7
- data/lib/droonga/single_step.rb +53 -0
- data/lib/droonga/{plugin/planner/watch.rb → single_step_definition.rb} +27 -26
- data/lib/droonga/{partition.rb → slice.rb} +23 -12
- data/lib/droonga/status_code.rb +25 -0
- data/lib/droonga/step_runner.rb +63 -0
- data/lib/droonga/watch_schema.rb +7 -3
- data/lib/droonga/watcher.rb +4 -4
- data/lib/droonga/worker.rb +6 -6
- data/lib/fluent/plugin/out_droonga.rb +27 -2
- data/sample/cluster/catalog.json +33 -32
- data/test/command/config/default/catalog.json +72 -45
- data/test/command/config/version1/catalog.json +68 -0
- data/test/command/config/version1/fluentd.conf +11 -0
- data/test/command/suite/message/error/missing-dataset.expected +1 -1
- data/test/command/suite/message/error/unknown-dataset.expected +1 -1
- data/test/command/suite/message/error/unknown-type.expected +13 -0
- data/test/command/suite/message/error/{unknown-command.test → unknown-type.test} +1 -1
- data/test/command/suite/search/error/missing-source-parameter.expected +1 -1
- data/test/command/suite/search/error/unknown-source.expected +15 -3
- data/test/command/suite/watch/subscribe.expected +1 -3
- data/test/command/suite/watch/unsubscribe.expected +1 -3
- data/test/performance/watch/catalog.json +1 -0
- data/test/unit/catalog/test_dataset.rb +16 -358
- data/test/unit/catalog/test_schema.rb +285 -0
- data/test/unit/catalog/test_version1.rb +222 -28
- data/test/unit/catalog/test_version2.rb +155 -0
- data/test/unit/fixtures/catalog/version2.json +62 -0
- data/test/unit/helper/distributed_search_planner_helper.rb +2 -2
- data/test/unit/plugins/crud/test_add.rb +13 -13
- data/test/unit/plugins/groonga/test_column_create.rb +14 -11
- data/test/unit/plugins/groonga/test_table_create.rb +4 -9
- data/test/unit/plugins/groonga/test_table_remove.rb +4 -9
- data/test/unit/{plugin/planner/search_planner → plugins/search/planner}/test_basic.rb +0 -0
- data/test/unit/{plugin/planner/search_planner → plugins/search/planner}/test_group_by.rb +0 -0
- data/test/unit/{plugin/planner/search_planner → plugins/search/planner}/test_output.rb +0 -0
- data/test/unit/{plugin/planner/search_planner → plugins/search/planner}/test_sort_by.rb +0 -0
- data/test/unit/{plugin/collector/test_search.rb → plugins/search/test_collector.rb} +40 -39
- data/test/unit/plugins/{test_search.rb → search/test_handler.rb} +6 -5
- data/test/unit/{plugin/planner/test_search.rb → plugins/search/test_planner.rb} +3 -3
- data/test/unit/{plugin/collector → plugins}/test_basic.rb +68 -50
- data/test/unit/plugins/test_groonga.rb +2 -15
- data/test/unit/plugins/test_watch.rb +25 -22
- data/test/unit/test_message_matcher.rb +29 -6
- data/test/unit/test_output.rb +4 -0
- metadata +58 -50
- data/lib/droonga/collector_plugin.rb +0 -50
- data/lib/droonga/legacy_pluggable.rb +0 -66
- data/lib/droonga/legacy_plugin.rb +0 -57
- data/lib/droonga/legacy_plugin_repository.rb +0 -54
- data/lib/droonga/planner_plugin.rb +0 -54
- data/lib/droonga/plugin/collector/search.rb +0 -98
- data/lib/droonga/plugin/planner/crud.rb +0 -49
- data/lib/droonga/plugin/planner/distributed_search_planner.rb +0 -393
- data/lib/droonga/plugin/planner/groonga.rb +0 -54
- data/lib/droonga/plugin_registerable.rb +0 -75
- data/test/command/suite/message/error/unknown-command.expected +0 -13
- data/test/unit/test_command_repository.rb +0 -39
- data/test/unit/test_legacy_plugin.rb +0 -50
- data/test/unit/test_legacy_plugin_repository.rb +0 -89
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
|
-
# Copyright (C) 2013 Droonga Project
|
3
|
+
# Copyright (C) 2013-2014 Droonga Project
|
4
4
|
#
|
5
5
|
# This library is free software; you can redistribute it and/or
|
6
6
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -17,39 +17,47 @@
|
|
17
17
|
|
18
18
|
require "pathname"
|
19
19
|
|
20
|
+
require "droonga/loggable"
|
21
|
+
|
20
22
|
module Droonga
|
21
23
|
class PluginLoader
|
24
|
+
include Loggable
|
25
|
+
|
22
26
|
class << self
|
23
27
|
def load_all
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
28
|
+
loader = new
|
29
|
+
loader.load_all
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
end
|
35
|
+
|
36
|
+
def load(name)
|
37
|
+
logger.debug("loading...: <#{name}>")
|
38
|
+
path = "droonga/plugins/#{name}"
|
39
|
+
begin
|
40
|
+
require path
|
41
|
+
rescue StandardError, SyntaxError => error
|
42
|
+
logger.exception("failed to load: <#{path}>", error)
|
43
|
+
raise
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
47
|
+
def load_all
|
48
|
+
$LOAD_PATH.each do |load_path|
|
49
|
+
search_pattern = "#{load_path}/droonga/plugins/*.rb"
|
50
|
+
logger.debug("searching...: <#{search_pattern}>")
|
51
|
+
Pathname.glob(search_pattern) do |plugin_path|
|
52
|
+
name = Pathname(plugin_path).basename(".rb").to_s
|
53
|
+
load(name)
|
54
|
+
end
|
55
|
+
end
|
48
56
|
end
|
49
57
|
|
50
|
-
|
51
|
-
|
52
|
-
|
58
|
+
private
|
59
|
+
def log_tag
|
60
|
+
"plugin-loader"
|
53
61
|
end
|
54
62
|
end
|
55
63
|
end
|
@@ -17,6 +17,12 @@ module Droonga
|
|
17
17
|
class PluginRegistry
|
18
18
|
include Enumerable
|
19
19
|
|
20
|
+
class UnknownPlugin < Error
|
21
|
+
def initialize(name, klass)
|
22
|
+
super("[#{klass}] Plugin not found: <#{name}>")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
20
26
|
def initialize
|
21
27
|
@plugins = {}
|
22
28
|
end
|
@@ -39,7 +45,9 @@ module Droonga
|
|
39
45
|
|
40
46
|
def find_sub_classes(name, klass)
|
41
47
|
plugin_module = self[name]
|
42
|
-
|
48
|
+
if plugin_module.nil?
|
49
|
+
raise UnknownPlugin.new(name, klass)
|
50
|
+
end
|
43
51
|
sub_classes = []
|
44
52
|
collect_sub_classes_recursive(plugin_module, klass, sub_classes)
|
45
53
|
sub_classes
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Copyright (C) 2014 Droonga Project
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License version 2.1 as published by the Free Software Foundation.
|
6
|
+
#
|
7
|
+
# This library is distributed in the hope that it will be useful,
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
10
|
+
# Lesser General Public License for more details.
|
11
|
+
#
|
12
|
+
# You should have received a copy of the GNU Lesser General Public
|
13
|
+
# License along with this library; if not, write to the Free Software
|
14
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
15
|
+
|
16
|
+
require "droonga/plugin"
|
17
|
+
require "droonga/reducer"
|
18
|
+
|
19
|
+
module Droonga
|
20
|
+
module Plugins
|
21
|
+
module Basic
|
22
|
+
extend Plugin
|
23
|
+
register("basic")
|
24
|
+
|
25
|
+
class GatherCollector < Droonga::Collector
|
26
|
+
message.pattern = ["task.step.type", :equal, "gather"]
|
27
|
+
|
28
|
+
def collect(message)
|
29
|
+
output = message.input || message.name
|
30
|
+
if output.is_a?(Hash)
|
31
|
+
output_name = output["output"]
|
32
|
+
else
|
33
|
+
output_name = output
|
34
|
+
end
|
35
|
+
message.values[output_name] = message.value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class ReduceCollector < Droonga::Collector
|
40
|
+
message.pattern = ["task.step.type", :equal, "reduce"]
|
41
|
+
|
42
|
+
def collect(message)
|
43
|
+
message.input.each do |output_name, deal|
|
44
|
+
left_value = message.values[output_name]
|
45
|
+
right_value = message.value
|
46
|
+
reducer = Reducer.new(deal)
|
47
|
+
value = reducer.reduce(left_value, right_value)
|
48
|
+
message.values[output_name] = value
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/droonga/plugins/crud.rb
CHANGED
@@ -16,28 +16,40 @@
|
|
16
16
|
require "groonga"
|
17
17
|
|
18
18
|
require "droonga/plugin"
|
19
|
-
require "droonga/
|
19
|
+
require "droonga/error_messages"
|
20
20
|
|
21
21
|
module Droonga
|
22
22
|
module Plugins
|
23
23
|
module CRUD
|
24
|
-
Plugin
|
24
|
+
extend Plugin
|
25
|
+
register("crud")
|
25
26
|
|
26
27
|
class Adapter < Droonga::Adapter
|
27
|
-
|
28
|
-
|
28
|
+
input_message.pattern = ["type", :equal, "add"]
|
29
|
+
output_message.pattern = ["body.success", :exist]
|
30
|
+
|
31
|
+
def adapt_input(input_message)
|
32
|
+
request = input_message.body
|
33
|
+
key = request["key"] || rand.to_s
|
34
|
+
values = request["values"] || {}
|
35
|
+
request["filter"] = values.merge("key" => key)
|
36
|
+
end
|
29
37
|
|
30
38
|
def adapt_output(output_message)
|
31
|
-
|
32
|
-
|
33
|
-
|
39
|
+
if output_message.errors
|
40
|
+
detail = output_message.body["detail"]
|
41
|
+
return if detail.nil?
|
42
|
+
detail.delete("filter")
|
43
|
+
output_message.errors.each do |path, error|
|
44
|
+
error["body"]["detail"].delete("filter")
|
45
|
+
end
|
46
|
+
else
|
47
|
+
output_message.body.delete("filter")
|
34
48
|
end
|
35
49
|
end
|
36
50
|
end
|
37
51
|
|
38
52
|
class Handler < Droonga::Handler
|
39
|
-
message.type = "add"
|
40
|
-
|
41
53
|
class MissingTableParameter < BadRequest
|
42
54
|
def initialize
|
43
55
|
super("\"table\" must be specified.")
|
@@ -71,12 +83,8 @@ module Droonga
|
|
71
83
|
end
|
72
84
|
end
|
73
85
|
|
74
|
-
def handle(message
|
75
|
-
|
76
|
-
outputs = {
|
77
|
-
"success" => succeeded,
|
78
|
-
}
|
79
|
-
messenger.emit(outputs)
|
86
|
+
def handle(message)
|
87
|
+
process_add(message.request)
|
80
88
|
end
|
81
89
|
|
82
90
|
private
|
@@ -119,6 +127,19 @@ module Droonga
|
|
119
127
|
end
|
120
128
|
end
|
121
129
|
end
|
130
|
+
|
131
|
+
define_single_step do |step|
|
132
|
+
step.name = "add"
|
133
|
+
step.inputs = {
|
134
|
+
"table" => {
|
135
|
+
:type => :table,
|
136
|
+
:filter => "filter",
|
137
|
+
},
|
138
|
+
}
|
139
|
+
step.write = true
|
140
|
+
step.handler = Handler
|
141
|
+
step.collector = Collectors::And
|
142
|
+
end
|
122
143
|
end
|
123
144
|
end
|
124
145
|
end
|
@@ -18,14 +18,15 @@ require "droonga/plugin"
|
|
18
18
|
module Droonga
|
19
19
|
module Plugins
|
20
20
|
module Error
|
21
|
-
Plugin
|
21
|
+
extend Plugin
|
22
|
+
register("error")
|
22
23
|
|
23
24
|
class Adapter < Droonga::Adapter
|
24
|
-
|
25
|
+
output_message.pattern = ["body.errors", :exist]
|
25
26
|
|
26
27
|
def adapt_output(output_message)
|
27
28
|
errors = output_message.body["errors"]
|
28
|
-
if errors
|
29
|
+
if errors and !errors.empty?
|
29
30
|
output_message.errors = errors
|
30
31
|
|
31
32
|
status_codes = []
|
@@ -36,7 +37,7 @@ module Droonga
|
|
36
37
|
if status_codes.size == 1
|
37
38
|
output_message.status_code = status_codes.first
|
38
39
|
else
|
39
|
-
output_message.status_code =
|
40
|
+
output_message.status_code = ErrorMessages::InternalServerError::STATUS_CODE
|
40
41
|
end
|
41
42
|
|
42
43
|
output_message.body = errors.values.first["body"]
|
@@ -14,16 +14,19 @@
|
|
14
14
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
15
15
|
|
16
16
|
require "droonga/plugin"
|
17
|
-
require "droonga/plugins/groonga/generic_response"
|
18
|
-
require "droonga/plugins/groonga/select"
|
19
|
-
require "droonga/plugins/groonga/table_create"
|
20
|
-
require "droonga/plugins/groonga/table_remove"
|
21
|
-
require "droonga/plugins/groonga/column_create"
|
22
17
|
|
23
18
|
module Droonga
|
24
19
|
module Plugins
|
25
20
|
module Groonga
|
26
|
-
Plugin
|
21
|
+
extend Plugin
|
22
|
+
register("groonga")
|
27
23
|
end
|
28
24
|
end
|
29
25
|
end
|
26
|
+
|
27
|
+
require "droonga/plugins/groonga/generic_response"
|
28
|
+
require "droonga/plugins/groonga/select"
|
29
|
+
require "droonga/plugins/groonga/table_create"
|
30
|
+
require "droonga/plugins/groonga/table_remove"
|
31
|
+
require "droonga/plugins/groonga/column_create"
|
32
|
+
|
@@ -28,7 +28,7 @@ module Droonga
|
|
28
28
|
@command = command_class.new("column_create", request)
|
29
29
|
|
30
30
|
table_name = @command["table"]
|
31
|
-
if table_name.nil?
|
31
|
+
if table_name.nil? or @context[table_name].nil?
|
32
32
|
message = "table doesn't exist: <#{table_name.to_s}>"
|
33
33
|
raise CommandError.new(:status => Status::INVALID_ARGUMENT,
|
34
34
|
:message => message,
|
@@ -108,15 +108,20 @@ module Droonga
|
|
108
108
|
end
|
109
109
|
|
110
110
|
class Handler < Droonga::Handler
|
111
|
-
message.type = "column_create"
|
112
111
|
action.synchronous = true
|
113
112
|
|
114
|
-
def handle(message
|
113
|
+
def handle(message)
|
115
114
|
command = Command.new(@context)
|
116
|
-
|
117
|
-
messenger.emit(outputs)
|
115
|
+
command.execute(message.request)
|
118
116
|
end
|
119
117
|
end
|
118
|
+
|
119
|
+
Groonga.define_single_step do |step|
|
120
|
+
step.name = "column_create"
|
121
|
+
step.write = true
|
122
|
+
step.handler = Handler
|
123
|
+
step.collector = Collectors::Add
|
124
|
+
end
|
120
125
|
end
|
121
126
|
end
|
122
127
|
end
|
@@ -41,9 +41,9 @@ module Droonga
|
|
41
41
|
def execute(request)
|
42
42
|
@start_time = Time.now.to_f
|
43
43
|
result = process_request(request)
|
44
|
-
|
44
|
+
[header(Status::SUCCESS), result]
|
45
45
|
rescue CommandError => error
|
46
|
-
|
46
|
+
[header(error.status, error.message), error.result]
|
47
47
|
end
|
48
48
|
|
49
49
|
private
|
@@ -53,12 +53,6 @@ module Droonga
|
|
53
53
|
header.push(error_message) unless error_message.empty?
|
54
54
|
header
|
55
55
|
end
|
56
|
-
|
57
|
-
def format(header, body)
|
58
|
-
{
|
59
|
-
"result" => [header, body],
|
60
|
-
}
|
61
|
-
end
|
62
56
|
end
|
63
57
|
end
|
64
58
|
end
|
@@ -25,8 +25,8 @@ module Droonga
|
|
25
25
|
"table_remove",
|
26
26
|
"column_create",
|
27
27
|
]
|
28
|
-
|
29
|
-
|
28
|
+
input_message.pattern = ["type", :in, groonga_commands]
|
29
|
+
output_message.pattern = ["body.result", :exist]
|
30
30
|
|
31
31
|
def adapt_output(output_message)
|
32
32
|
output_message.body = output_message.body["result"]
|
@@ -101,13 +101,13 @@ module Droonga
|
|
101
101
|
end
|
102
102
|
|
103
103
|
class Adapter < Droonga::Adapter
|
104
|
-
|
104
|
+
input_message.pattern = ["type", :equal, "select"]
|
105
105
|
|
106
106
|
def adapt_input(input_message)
|
107
107
|
converter = RequestConverter.new
|
108
108
|
select_request = input_message.body
|
109
109
|
search_request = converter.convert(select_request)
|
110
|
-
input_message.
|
110
|
+
input_message.type = "search"
|
111
111
|
input_message.body = search_request
|
112
112
|
end
|
113
113
|
|
@@ -91,15 +91,20 @@ module Droonga
|
|
91
91
|
end
|
92
92
|
|
93
93
|
class Handler < Droonga::Handler
|
94
|
-
message.type = "table_create"
|
95
94
|
action.synchronous = true
|
96
95
|
|
97
|
-
def handle(message
|
96
|
+
def handle(message)
|
98
97
|
command = Command.new(@context)
|
99
|
-
|
100
|
-
messenger.emit(outputs)
|
98
|
+
command.execute(message.request)
|
101
99
|
end
|
102
100
|
end
|
101
|
+
|
102
|
+
Groonga.define_single_step do |step|
|
103
|
+
step.name = "table_create"
|
104
|
+
step.write = true
|
105
|
+
step.handler = Handler
|
106
|
+
step.collector = Collectors::Add
|
107
|
+
end
|
103
108
|
end
|
104
109
|
end
|
105
110
|
end
|
@@ -28,7 +28,7 @@ module Droonga
|
|
28
28
|
@command = command_class.new("table_remove", request)
|
29
29
|
|
30
30
|
name = @command["name"]
|
31
|
-
if name.nil?
|
31
|
+
if name.nil? or @context[name].nil?
|
32
32
|
raise CommandError.new(:status => Status::INVALID_ARGUMENT,
|
33
33
|
:message => "table not found",
|
34
34
|
:result => false)
|
@@ -42,15 +42,20 @@ module Droonga
|
|
42
42
|
end
|
43
43
|
|
44
44
|
class Handler < Droonga::Handler
|
45
|
-
message.type = "table_remove"
|
46
45
|
action.synchronous = true
|
47
46
|
|
48
|
-
def handle(message
|
47
|
+
def handle(message)
|
49
48
|
command = Command.new(@context)
|
50
|
-
|
51
|
-
messenger.emit(outputs)
|
49
|
+
command.execute(message.request)
|
52
50
|
end
|
53
51
|
end
|
52
|
+
|
53
|
+
Groonga.define_single_step do |step|
|
54
|
+
step.name = "table_remove"
|
55
|
+
step.write = true
|
56
|
+
step.handler = Handler
|
57
|
+
step.collector = Collectors::Add
|
58
|
+
end
|
54
59
|
end
|
55
60
|
end
|
56
61
|
end
|
@@ -15,16 +15,23 @@
|
|
15
15
|
|
16
16
|
require "droonga/plugin"
|
17
17
|
require "droonga/searcher"
|
18
|
+
require "droonga/plugins/search/distributed_search_planner"
|
18
19
|
|
19
20
|
module Droonga
|
20
21
|
module Plugins
|
21
22
|
module Search
|
22
|
-
Plugin
|
23
|
+
extend Plugin
|
24
|
+
register("search")
|
23
25
|
|
24
|
-
class
|
25
|
-
message
|
26
|
+
class Planner < Droonga::Planner
|
27
|
+
def plan(message)
|
28
|
+
planner = DistributedSearchPlanner.new(message)
|
29
|
+
planner.plan
|
30
|
+
end
|
31
|
+
end
|
26
32
|
|
27
|
-
|
33
|
+
class Handler < Droonga::Handler
|
34
|
+
def handle(message)
|
28
35
|
searcher = Droonga::Searcher.new(@context)
|
29
36
|
values = {}
|
30
37
|
request = message.request
|
@@ -32,9 +39,103 @@ module Droonga
|
|
32
39
|
searcher.search(request["queries"]).each do |output, value|
|
33
40
|
values[output] = value
|
34
41
|
end
|
35
|
-
|
42
|
+
values
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class GatherCollector < Droonga::Collector
|
47
|
+
message.pattern = ["task.step.type", :equal, "search_gather"]
|
48
|
+
|
49
|
+
def collect(message)
|
50
|
+
output = message.input || message.name
|
51
|
+
if output.is_a?(Hash)
|
52
|
+
elements = output["elements"]
|
53
|
+
if elements and elements.is_a?(Hash)
|
54
|
+
# because "count" mapper requires all records,
|
55
|
+
# I have to apply it at first, before "limit" and "offset" are applied.
|
56
|
+
body = message.body
|
57
|
+
value = message.value
|
58
|
+
count_mapper = elements["count"]
|
59
|
+
if count_mapper
|
60
|
+
if count_mapper["no_output"]
|
61
|
+
value.delete("count")
|
62
|
+
else
|
63
|
+
value["count"] = value[count_mapper["target"]].size
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
records_mapper = elements["records"]
|
68
|
+
if records_mapper and value["records"]
|
69
|
+
if records_mapper["no_output"]
|
70
|
+
value.delete("records")
|
71
|
+
else
|
72
|
+
value["records"] = Reducer.apply_range(value["records"],
|
73
|
+
records_mapper)
|
74
|
+
value["records"] = apply_output_attributes_and_format(value["records"], records_mapper)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
output_name = output["output"]
|
79
|
+
else
|
80
|
+
output_name = output
|
81
|
+
end
|
82
|
+
message.values[output_name] = message.value
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
def apply_output_attributes_and_format(items, output)
|
87
|
+
attributes = output["attributes"] || []
|
88
|
+
if output["format"] == "complex"
|
89
|
+
items.collect do |item|
|
90
|
+
complex_item = {}
|
91
|
+
attributes.each_with_index do |label, index|
|
92
|
+
complex_item[label] = item[index]
|
93
|
+
end
|
94
|
+
complex_item
|
95
|
+
end
|
96
|
+
else
|
97
|
+
items.collect do |item|
|
98
|
+
item[0...attributes.size]
|
99
|
+
end
|
100
|
+
end
|
36
101
|
end
|
37
102
|
end
|
103
|
+
|
104
|
+
class ReduceCollector < Droonga::Collector
|
105
|
+
message.pattern = ["task.step.type", :equal, "search_reduce"]
|
106
|
+
|
107
|
+
def collect(message)
|
108
|
+
#XXX This is just a workaround. Errors should be handled by the framework itself.
|
109
|
+
if message.name == "errors"
|
110
|
+
basic_reduce_collector = Basic::ReduceCollector.new
|
111
|
+
return basic_reduce_collector.collect(message)
|
112
|
+
end
|
113
|
+
|
114
|
+
message.input.each do |output_name, elements|
|
115
|
+
old_value = message.values[output_name]
|
116
|
+
if old_value
|
117
|
+
value = reduce_elements(elements, old_value, message.value)
|
118
|
+
else
|
119
|
+
value = message.value
|
120
|
+
end
|
121
|
+
message.values[output_name] = value
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def reduce_elements(elements, left_values, right_values)
|
126
|
+
result = {}
|
127
|
+
elements.each do |key, deal|
|
128
|
+
reducer = Reducer.new(deal)
|
129
|
+
result[key] = reducer.reduce(left_values[key], right_values[key])
|
130
|
+
end
|
131
|
+
result
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
define_single_step do |step|
|
136
|
+
step.name = "search"
|
137
|
+
step.handler = Handler
|
138
|
+
end
|
38
139
|
end
|
39
140
|
end
|
40
141
|
end
|