groonga-command 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +21 -0
- data/README.md +47 -0
- data/Rakefile +44 -0
- data/doc/text/lgpl-2.1.txt +502 -0
- data/doc/text/news.md +5 -0
- data/groonga-command.gemspec +64 -0
- data/lib/groonga/command.rb +20 -0
- data/lib/groonga/command/base.rb +138 -0
- data/lib/groonga/command/column-create.rb +39 -0
- data/lib/groonga/command/column-remove.rb +36 -0
- data/lib/groonga/command/column-rename.rb +37 -0
- data/lib/groonga/command/delete.rb +38 -0
- data/lib/groonga/command/error.rb +24 -0
- data/lib/groonga/command/get.rb +39 -0
- data/lib/groonga/command/load.rb +56 -0
- data/lib/groonga/command/parser.rb +424 -0
- data/lib/groonga/command/select.rb +69 -0
- data/lib/groonga/command/suggest.rb +47 -0
- data/lib/groonga/command/table-create.rb +39 -0
- data/lib/groonga/command/table-remove.rb +35 -0
- data/lib/groonga/command/table-rename.rb +36 -0
- data/lib/groonga/command/truncate.rb +35 -0
- data/lib/groonga/command/version.rb +23 -0
- data/test/command/test-base.rb +114 -0
- data/test/command/test-column-create.rb +47 -0
- data/test/command/test-column-remove.rb +41 -0
- data/test/command/test-column-rename.rb +43 -0
- data/test/command/test-delete.rb +45 -0
- data/test/command/test-get.rb +44 -0
- data/test/command/test-load.rb +49 -0
- data/test/command/test-select.rb +60 -0
- data/test/command/test-suggest.rb +68 -0
- data/test/command/test-table-create.rb +48 -0
- data/test/command/test-table-remove.rb +39 -0
- data/test/command/test-table-rename.rb +41 -0
- data/test/command/test-truncate.rb +39 -0
- data/test/groonga-command-test-utils.rb +102 -0
- data/test/run-test.rb +39 -0
- data/test/test-parser.rb +353 -0
- metadata +237 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
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 as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
require "groonga/command/base"
|
20
|
+
|
21
|
+
module Groonga
|
22
|
+
module Command
|
23
|
+
class Select < Base
|
24
|
+
Command.register("select", self)
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def parameter_names
|
28
|
+
# TODO: Fill me
|
29
|
+
[
|
30
|
+
:table
|
31
|
+
]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def sortby
|
36
|
+
self[:sortby]
|
37
|
+
end
|
38
|
+
|
39
|
+
def scorer
|
40
|
+
self[:scorer]
|
41
|
+
end
|
42
|
+
|
43
|
+
def query
|
44
|
+
self[:query]
|
45
|
+
end
|
46
|
+
|
47
|
+
def filter
|
48
|
+
self[:filter]
|
49
|
+
end
|
50
|
+
|
51
|
+
def conditions
|
52
|
+
@conditions ||= filter.split(/(?:&&|&!|\|\|)/).collect do |condition|
|
53
|
+
condition = condition.strip
|
54
|
+
condition = condition.gsub(/\A[\s\(]*/, '')
|
55
|
+
condition = condition.gsub(/[\s\)]*\z/, '') unless /\(/ =~ condition
|
56
|
+
condition
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def drilldowns
|
61
|
+
@drilldowns ||= (self[:drilldown] || "").split(/\s*,\s*/)
|
62
|
+
end
|
63
|
+
|
64
|
+
def output_columns
|
65
|
+
self[:output_columns]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
|
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 as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
require "groonga/command/base"
|
20
|
+
|
21
|
+
module Groonga
|
22
|
+
module Command
|
23
|
+
class Suggest < Base
|
24
|
+
Command.register("suggest", self)
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def parameter_names
|
28
|
+
[
|
29
|
+
:types,
|
30
|
+
:table,
|
31
|
+
:column,
|
32
|
+
:query,
|
33
|
+
:sortby,
|
34
|
+
:output_columns,
|
35
|
+
:offset,
|
36
|
+
:limit,
|
37
|
+
:frequency_threshold,
|
38
|
+
:conditional_probability_threshold,
|
39
|
+
:prefix_search,
|
40
|
+
:similar_search
|
41
|
+
]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
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 as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
require "groonga/command/base"
|
20
|
+
|
21
|
+
module Groonga
|
22
|
+
module Command
|
23
|
+
class TableCreate < Base
|
24
|
+
Command.register("table_create", self)
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def parameter_names
|
28
|
+
[
|
29
|
+
:name,
|
30
|
+
:flags,
|
31
|
+
:key_type,
|
32
|
+
:value_type,
|
33
|
+
:default_tokenizer,
|
34
|
+
]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
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 as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
require "groonga/command/base"
|
20
|
+
|
21
|
+
module Groonga
|
22
|
+
module Command
|
23
|
+
class TableRemove < Base
|
24
|
+
Command.register("table_remove", self)
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def parameter_names
|
28
|
+
[
|
29
|
+
:name,
|
30
|
+
]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
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 as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
require "groonga/command/base"
|
20
|
+
|
21
|
+
module Groonga
|
22
|
+
module Command
|
23
|
+
class TableRename < Base
|
24
|
+
Command.register("table_rename", self)
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def parameter_names
|
28
|
+
[
|
29
|
+
:name,
|
30
|
+
:new_name,
|
31
|
+
]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
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 as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
require "groonga/command/base"
|
20
|
+
|
21
|
+
module Groonga
|
22
|
+
module Command
|
23
|
+
class Truncate < Base
|
24
|
+
Command.register("truncate", self)
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def parameter_names
|
28
|
+
[
|
29
|
+
:table,
|
30
|
+
]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
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 as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
module Groonga
|
20
|
+
module Command
|
21
|
+
VERSION = "1.0.0"
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2011-2012 Kouhei Sutou <kou@clear-code.com>
|
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 as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
class BaseCommandTest < Test::Unit::TestCase
|
20
|
+
class CovnertToURIFormatTest < self
|
21
|
+
def test_no_special_characters
|
22
|
+
select = Groonga::Command::Base.new("select",
|
23
|
+
:table => "Users",
|
24
|
+
:filter => "age<=30",
|
25
|
+
:output_type => "json")
|
26
|
+
assert_equal("/d/select.json?filter=age%3C%3D30&table=Users",
|
27
|
+
select.to_uri_format)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_double_quote
|
31
|
+
filter = 'geo_in_rectangle(location,' +
|
32
|
+
'"35.73360x139.7394","62614x139.7714") && ' +
|
33
|
+
'((type == "たいやき" || type == "和菓子")) && ' +
|
34
|
+
'keyword @ "たいやき" &! keyword @ "白" &! keyword @ "養殖"'
|
35
|
+
select = Groonga::Command::Base.new("select",
|
36
|
+
:table => "Users",
|
37
|
+
:filter => filter,
|
38
|
+
:output_type => "json")
|
39
|
+
assert_equal("/d/select.json?filter=geo_in_rectangle%28location%2C" +
|
40
|
+
"%2235.73360x139.7394%22%2C%2262614x139.7714%22%29+" +
|
41
|
+
"%26%26+%28%28type+" +
|
42
|
+
"%3D%3D+%22%E3%81%9F%E3%81%84%E3%82%84%E3%81%8D%22+" +
|
43
|
+
"%7C%7C+type+%3D%3D+" +
|
44
|
+
"%22%E5%92%8C%E8%8F%93%E5%AD%90%22%29%29+" +
|
45
|
+
"%26%26+keyword+%40+" +
|
46
|
+
"%22%E3%81%9F%E3%81%84%E3%82%84%E3%81%8D%22+%26%21+" +
|
47
|
+
"keyword+%40+%22%E7%99%BD%22+%26%21+" +
|
48
|
+
"keyword+%40+%22%E9%A4%8A%E6%AE%96%22&table=Users",
|
49
|
+
select.to_uri_format)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class CovnertToCommandFormatTest < self
|
54
|
+
def test_no_special_characters
|
55
|
+
select = Groonga::Command::Base.new("select",
|
56
|
+
:table => "Users",
|
57
|
+
:filter => "age<=30",
|
58
|
+
:output_type => "json")
|
59
|
+
assert_equal("select --filter \"age<=30\" " +
|
60
|
+
"--output_type \"json\" --table \"Users\"",
|
61
|
+
select.to_command_format)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_double_quote
|
65
|
+
filter = 'geo_in_rectangle(location,' +
|
66
|
+
'"35.73360x139.7394","62614x139.7714") && ' +
|
67
|
+
'((type == "たいやき" || type == "和菓子")) && ' +
|
68
|
+
'keyword @ "たいやき" &! keyword @ "白" &! keyword @ "養殖"'
|
69
|
+
select = Groonga::Command::Base.new("select",
|
70
|
+
:table => "Users",
|
71
|
+
:filter => filter,
|
72
|
+
:output_type => "json")
|
73
|
+
assert_equal("select " +
|
74
|
+
"--filter " +
|
75
|
+
"\"geo_in_rectangle(location," +
|
76
|
+
"\\\"35.73360x139.7394\\\",\\\"62614x139.7714\\\") && " +
|
77
|
+
"((type == \\\"たいやき\\\" || " +
|
78
|
+
"type == \\\"和菓子\\\")) && " +
|
79
|
+
"keyword @ \\\"たいやき\\\" &! keyword @ \\\"白\\\" &! " +
|
80
|
+
"keyword @ \\\"養殖\\\"\" " +
|
81
|
+
"--output_type \"json\" --table \"Users\"",
|
82
|
+
select.to_command_format)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
sub_test_case("#[]") do
|
87
|
+
def setup
|
88
|
+
@table = "Users"
|
89
|
+
@select = Groonga::Command::Base.new("select", :table => @table)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_symbol
|
93
|
+
assert_equal(@table, @select[:table])
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_string
|
97
|
+
assert_equal(@table, @select["table"])
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
sub_test_case("#has_key?") do
|
102
|
+
def setup
|
103
|
+
@select = Groonga::Command::Base.new("select", :table => "Users")
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_symbol
|
107
|
+
assert_true(@select.has_key?(:table))
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_string
|
111
|
+
assert_true(@select.has_key?("table"))
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
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 as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
class ColumnCreateCommandTest < Test::Unit::TestCase
|
20
|
+
class CommandLineTest < self
|
21
|
+
include GroongaCommandTestUtils::CommandLineCommandParser
|
22
|
+
|
23
|
+
def test_ordered_arguments
|
24
|
+
table = "Lexicon"
|
25
|
+
name = "content_index"
|
26
|
+
flags = "COLUMN_INDEX"
|
27
|
+
type = "Posts"
|
28
|
+
source = "content"
|
29
|
+
|
30
|
+
command = parse(table, name, flags, type, source)
|
31
|
+
assert_instance_of(Groonga::Command::ColumnCreate, command)
|
32
|
+
assert_equal({
|
33
|
+
:table => table,
|
34
|
+
:name => name,
|
35
|
+
:flags => flags,
|
36
|
+
:type => type,
|
37
|
+
:source => source,
|
38
|
+
},
|
39
|
+
command.arguments)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def parse(*arguments)
|
44
|
+
super("column_create", arguments, :output_type => false)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|