fluent-plugin-droonga 0.0.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +6 -0
- data/.yardopts +7 -0
- data/Gemfile +14 -2
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/Rakefile +27 -5
- data/benchmark/benchmark.rb +1 -1
- data/benchmark/utils.rb +9 -6
- data/benchmark/watch/benchmark-notify.rb +2 -2
- data/benchmark/watch/benchmark-publish.rb +1 -1
- data/benchmark/watch/benchmark-scan.rb +1 -1
- data/benchmark/watch/catalog.json +1 -1
- data/bin/grn2jsons +1 -1
- data/fluent-plugin-droonga.gemspec +5 -3
- data/lib/droonga/adapter.rb +13 -130
- data/lib/droonga/adapter_plugin.rb +51 -0
- data/lib/droonga/catalog.rb +2 -2
- data/lib/droonga/collector.rb +107 -0
- data/lib/droonga/collector_plugin.rb +82 -0
- data/lib/droonga/command_mapper.rb +1 -1
- data/lib/droonga/{proxy.rb → dispatcher.rb} +116 -151
- data/lib/droonga/distributor.rb +51 -0
- data/lib/droonga/distributor_plugin.rb +59 -0
- data/lib/droonga/engine.rb +9 -50
- data/lib/droonga/farm.rb +47 -0
- data/lib/droonga/forwarder.rb +125 -0
- data/lib/droonga/handler.rb +69 -60
- data/lib/droonga/handler_plugin.rb +22 -11
- data/lib/droonga/input_message.rb +51 -0
- data/lib/droonga/job_queue.rb +5 -1
- data/lib/droonga/job_queue_schema.rb +1 -1
- data/lib/droonga/logger.rb +1 -1
- data/lib/droonga/partition.rb +76 -0
- data/lib/droonga/pluggable.rb +62 -0
- data/lib/droonga/plugin.rb +18 -16
- data/lib/droonga/plugin/{adapter_groonga.rb → adapter/groonga.rb} +10 -10
- data/lib/droonga/plugin/adapter/groonga/select.rb +13 -4
- data/lib/droonga/plugin/collector/basic.rb +142 -0
- data/lib/droonga/plugin/distributor/crud.rb +43 -0
- data/lib/droonga/plugin/distributor/groonga.rb +37 -0
- data/lib/droonga/plugin/distributor/search.rb +273 -0
- data/lib/droonga/plugin/distributor/watch.rb +39 -0
- data/lib/droonga/plugin/{handler_add.rb → handler/add.rb} +6 -6
- data/lib/droonga/plugin/{handler_forward.rb → handler/forward.rb} +9 -4
- data/lib/droonga/plugin/{handler_groonga.rb → handler/groonga.rb} +36 -4
- data/lib/droonga/plugin/handler/groonga/column_create.rb +5 -9
- data/lib/droonga/plugin/handler/groonga/table_create.rb +9 -18
- data/lib/droonga/plugin/{handler_search.rb → handler/search.rb} +4 -4
- data/lib/droonga/plugin/{handler_watch.rb → handler/watch.rb} +4 -4
- data/lib/droonga/plugin_loader.rb +45 -0
- data/lib/droonga/plugin_registerable.rb +51 -0
- data/lib/droonga/plugin_repository.rb +56 -0
- data/lib/droonga/processor.rb +64 -0
- data/lib/droonga/searcher.rb +16 -7
- data/lib/droonga/server.rb +5 -9
- data/lib/droonga/sweeper.rb +1 -1
- data/lib/droonga/watch_schema.rb +1 -1
- data/lib/droonga/watcher.rb +1 -1
- data/lib/droonga/worker.rb +21 -9
- data/lib/fluent/plugin/out_droonga.rb +33 -15
- data/lib/groonga_command_converter.rb +1 -1
- data/sample/cluster/fluentd.conf +0 -1
- data/test/command/config/default/catalog.json +43 -0
- data/test/command/config/default/fluentd.conf +11 -0
- data/test/command/fixture/documents.jsons +208 -0
- data/test/command/fixture/user-table-array.jsons +38 -0
- data/test/command/fixture/user-table.jsons +38 -0
- data/test/command/run-test.rb +35 -0
- data/test/command/suite/add/minimum.expected +12 -0
- data/test/command/suite/add/minimum.test +11 -0
- data/test/command/suite/add/with-values.expected +12 -0
- data/test/command/suite/add/with-values.test +17 -0
- data/test/command/suite/add/without-key.expected +12 -0
- data/test/command/suite/add/without-key.test +16 -0
- data/test/command/suite/groonga/column_create/scalar.expected +34 -0
- data/test/command/suite/groonga/column_create/scalar.test +17 -0
- data/test/command/suite/groonga/column_create/vector.expected +34 -0
- data/test/command/suite/groonga/column_create/vector.test +18 -0
- data/test/command/suite/groonga/select/minimum.expected +26 -0
- data/test/command/suite/groonga/select/minimum.test +8 -0
- data/test/command/suite/groonga/table_create/array.expected +17 -0
- data/test/command/suite/groonga/table_create/array.test +8 -0
- data/test/command/suite/groonga/table_create/hash.expected +17 -0
- data/test/command/suite/groonga/table_create/hash.test +8 -0
- data/test/command/suite/search/array-attribute-label.expected +25 -0
- data/test/command/suite/search/array-attribute-label.test +30 -0
- data/test/command/suite/search/chained-queries.expected +45 -0
- data/test/command/suite/search/chained-queries.test +43 -0
- data/test/command/suite/search/complex.expected +52 -0
- data/test/command/suite/search/complex.test +25 -0
- data/test/command/suite/search/condition-nested.expected +19 -0
- data/test/command/suite/search/condition-nested.test +29 -0
- data/test/command/suite/search/condition-query.expected +28 -0
- data/test/command/suite/search/condition-query.test +25 -0
- data/test/command/suite/search/condition-script.expected +28 -0
- data/test/command/suite/search/condition-script.test +28 -0
- data/test/command/suite/search/hash-attribute-label.expected +34 -0
- data/test/command/suite/search/hash-attribute-label.test +38 -0
- data/test/command/suite/search/minimum.expected +13 -0
- data/test/command/suite/search/minimum.test +16 -0
- data/test/command/suite/search/multiple-queries.expected +39 -0
- data/test/command/suite/search/multiple-queries.test +39 -0
- data/test/command/suite/search/output-range.expected +28 -0
- data/test/command/suite/search/output-range.test +25 -0
- data/test/command/suite/search/simple.expected +52 -0
- data/test/command/suite/search/simple.test +24 -0
- data/test/command/suite/search/sort-and-output-range.expected +25 -0
- data/test/command/suite/search/sort-and-output-range.test +29 -0
- data/test/command/suite/search/sort-range.expected +28 -0
- data/test/command/suite/search/sort-range.test +28 -0
- data/test/command/suite/search/sort-with-invisible-column.expected +28 -0
- data/test/command/suite/search/sort-with-invisible-column.test +28 -0
- data/test/unit/fixtures/array.grn +18 -0
- data/test/{fixtures → unit/fixtures}/catalog.json +0 -0
- data/test/{fixtures → unit/fixtures}/document.grn +20 -9
- data/test/unit/fixtures/reference/array.grn +11 -0
- data/test/unit/fixtures/reference/hash.grn +7 -0
- data/test/{helper.rb → unit/helper.rb} +2 -1
- data/test/{helper → unit/helper}/fixture.rb +1 -1
- data/test/unit/helper/plugin_helper.rb +38 -0
- data/test/{helper → unit/helper}/sandbox.rb +19 -6
- data/test/{helper → unit/helper}/stub_worker.rb +1 -1
- data/test/{helper → unit/helper}/watch_helper.rb +1 -13
- data/test/{plugin → unit/plugin}/adapter/groonga/test_select.rb +108 -4
- data/test/unit/plugin/collector/test_basic.rb +558 -0
- data/test/unit/plugin/distributor/test_search.rb +914 -0
- data/test/{plugin → unit/plugin}/handler/groonga/test_column_create.rb +18 -14
- data/test/{plugin → unit/plugin}/handler/groonga/test_table_create.rb +13 -11
- data/test/{plugin/handler/test_handler_add.rb → unit/plugin/handler/test_add.rb} +2 -14
- data/test/{plugin/handler/test_handler_groonga.rb → unit/plugin/handler/test_groonga.rb} +6 -26
- data/test/unit/plugin/handler/test_search.rb +601 -0
- data/test/{plugin/handler/test_handler_watch.rb → unit/plugin/handler/test_watch.rb} +2 -2
- data/test/{run-test.rb → unit/run-test.rb} +3 -3
- data/test/{test_adapter.rb → unit/test_adapter.rb} +17 -14
- data/test/{test_catalog.rb → unit/test_catalog.rb} +4 -4
- data/test/{test_command_mapper.rb → unit/test_command_mapper.rb} +1 -1
- data/test/{test_groonga_command_converter.rb → unit/test_groonga_command_converter.rb} +3 -3
- data/test/{test_job_queue_schema.rb → unit/test_job_queue_schema.rb} +1 -1
- data/test/{test_output.rb → unit/test_output.rb} +9 -9
- data/test/{test_handler.rb → unit/test_plugin.rb} +19 -22
- data/test/unit/test_plugin_repository.rb +89 -0
- data/test/{test_sweeper.rb → unit/test_sweeper.rb} +1 -1
- data/test/{test_watch_schema.rb → unit/test_watch_schema.rb} +1 -1
- data/test/{test_watcher.rb → unit/test_watcher.rb} +1 -1
- metadata +226 -66
- data/lib/droonga/executor.rb +0 -289
- data/lib/droonga/plugin/handler_proxy.rb +0 -82
- data/test/plugin/handler/test_handler_search.rb +0 -512
- data/test/test_worker.rb +0 -144
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
|
-
# Copyright (C) 2013
|
3
|
+
# Copyright (C) 2013 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,11 +17,11 @@
|
|
17
17
|
|
18
18
|
require "groonga"
|
19
19
|
|
20
|
-
require "droonga/
|
20
|
+
require "droonga/handler_plugin"
|
21
21
|
|
22
22
|
module Droonga
|
23
|
-
class GroongaHandler < Droonga::
|
24
|
-
|
23
|
+
class GroongaHandler < Droonga::HandlerPlugin
|
24
|
+
repository.register("groonga", self)
|
25
25
|
|
26
26
|
command :table_create
|
27
27
|
def table_create(request)
|
@@ -45,6 +45,38 @@ module Droonga
|
|
45
45
|
SUCCESS = 0
|
46
46
|
INVALID_ARGUMENT = -22
|
47
47
|
end
|
48
|
+
|
49
|
+
class Command
|
50
|
+
class CommandError < StandardError
|
51
|
+
attr_reader :status, :message, :result
|
52
|
+
|
53
|
+
def initialize(params={})
|
54
|
+
@status = params[:status]
|
55
|
+
@message = params[:message]
|
56
|
+
@result = params[:result]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def initialize(context)
|
61
|
+
@context = context
|
62
|
+
end
|
63
|
+
|
64
|
+
def execute(request)
|
65
|
+
@start_time = Time.now.to_f
|
66
|
+
result = process_request(request)
|
67
|
+
[header(Status::SUCCESS), result]
|
68
|
+
rescue CommandError => error
|
69
|
+
[header(error.status, error.message), error.result]
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
def header(return_code, error_message="")
|
74
|
+
elapsed_time = Time.now.to_f - @start_time
|
75
|
+
header = [return_code, @start_time, elapsed_time]
|
76
|
+
header.push(error_message) unless error_message.empty?
|
77
|
+
header
|
78
|
+
end
|
79
|
+
end
|
48
80
|
end
|
49
81
|
end
|
50
82
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
|
-
# Copyright (C) 2013
|
3
|
+
# Copyright (C) 2013 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
|
@@ -20,12 +20,8 @@ require "groonga/command/column-create"
|
|
20
20
|
|
21
21
|
module Droonga
|
22
22
|
class GroongaHandler
|
23
|
-
class ColumnCreate
|
24
|
-
def
|
25
|
-
@context = context
|
26
|
-
end
|
27
|
-
|
28
|
-
def execute(request)
|
23
|
+
class ColumnCreate < Command
|
24
|
+
def process_request(request)
|
29
25
|
command_class = Groonga::Command.find("column_create")
|
30
26
|
@command = command_class.new("column_create", request)
|
31
27
|
|
@@ -48,7 +44,7 @@ module Droonga
|
|
48
44
|
table.column(column_name, column_type, options)
|
49
45
|
end
|
50
46
|
end
|
51
|
-
|
47
|
+
true
|
52
48
|
end
|
53
49
|
|
54
50
|
def create_column_options
|
@@ -78,7 +74,7 @@ module Droonga
|
|
78
74
|
table.index("#{target_table}.#{target_column}", options)
|
79
75
|
end
|
80
76
|
end
|
81
|
-
|
77
|
+
true
|
82
78
|
end
|
83
79
|
|
84
80
|
def create_index_options
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
|
-
# Copyright (C) 2013
|
3
|
+
# Copyright (C) 2013 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
|
@@ -20,32 +20,23 @@ require "groonga/command/table-create"
|
|
20
20
|
|
21
21
|
module Droonga
|
22
22
|
class GroongaHandler
|
23
|
-
class TableCreate
|
24
|
-
def
|
25
|
-
@context = context
|
26
|
-
end
|
27
|
-
|
28
|
-
def header(return_code, error_message="")
|
29
|
-
elapsed_time = Time.now.to_f - @start_time
|
30
|
-
header = [return_code, @start_time, elapsed_time]
|
31
|
-
header.push(error_message) unless error_message.empty?
|
32
|
-
header
|
33
|
-
end
|
34
|
-
|
35
|
-
def execute(request)
|
36
|
-
@start_time = Time.now.to_f
|
37
|
-
|
23
|
+
class TableCreate < Command
|
24
|
+
def process_request(request)
|
38
25
|
command_class = Groonga::Command.find("table_create")
|
39
26
|
@command = command_class.new("table_create", request)
|
40
27
|
|
41
28
|
name = @command["name"]
|
42
|
-
|
29
|
+
unless name
|
30
|
+
raise CommandError.new(:status => Status::INVALID_ARGUMENT,
|
31
|
+
:message => "Should not create anonymous table",
|
32
|
+
:result => false)
|
33
|
+
end
|
43
34
|
|
44
35
|
options = parse_command
|
45
36
|
Groonga::Schema.define(:context => @context) do |schema|
|
46
37
|
schema.create_table(name, options)
|
47
38
|
end
|
48
|
-
|
39
|
+
true
|
49
40
|
end
|
50
41
|
|
51
42
|
private
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
|
-
# Copyright (C) 2013
|
3
|
+
# Copyright (C) 2013 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
|
@@ -15,12 +15,12 @@
|
|
15
15
|
# License along with this library; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
17
|
|
18
|
-
require "droonga/
|
18
|
+
require "droonga/handler_plugin"
|
19
19
|
require "droonga/searcher"
|
20
20
|
|
21
21
|
module Droonga
|
22
|
-
class SearchHandler < Droonga::
|
23
|
-
|
22
|
+
class SearchHandler < Droonga::HandlerPlugin
|
23
|
+
repository.register("search", self)
|
24
24
|
|
25
25
|
command :search
|
26
26
|
def search(request)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
|
-
# Copyright (C) 2013
|
3
|
+
# Copyright (C) 2013 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
|
@@ -18,11 +18,11 @@
|
|
18
18
|
require "droonga/watcher"
|
19
19
|
require "droonga/sweeper"
|
20
20
|
require "droonga/watch_schema"
|
21
|
-
require "droonga/
|
21
|
+
require "droonga/handler_plugin"
|
22
22
|
|
23
23
|
module Droonga
|
24
|
-
class WatchHandler < Droonga::
|
25
|
-
|
24
|
+
class WatchHandler < Droonga::HandlerPlugin
|
25
|
+
repository.register("watch", self)
|
26
26
|
|
27
27
|
def initialize(*args)
|
28
28
|
super
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013 Droonga Project
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License version 2.1 as published by the Free Software Foundation.
|
8
|
+
#
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
|
18
|
+
module Droonga
|
19
|
+
class PluginLoader
|
20
|
+
class << self
|
21
|
+
def load_all
|
22
|
+
$LOAD_PATH.each do |load_path|
|
23
|
+
Dir.glob("#{load_path}/droonga/plugin/*") do |type_path|
|
24
|
+
next unless File.directory?(type_path)
|
25
|
+
type = File.basename(type_path)
|
26
|
+
Dir.glob("#{type_path}/*.rb") do |path|
|
27
|
+
name = File.basename(path, ".rb")
|
28
|
+
plugin = new(type, name)
|
29
|
+
plugin.load
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize(type, name)
|
37
|
+
@type = type
|
38
|
+
@name = name
|
39
|
+
end
|
40
|
+
|
41
|
+
def load
|
42
|
+
require "droonga/plugin/#{@type}/#{@name}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013 Droonga Project
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License version 2.1 as published by the Free Software Foundation.
|
8
|
+
#
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
|
18
|
+
require "droonga/command_mapper"
|
19
|
+
require "droonga/plugin_repository"
|
20
|
+
|
21
|
+
module Droonga
|
22
|
+
module PluginRegisterable
|
23
|
+
class << self
|
24
|
+
def extended(plugin_class)
|
25
|
+
super
|
26
|
+
plugin_class.class_variable_set(:@@repository, PluginRepository.new)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def repository
|
31
|
+
class_variable_get(:@@repository)
|
32
|
+
end
|
33
|
+
|
34
|
+
def inherited(sub_class)
|
35
|
+
super
|
36
|
+
sub_class.instance_variable_set(:@command_mapper, CommandMapper.new)
|
37
|
+
end
|
38
|
+
|
39
|
+
def command(name_or_map)
|
40
|
+
@command_mapper.register(name_or_map)
|
41
|
+
end
|
42
|
+
|
43
|
+
def method_name(command)
|
44
|
+
@command_mapper[command]
|
45
|
+
end
|
46
|
+
|
47
|
+
def processable?(command)
|
48
|
+
not method_name(command).nil?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013 Droonga Project
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License version 2.1 as published by the Free Software Foundation.
|
8
|
+
#
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
|
18
|
+
module Droonga
|
19
|
+
class PluginRepository
|
20
|
+
include Enumerable
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@plugins = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
def each(&block)
|
27
|
+
@plugins.each(&block)
|
28
|
+
end
|
29
|
+
|
30
|
+
def register(name, klass)
|
31
|
+
@plugins[name] = klass
|
32
|
+
end
|
33
|
+
|
34
|
+
def [](name)
|
35
|
+
@plugins[name]
|
36
|
+
end
|
37
|
+
|
38
|
+
def clear
|
39
|
+
@plugins.clear
|
40
|
+
end
|
41
|
+
|
42
|
+
def instantiate(name, *args, &block)
|
43
|
+
plugin_class = self[name]
|
44
|
+
if plugin_class.nil?
|
45
|
+
# TODO: use the original error
|
46
|
+
raise ArgumentError, "unknown plugin: <#{name}>"
|
47
|
+
end
|
48
|
+
begin
|
49
|
+
plugin_class.new(*args, &block)
|
50
|
+
rescue
|
51
|
+
p [plugin_class, plugin_class.method(:new), plugin_class.method(:new).arity, args.size]
|
52
|
+
raise
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013 Droonga Project
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License version 2.1 as published by the Free Software Foundation.
|
8
|
+
#
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
|
18
|
+
require "droonga/job_queue"
|
19
|
+
require "droonga/handler"
|
20
|
+
|
21
|
+
module Droonga
|
22
|
+
class Processor
|
23
|
+
def initialize(options={})
|
24
|
+
@options = options
|
25
|
+
@database_name = @options[:database]
|
26
|
+
@queue_name = @options[:options] || "DroongaQueue"
|
27
|
+
@n_workers = @options[:n_workers] || 0
|
28
|
+
end
|
29
|
+
|
30
|
+
def start
|
31
|
+
Droonga::JobQueue.ensure_schema(@database_name,
|
32
|
+
@queue_name)
|
33
|
+
@job_queue = JobQueue.open(@database_name, @queue_name)
|
34
|
+
@handler = Handler.new(@options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def shutdown
|
38
|
+
$log.trace("processor: shutdown: start")
|
39
|
+
@handler.shutdown
|
40
|
+
@job_queue.close
|
41
|
+
$log.trace("processor: shutdown: done")
|
42
|
+
end
|
43
|
+
|
44
|
+
def process(envelope, synchronous=nil)
|
45
|
+
$log.trace("proessor: process: start")
|
46
|
+
reply_to = envelope["replyTo"]
|
47
|
+
command = envelope["type"]
|
48
|
+
if @handler.processable?(command)
|
49
|
+
$log.trace("proessor: process: handlable: #{command}")
|
50
|
+
if synchronous.nil?
|
51
|
+
synchronous = @handler.prefer_synchronous?(command)
|
52
|
+
end
|
53
|
+
if @n_workers.zero? or synchronous
|
54
|
+
@handler.process(envelope)
|
55
|
+
else
|
56
|
+
@job_queue.push_message(envelope)
|
57
|
+
end
|
58
|
+
else
|
59
|
+
$log.trace("proessor: process: ignore #{command}")
|
60
|
+
end
|
61
|
+
$log.trace("proessor: process: done")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/droonga/searcher.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
|
-
# Copyright (C) 2013
|
3
|
+
# Copyright (C) 2013 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
|
@@ -159,8 +159,8 @@ module Droonga
|
|
159
159
|
end
|
160
160
|
if condition["query"]
|
161
161
|
options[:syntax] = :query
|
162
|
-
if condition["
|
163
|
-
case condition["
|
162
|
+
if condition["defaultOperator"]
|
163
|
+
case condition["defaultOperator"]
|
164
164
|
when "||"
|
165
165
|
options[:default_operator] = Groonga::Operator::OR
|
166
166
|
when "&&"
|
@@ -171,17 +171,17 @@ module Droonga
|
|
171
171
|
raise "undefined operator assigned #{condition["default_operator"]}"
|
172
172
|
end
|
173
173
|
end
|
174
|
-
if condition["
|
174
|
+
if condition["allowPragma"]
|
175
175
|
options[:allow_pragma] = true
|
176
176
|
end
|
177
|
-
if condition["
|
177
|
+
if condition["allowColumn"]
|
178
178
|
options[:allow_column] = true
|
179
179
|
end
|
180
180
|
expression.parse(condition["query"], options)
|
181
181
|
elsif condition["script"]
|
182
182
|
# "script" is ignored when "query" is also assigned.
|
183
183
|
options[:syntax] = :script
|
184
|
-
if condition["
|
184
|
+
if condition["allowUpdate"]
|
185
185
|
options[:allow_update] = true
|
186
186
|
end
|
187
187
|
expression.parse(condition["script"], options)
|
@@ -296,8 +296,12 @@ module Droonga
|
|
296
296
|
# XXX IMPLEMENT ME!!!
|
297
297
|
attributes = nil
|
298
298
|
if @query["output"]["format"] == "complex"
|
299
|
+
# should convert columnst to an object like:
|
300
|
+
# {"_id" => {"type" => "UInt32", "vector" => false}}
|
299
301
|
attributes = {}
|
300
302
|
else
|
303
|
+
# should convert columnst to an object like:
|
304
|
+
# [{"name" => "_id", "type" => "UInt32", "vector" => false}]
|
301
305
|
attributes = []
|
302
306
|
end
|
303
307
|
|
@@ -360,7 +364,12 @@ module Droonga
|
|
360
364
|
variable.value = record
|
361
365
|
expression.execute
|
362
366
|
else
|
363
|
-
record[attribute[:source]]
|
367
|
+
value = record[attribute[:source]]
|
368
|
+
if value.is_a?(Groonga::Record)
|
369
|
+
value.record_id
|
370
|
+
else
|
371
|
+
value
|
372
|
+
end
|
364
373
|
end
|
365
374
|
end
|
366
375
|
end
|