fluent-plugin-droonga 0.0.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,4 +1,4 @@
|
|
|
1
|
-
# Copyright (C) 2013
|
|
1
|
+
# Copyright (C) 2013 Droonga Project
|
|
2
2
|
#
|
|
3
3
|
# This library is free software; you can redistribute it and/or
|
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
|
@@ -15,14 +15,18 @@
|
|
|
15
15
|
|
|
16
16
|
class ColumnCreateTest < GroongaHandlerTest
|
|
17
17
|
def test_success
|
|
18
|
-
@
|
|
19
|
-
@
|
|
20
|
-
|
|
18
|
+
@plugin.table_create({"name" => "Books"})
|
|
19
|
+
@plugin.column_create({"table" => "Books", "name" => "title", "type" => "ShortText"})
|
|
20
|
+
response = @messages.last.first
|
|
21
|
+
assert_equal(
|
|
22
|
+
[[Droonga::GroongaHandler::Status::SUCCESS, NORMALIZED_START_TIME, NORMALIZED_ELAPSED_TIME], true],
|
|
23
|
+
[normalize_header(response.first), response.last]
|
|
24
|
+
)
|
|
21
25
|
end
|
|
22
26
|
|
|
23
27
|
def test_name
|
|
24
|
-
@
|
|
25
|
-
@
|
|
28
|
+
@plugin.table_create({"name" => "Books"})
|
|
29
|
+
@plugin.column_create({"table" => "Books", "name" => "title", "type" => "ShortText"})
|
|
26
30
|
assert_equal(<<-SCHEMA, dump)
|
|
27
31
|
table_create Books TABLE_HASH_KEY --key_type ShortText
|
|
28
32
|
column_create Books title COLUMN_SCALAR ShortText
|
|
@@ -30,8 +34,8 @@ column_create Books title COLUMN_SCALAR ShortText
|
|
|
30
34
|
end
|
|
31
35
|
|
|
32
36
|
def test_type
|
|
33
|
-
@
|
|
34
|
-
@
|
|
37
|
+
@plugin.table_create({"name" => "Books"})
|
|
38
|
+
@plugin.column_create({"table" => "Books", "name" => "main_text", "type" => "LongText"})
|
|
35
39
|
assert_equal(<<-SCHEMA, dump)
|
|
36
40
|
table_create Books TABLE_HASH_KEY --key_type ShortText
|
|
37
41
|
column_create Books main_text COLUMN_SCALAR LongText
|
|
@@ -55,8 +59,8 @@ column_create Books main_text COLUMN_SCALAR LongText
|
|
|
55
59
|
"type" => "ShortText",
|
|
56
60
|
"flags" => data[:flags],
|
|
57
61
|
}
|
|
58
|
-
@
|
|
59
|
-
@
|
|
62
|
+
@plugin.table_create({"name" => "Books"})
|
|
63
|
+
@plugin.column_create(request)
|
|
60
64
|
assert_equal(<<-EXPECTED, dump)
|
|
61
65
|
table_create Books TABLE_HASH_KEY --key_type ShortText
|
|
62
66
|
column_create Books title #{data[:flags]} ShortText
|
|
@@ -67,8 +71,8 @@ column_create Books title #{data[:flags]} ShortText
|
|
|
67
71
|
class IndexTest < self
|
|
68
72
|
def setup
|
|
69
73
|
super
|
|
70
|
-
@
|
|
71
|
-
@
|
|
74
|
+
@plugin.table_create({"name" => "Books"})
|
|
75
|
+
@plugin.column_create({"table" => "Books", "name" => "title", "type" => "ShortText"})
|
|
72
76
|
end
|
|
73
77
|
|
|
74
78
|
def test_index_column_type
|
|
@@ -82,7 +86,7 @@ column_create Books title #{data[:flags]} ShortText
|
|
|
82
86
|
"source" => "title",
|
|
83
87
|
"flags" => data[:flags],
|
|
84
88
|
}
|
|
85
|
-
@
|
|
89
|
+
@plugin.column_create(request)
|
|
86
90
|
assert_equal(<<-EXPECTED, dump)
|
|
87
91
|
table_create Books TABLE_HASH_KEY --key_type ShortText
|
|
88
92
|
column_create Books title COLUMN_SCALAR ShortText
|
|
@@ -114,7 +118,7 @@ column_create Books entry_title #{data[:flags]} Books title
|
|
|
114
118
|
"source" => "title",
|
|
115
119
|
"flags" => flags,
|
|
116
120
|
}
|
|
117
|
-
@
|
|
121
|
+
@plugin.column_create(request)
|
|
118
122
|
assert_equal(<<-EXPECTED, dump)
|
|
119
123
|
table_create Books TABLE_HASH_KEY --key_type ShortText
|
|
120
124
|
column_create Books title COLUMN_SCALAR ShortText
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright (C) 2013
|
|
1
|
+
# Copyright (C) 2013 Droonga Project
|
|
2
2
|
#
|
|
3
3
|
# This library is free software; you can redistribute it and/or
|
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
|
@@ -15,23 +15,25 @@
|
|
|
15
15
|
|
|
16
16
|
class TableCreateTest < GroongaHandlerTest
|
|
17
17
|
def test_success
|
|
18
|
-
@
|
|
18
|
+
@plugin.table_create({"name" => "Books"})
|
|
19
|
+
response = @messages.last.first
|
|
19
20
|
assert_equal(
|
|
20
21
|
[[Droonga::GroongaHandler::Status::SUCCESS, NORMALIZED_START_TIME, NORMALIZED_ELAPSED_TIME], true],
|
|
21
|
-
[normalize_header(
|
|
22
|
+
[normalize_header(response.first), response.last]
|
|
22
23
|
)
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
def test_failure
|
|
26
|
-
@
|
|
27
|
+
@plugin.table_create({})
|
|
28
|
+
response = @messages.last.first
|
|
27
29
|
assert_equal(
|
|
28
30
|
[[Droonga::GroongaHandler::Status::INVALID_ARGUMENT, NORMALIZED_START_TIME, NORMALIZED_ELAPSED_TIME], false],
|
|
29
|
-
[normalize_header(
|
|
31
|
+
[normalize_header(response.first), response.last]
|
|
30
32
|
)
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
def test_name
|
|
34
|
-
@
|
|
36
|
+
@plugin.table_create({"name" => "Books"})
|
|
35
37
|
assert_equal(<<-SCHEMA, dump)
|
|
36
38
|
table_create Books TABLE_HASH_KEY --key_type ShortText
|
|
37
39
|
SCHEMA
|
|
@@ -81,7 +83,7 @@ table_create Books TABLE_NO_KEY
|
|
|
81
83
|
"name" => "Books",
|
|
82
84
|
"flags" => data[:flags],
|
|
83
85
|
}
|
|
84
|
-
@
|
|
86
|
+
@plugin.table_create(request)
|
|
85
87
|
assert_equal(data[:schema], dump)
|
|
86
88
|
end
|
|
87
89
|
end
|
|
@@ -92,7 +94,7 @@ table_create Books TABLE_NO_KEY
|
|
|
92
94
|
"name" => "Books",
|
|
93
95
|
"key_type" => "Int32",
|
|
94
96
|
}
|
|
95
|
-
@
|
|
97
|
+
@plugin.table_create(request)
|
|
96
98
|
assert_equal(<<-SCHEMA, dump)
|
|
97
99
|
table_create Books TABLE_HASH_KEY --key_type Int32
|
|
98
100
|
SCHEMA
|
|
@@ -105,7 +107,7 @@ table_create Books TABLE_HASH_KEY --key_type Int32
|
|
|
105
107
|
"name" => "Books",
|
|
106
108
|
"value_type" => "Int32",
|
|
107
109
|
}
|
|
108
|
-
@
|
|
110
|
+
@plugin.table_create(request)
|
|
109
111
|
assert_equal(<<-SCHEMA, dump)
|
|
110
112
|
table_create Books TABLE_HASH_KEY --key_type ShortText --value_type Int32
|
|
111
113
|
SCHEMA
|
|
@@ -118,7 +120,7 @@ table_create Books TABLE_HASH_KEY --key_type ShortText --value_type Int32
|
|
|
118
120
|
"name" => "Books",
|
|
119
121
|
"default_tokenizer" => "TokenBigram",
|
|
120
122
|
}
|
|
121
|
-
@
|
|
123
|
+
@plugin.table_create(request)
|
|
122
124
|
assert_equal(<<-SCHEMA, dump)
|
|
123
125
|
table_create Books TABLE_HASH_KEY --key_type ShortText --default_tokenizer TokenBigram
|
|
124
126
|
SCHEMA
|
|
@@ -131,7 +133,7 @@ table_create Books TABLE_HASH_KEY --key_type ShortText --default_tokenizer Token
|
|
|
131
133
|
"name" => "Books",
|
|
132
134
|
"normalizer" => "NormalizerAuto",
|
|
133
135
|
}
|
|
134
|
-
@
|
|
136
|
+
@plugin.table_create(request)
|
|
135
137
|
assert_equal(<<-SCHEMA, dump)
|
|
136
138
|
table_create Books TABLE_HASH_KEY|KEY_NORMALIZE --key_type ShortText
|
|
137
139
|
SCHEMA
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright (C) 2013
|
|
1
|
+
# Copyright (C) 2013 Droonga Project
|
|
2
2
|
#
|
|
3
3
|
# This library is free software; you can redistribute it and/or
|
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# License along with this library; if not, write to the Free Software
|
|
14
14
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
15
15
|
|
|
16
|
-
require "droonga/plugin/
|
|
16
|
+
require "droonga/plugin/handler/add"
|
|
17
17
|
|
|
18
18
|
class AddHandlerTest < Test::Unit::TestCase
|
|
19
19
|
def setup
|
|
@@ -28,21 +28,9 @@ class AddHandlerTest < Test::Unit::TestCase
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
private
|
|
31
|
-
def setup_database
|
|
32
|
-
FileUtils.rm_rf(@database_path.dirname.to_s)
|
|
33
|
-
FileUtils.mkdir_p(@database_path.dirname.to_s)
|
|
34
|
-
@database = Groonga::Database.create(:path => @database_path.to_s)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
31
|
def setup_schema
|
|
38
32
|
end
|
|
39
33
|
|
|
40
|
-
def teardown_database
|
|
41
|
-
@database.close
|
|
42
|
-
@database = nil
|
|
43
|
-
FileUtils.rm_rf(@database_path.dirname.to_s)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
34
|
def setup_handler
|
|
47
35
|
@worker = StubWorker.new
|
|
48
36
|
@handler = Droonga::AddHandler.new(@worker)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright (C) 2013
|
|
1
|
+
# Copyright (C) 2013 Droonga Project
|
|
2
2
|
#
|
|
3
3
|
# This library is free software; you can redistribute it and/or
|
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
|
@@ -13,41 +13,21 @@
|
|
|
13
13
|
# License along with this library; if not, write to the Free Software
|
|
14
14
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
15
15
|
|
|
16
|
-
require "droonga/plugin/
|
|
16
|
+
require "droonga/plugin/handler/groonga"
|
|
17
17
|
|
|
18
18
|
class GroongaHandlerTest < Test::Unit::TestCase
|
|
19
|
+
include PluginHelper
|
|
20
|
+
|
|
19
21
|
def setup
|
|
20
22
|
setup_database
|
|
21
|
-
|
|
23
|
+
setup_plugin(Droonga::GroongaHandler)
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
def teardown
|
|
25
|
-
|
|
27
|
+
teardown_plugin
|
|
26
28
|
teardown_database
|
|
27
29
|
end
|
|
28
30
|
|
|
29
|
-
private
|
|
30
|
-
def setup_database
|
|
31
|
-
FileUtils.rm_rf(@database_path.dirname.to_s)
|
|
32
|
-
FileUtils.mkdir_p(@database_path.dirname.to_s)
|
|
33
|
-
@database = Groonga::Database.create(:path => @database_path.to_s)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def teardown_database
|
|
37
|
-
@database.close
|
|
38
|
-
@database = nil
|
|
39
|
-
FileUtils.rm_rf(@database_path.dirname.to_s)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def setup_handler
|
|
43
|
-
@worker = StubWorker.new
|
|
44
|
-
@handler = Droonga::GroongaHandler.new(@worker)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def teardown_handler
|
|
48
|
-
@handler = nil
|
|
49
|
-
end
|
|
50
|
-
|
|
51
31
|
private
|
|
52
32
|
def dump
|
|
53
33
|
database_dumper = Groonga::DatabaseDumper.new(:database => @database)
|
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
# Copyright (C) 2013 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/handler/search"
|
|
17
|
+
|
|
18
|
+
class SearchHandlerTest < Test::Unit::TestCase
|
|
19
|
+
include PluginHelper
|
|
20
|
+
|
|
21
|
+
def setup
|
|
22
|
+
setup_database
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def teardown
|
|
26
|
+
teardown_plugin
|
|
27
|
+
teardown_database
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
def search(request)
|
|
32
|
+
@plugin.search(request)
|
|
33
|
+
results_to_result_set(@messages)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def results_to_result_set(results)
|
|
37
|
+
result_set = {}
|
|
38
|
+
results.each do |result_and_name|
|
|
39
|
+
result, name = result_and_name
|
|
40
|
+
result_set[name] = normalize_result(result)
|
|
41
|
+
end
|
|
42
|
+
result_set
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def normalize_result(result)
|
|
46
|
+
result["startTime"] = start_time if result["startTime"]
|
|
47
|
+
result["elapsedTime"] = elapsed_time if result["elapsedTime"]
|
|
48
|
+
result
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def start_time
|
|
52
|
+
"2013-01-31T14:34:47+09:00"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def elapsed_time
|
|
56
|
+
0.01
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def assert_search(expected, request)
|
|
60
|
+
assert_equal(expected, search(request))
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
class GeneralTest < self
|
|
64
|
+
def setup
|
|
65
|
+
super
|
|
66
|
+
restore(fixture_data("document.grn"))
|
|
67
|
+
setup_plugin(Droonga::SearchHandler)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
class NoParameterTest < self
|
|
71
|
+
def test_empty
|
|
72
|
+
assert_search({}, {})
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
class QueriesTest < self
|
|
77
|
+
def test_empty
|
|
78
|
+
assert_search({}, {"queries" => {}})
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
class HashQueryTest < self
|
|
83
|
+
def test_string_matchTo
|
|
84
|
+
request = base_request
|
|
85
|
+
request["queries"]["sections-result"]["condition"] = {
|
|
86
|
+
"query" => "Groonga",
|
|
87
|
+
"matchTo" => "title"
|
|
88
|
+
}
|
|
89
|
+
assert_search({
|
|
90
|
+
"sections-result" => {
|
|
91
|
+
"records" => [
|
|
92
|
+
{ "title" => "Groonga overview" },
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
request)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def test_array_matchTo
|
|
100
|
+
request = base_request
|
|
101
|
+
request["queries"]["sections-result"]["condition"] = {
|
|
102
|
+
"query" => "Groonga",
|
|
103
|
+
"matchTo" => ["title"]
|
|
104
|
+
}
|
|
105
|
+
assert_search({
|
|
106
|
+
"sections-result" => {
|
|
107
|
+
"records" => [
|
|
108
|
+
{ "title" => "Groonga overview" },
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
request)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def base_request
|
|
116
|
+
{
|
|
117
|
+
"queries" => {
|
|
118
|
+
"sections-result" => {
|
|
119
|
+
"source" => "Sections",
|
|
120
|
+
"output" => {
|
|
121
|
+
"elements" => [
|
|
122
|
+
"records",
|
|
123
|
+
],
|
|
124
|
+
"format" => "complex",
|
|
125
|
+
"limit" => 1,
|
|
126
|
+
"attributes" => ["title"],
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
}
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
class SourceTest < self
|
|
135
|
+
def test_non_existent
|
|
136
|
+
assert_raise(Droonga::Searcher::UndefinedSourceError) do
|
|
137
|
+
search({
|
|
138
|
+
"queries" => {
|
|
139
|
+
"non-existent-result" => {
|
|
140
|
+
"source" => "non-existent",
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
})
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def test_existent
|
|
148
|
+
assert_search({
|
|
149
|
+
"sections-result" => {},
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"queries" => {
|
|
153
|
+
"sections-result" => {
|
|
154
|
+
"source" => "Sections",
|
|
155
|
+
"output" => {},
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
})
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
class OutputTest < self
|
|
163
|
+
def test_count
|
|
164
|
+
assert_search({
|
|
165
|
+
"sections-result" => {
|
|
166
|
+
"count" => 9,
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"queries" => {
|
|
171
|
+
"sections-result" => {
|
|
172
|
+
"source" => "Sections",
|
|
173
|
+
"output" => {
|
|
174
|
+
"elements" => [
|
|
175
|
+
"count",
|
|
176
|
+
],
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
})
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def test_elapsed_time
|
|
184
|
+
assert_search({
|
|
185
|
+
"sections-result" => {
|
|
186
|
+
"startTime" => start_time,
|
|
187
|
+
"elapsedTime" => elapsed_time,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"queries" => {
|
|
192
|
+
"sections-result" => {
|
|
193
|
+
"source" => "Sections",
|
|
194
|
+
"output" => {
|
|
195
|
+
"elements" => [
|
|
196
|
+
"startTime",
|
|
197
|
+
"elapsedTime",
|
|
198
|
+
],
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
})
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
class AttributesTest < self
|
|
206
|
+
def test_source_only
|
|
207
|
+
expected = {
|
|
208
|
+
"sections-result" => {
|
|
209
|
+
"records" => [
|
|
210
|
+
{
|
|
211
|
+
"_key" => "1.1",
|
|
212
|
+
"title" => "Groonga overview",
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
"_key" => "1.2",
|
|
216
|
+
"title" => "Full text search and Instant update",
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"_key" => "1.3",
|
|
220
|
+
"title" => "Column store and aggregate query",
|
|
221
|
+
},
|
|
222
|
+
],
|
|
223
|
+
},
|
|
224
|
+
}
|
|
225
|
+
request = {
|
|
226
|
+
"queries" => {
|
|
227
|
+
"sections-result" => {
|
|
228
|
+
"source" => "Sections",
|
|
229
|
+
"output" => {
|
|
230
|
+
"elements" => [
|
|
231
|
+
"records",
|
|
232
|
+
],
|
|
233
|
+
"format" => "complex",
|
|
234
|
+
"limit" => 3,
|
|
235
|
+
"attributes" => ["_key", "title"],
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
}
|
|
240
|
+
assert_search(expected, request)
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def test_label
|
|
244
|
+
expected = {
|
|
245
|
+
"sections-result" => {
|
|
246
|
+
"records" => [
|
|
247
|
+
{
|
|
248
|
+
"key" => "1.1",
|
|
249
|
+
"title" => "Groonga overview",
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
"key" => "1.2",
|
|
253
|
+
"title" => "Full text search and Instant update",
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
"key" => "1.3",
|
|
257
|
+
"title" => "Column store and aggregate query",
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
},
|
|
261
|
+
}
|
|
262
|
+
request = {
|
|
263
|
+
"queries" => {
|
|
264
|
+
"sections-result" => {
|
|
265
|
+
"source" => "Sections",
|
|
266
|
+
"output" => {
|
|
267
|
+
"elements" => [
|
|
268
|
+
"records",
|
|
269
|
+
],
|
|
270
|
+
"format" => "complex",
|
|
271
|
+
"limit" => 3,
|
|
272
|
+
"attributes" => [
|
|
273
|
+
{
|
|
274
|
+
"label" => "key",
|
|
275
|
+
"source" => "_key",
|
|
276
|
+
},
|
|
277
|
+
"title",
|
|
278
|
+
],
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
}
|
|
283
|
+
assert_search(expected, request)
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def test_static_value
|
|
287
|
+
expected = {
|
|
288
|
+
"sections-result" => {
|
|
289
|
+
"records" => [
|
|
290
|
+
{
|
|
291
|
+
"single_quote_string" => "string value",
|
|
292
|
+
"double_quote_string" => "string value",
|
|
293
|
+
"integer" => 29,
|
|
294
|
+
"complex_negative_number" => -29.29,
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
"single_quote_string" => "string value",
|
|
298
|
+
"double_quote_string" => "string value",
|
|
299
|
+
"integer" => 29,
|
|
300
|
+
"complex_negative_number" => -29.29,
|
|
301
|
+
},
|
|
302
|
+
],
|
|
303
|
+
},
|
|
304
|
+
}
|
|
305
|
+
request = {
|
|
306
|
+
"queries" => {
|
|
307
|
+
"sections-result" => {
|
|
308
|
+
"source" => "Sections",
|
|
309
|
+
"output" => {
|
|
310
|
+
"elements" => [
|
|
311
|
+
"records",
|
|
312
|
+
],
|
|
313
|
+
"format" => "complex",
|
|
314
|
+
"limit" => 2,
|
|
315
|
+
"attributes" => [
|
|
316
|
+
{
|
|
317
|
+
"label" => "single_quote_string",
|
|
318
|
+
"source" => "'string value'",
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
"label" => "double_quote_string",
|
|
322
|
+
"source" => '"string value"',
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
"label" => "integer",
|
|
326
|
+
"source" => "29",
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
"label" => "complex_negative_number",
|
|
330
|
+
"source" => "-29.29",
|
|
331
|
+
},
|
|
332
|
+
],
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
}
|
|
337
|
+
assert_search(expected, request)
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
def test_expression
|
|
341
|
+
expected = {
|
|
342
|
+
"sections-result" => {
|
|
343
|
+
"records" => [
|
|
344
|
+
{
|
|
345
|
+
"formatted title" => "<Groonga overview>",
|
|
346
|
+
"title" => "Groonga overview",
|
|
347
|
+
},
|
|
348
|
+
],
|
|
349
|
+
},
|
|
350
|
+
}
|
|
351
|
+
request = {
|
|
352
|
+
"queries" => {
|
|
353
|
+
"sections-result" => {
|
|
354
|
+
"source" => "Sections",
|
|
355
|
+
"output" => {
|
|
356
|
+
"elements" => [
|
|
357
|
+
"records",
|
|
358
|
+
],
|
|
359
|
+
"format" => "complex",
|
|
360
|
+
"limit" => 1,
|
|
361
|
+
"attributes" => [
|
|
362
|
+
"title",
|
|
363
|
+
{
|
|
364
|
+
"label" => "formatted title",
|
|
365
|
+
"source" => "'<' + title + '>'",
|
|
366
|
+
},
|
|
367
|
+
],
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
}
|
|
372
|
+
assert_search(expected, request)
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
def test_snippet_html
|
|
376
|
+
expected = {
|
|
377
|
+
"sections-result" => {
|
|
378
|
+
"records" => [
|
|
379
|
+
{
|
|
380
|
+
"title" => "Groonga overview",
|
|
381
|
+
"snippet" => [
|
|
382
|
+
"<span class=\"keyword\">Groonga</span> overview",
|
|
383
|
+
],
|
|
384
|
+
},
|
|
385
|
+
],
|
|
386
|
+
},
|
|
387
|
+
}
|
|
388
|
+
request = {
|
|
389
|
+
"queries" => {
|
|
390
|
+
"sections-result" => {
|
|
391
|
+
"source" => "Sections",
|
|
392
|
+
"condition" => {
|
|
393
|
+
"query" => "Groonga",
|
|
394
|
+
"matchTo" => ["title"],
|
|
395
|
+
},
|
|
396
|
+
"output" => {
|
|
397
|
+
"elements" => [
|
|
398
|
+
"records",
|
|
399
|
+
],
|
|
400
|
+
"format" => "complex",
|
|
401
|
+
"limit" => 1,
|
|
402
|
+
"attributes" => [
|
|
403
|
+
"title",
|
|
404
|
+
{
|
|
405
|
+
"label" => "snippet",
|
|
406
|
+
"source" => "snippet_html(title)",
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
},
|
|
410
|
+
},
|
|
411
|
+
},
|
|
412
|
+
}
|
|
413
|
+
assert_search(expected, request)
|
|
414
|
+
end
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
class FormatTest < self
|
|
418
|
+
def test_complex
|
|
419
|
+
request = {
|
|
420
|
+
"queries" => {
|
|
421
|
+
"sections-result" => {
|
|
422
|
+
"source" => "Sections",
|
|
423
|
+
"output" => {
|
|
424
|
+
"elements" => [
|
|
425
|
+
"records",
|
|
426
|
+
],
|
|
427
|
+
"format" => "complex",
|
|
428
|
+
"limit" => 3,
|
|
429
|
+
"attributes" => ["_key", "title"],
|
|
430
|
+
},
|
|
431
|
+
},
|
|
432
|
+
},
|
|
433
|
+
}
|
|
434
|
+
assert_search(complex_result, request)
|
|
435
|
+
end
|
|
436
|
+
|
|
437
|
+
def test_simple
|
|
438
|
+
request = {
|
|
439
|
+
"queries" => {
|
|
440
|
+
"sections-result" => {
|
|
441
|
+
"source" => "Sections",
|
|
442
|
+
"output" => {
|
|
443
|
+
"elements" => [
|
|
444
|
+
"records",
|
|
445
|
+
],
|
|
446
|
+
"format" => "simple",
|
|
447
|
+
"limit" => 3,
|
|
448
|
+
"attributes" => ["_key", "title"],
|
|
449
|
+
},
|
|
450
|
+
},
|
|
451
|
+
},
|
|
452
|
+
}
|
|
453
|
+
assert_search(simple_result, request)
|
|
454
|
+
end
|
|
455
|
+
|
|
456
|
+
def test_default
|
|
457
|
+
request = {
|
|
458
|
+
"queries" => {
|
|
459
|
+
"sections-result" => {
|
|
460
|
+
"source" => "Sections",
|
|
461
|
+
"output" => {
|
|
462
|
+
"elements" => [
|
|
463
|
+
"records",
|
|
464
|
+
],
|
|
465
|
+
"limit" => 3,
|
|
466
|
+
"attributes" => ["_key", "title"],
|
|
467
|
+
},
|
|
468
|
+
},
|
|
469
|
+
},
|
|
470
|
+
}
|
|
471
|
+
assert_search(simple_result, request)
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
def complex_result
|
|
475
|
+
{
|
|
476
|
+
"sections-result" => {
|
|
477
|
+
"records" => [
|
|
478
|
+
{
|
|
479
|
+
"_key" => "1.1",
|
|
480
|
+
"title" => "Groonga overview",
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
"_key" => "1.2",
|
|
484
|
+
"title" => "Full text search and Instant update",
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
"_key" => "1.3",
|
|
488
|
+
"title" => "Column store and aggregate query",
|
|
489
|
+
},
|
|
490
|
+
],
|
|
491
|
+
},
|
|
492
|
+
}
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
def simple_result
|
|
496
|
+
{
|
|
497
|
+
"sections-result" => {
|
|
498
|
+
"records" => [
|
|
499
|
+
["1.1", "Groonga overview"],
|
|
500
|
+
["1.2", "Full text search and Instant update"],
|
|
501
|
+
["1.3", "Column store and aggregate query"],
|
|
502
|
+
],
|
|
503
|
+
},
|
|
504
|
+
}
|
|
505
|
+
end
|
|
506
|
+
end
|
|
507
|
+
end
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
class ReferenceTest < self
|
|
511
|
+
class Hash
|
|
512
|
+
def setup
|
|
513
|
+
super
|
|
514
|
+
restore(fixture_data("reference/hash.grn"))
|
|
515
|
+
setup_plugin(Droonga::SearchHandler)
|
|
516
|
+
end
|
|
517
|
+
|
|
518
|
+
def test_reference_to_hash
|
|
519
|
+
expected = {
|
|
520
|
+
"sections-result" => {
|
|
521
|
+
"records" => [
|
|
522
|
+
{
|
|
523
|
+
"_key" => "1.1",
|
|
524
|
+
"document" => "Groonga",
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
"_key" => "1.2",
|
|
528
|
+
"document" => "Groonga",
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
"_key" => "1.3",
|
|
532
|
+
"document" => "Groonga",
|
|
533
|
+
},
|
|
534
|
+
],
|
|
535
|
+
},
|
|
536
|
+
}
|
|
537
|
+
request = {
|
|
538
|
+
"queries" => {
|
|
539
|
+
"sections-result" => {
|
|
540
|
+
"source" => "SectionsForHash",
|
|
541
|
+
"output" => {
|
|
542
|
+
"elements" => [
|
|
543
|
+
"records",
|
|
544
|
+
],
|
|
545
|
+
"format" => "complex",
|
|
546
|
+
"limit" => 3,
|
|
547
|
+
"attributes" => ["_key", "document"],
|
|
548
|
+
},
|
|
549
|
+
},
|
|
550
|
+
},
|
|
551
|
+
}
|
|
552
|
+
assert_search(expected, request)
|
|
553
|
+
end
|
|
554
|
+
end
|
|
555
|
+
|
|
556
|
+
class Array
|
|
557
|
+
def setup
|
|
558
|
+
super
|
|
559
|
+
restore(fixture_data("reference/array.grn"))
|
|
560
|
+
setup_plugin(Droonga::SearchHandler)
|
|
561
|
+
end
|
|
562
|
+
|
|
563
|
+
def test_reference_to_array
|
|
564
|
+
expected = {
|
|
565
|
+
"sections-result" => {
|
|
566
|
+
"records" => [
|
|
567
|
+
{
|
|
568
|
+
"_key" => "1.1",
|
|
569
|
+
"document" => 1,
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
"_key" => "1.2",
|
|
573
|
+
"document" => 1,
|
|
574
|
+
},
|
|
575
|
+
{
|
|
576
|
+
"_key" => "1.3",
|
|
577
|
+
"document" => 1,
|
|
578
|
+
},
|
|
579
|
+
],
|
|
580
|
+
},
|
|
581
|
+
}
|
|
582
|
+
request = {
|
|
583
|
+
"queries" => {
|
|
584
|
+
"sections-result" => {
|
|
585
|
+
"source" => "SectionsForArray",
|
|
586
|
+
"output" => {
|
|
587
|
+
"elements" => [
|
|
588
|
+
"records",
|
|
589
|
+
],
|
|
590
|
+
"format" => "complex",
|
|
591
|
+
"limit" => 3,
|
|
592
|
+
"attributes" => ["_key", "document"],
|
|
593
|
+
},
|
|
594
|
+
},
|
|
595
|
+
},
|
|
596
|
+
}
|
|
597
|
+
assert_search(expected, request)
|
|
598
|
+
end
|
|
599
|
+
end
|
|
600
|
+
end
|
|
601
|
+
end
|