groonga-command 1.0.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.
Files changed (40) hide show
  1. data/Gemfile +21 -0
  2. data/README.md +47 -0
  3. data/Rakefile +44 -0
  4. data/doc/text/lgpl-2.1.txt +502 -0
  5. data/doc/text/news.md +5 -0
  6. data/groonga-command.gemspec +64 -0
  7. data/lib/groonga/command.rb +20 -0
  8. data/lib/groonga/command/base.rb +138 -0
  9. data/lib/groonga/command/column-create.rb +39 -0
  10. data/lib/groonga/command/column-remove.rb +36 -0
  11. data/lib/groonga/command/column-rename.rb +37 -0
  12. data/lib/groonga/command/delete.rb +38 -0
  13. data/lib/groonga/command/error.rb +24 -0
  14. data/lib/groonga/command/get.rb +39 -0
  15. data/lib/groonga/command/load.rb +56 -0
  16. data/lib/groonga/command/parser.rb +424 -0
  17. data/lib/groonga/command/select.rb +69 -0
  18. data/lib/groonga/command/suggest.rb +47 -0
  19. data/lib/groonga/command/table-create.rb +39 -0
  20. data/lib/groonga/command/table-remove.rb +35 -0
  21. data/lib/groonga/command/table-rename.rb +36 -0
  22. data/lib/groonga/command/truncate.rb +35 -0
  23. data/lib/groonga/command/version.rb +23 -0
  24. data/test/command/test-base.rb +114 -0
  25. data/test/command/test-column-create.rb +47 -0
  26. data/test/command/test-column-remove.rb +41 -0
  27. data/test/command/test-column-rename.rb +43 -0
  28. data/test/command/test-delete.rb +45 -0
  29. data/test/command/test-get.rb +44 -0
  30. data/test/command/test-load.rb +49 -0
  31. data/test/command/test-select.rb +60 -0
  32. data/test/command/test-suggest.rb +68 -0
  33. data/test/command/test-table-create.rb +48 -0
  34. data/test/command/test-table-remove.rb +39 -0
  35. data/test/command/test-table-rename.rb +41 -0
  36. data/test/command/test-truncate.rb +39 -0
  37. data/test/groonga-command-test-utils.rb +102 -0
  38. data/test/run-test.rb +39 -0
  39. data/test/test-parser.rb +353 -0
  40. metadata +237 -0
@@ -0,0 +1,41 @@
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 ColumnRemoveCommandTest < Test::Unit::TestCase
20
+ class CommandLineTest < self
21
+ include GroongaCommandTestUtils::CommandLineCommandParser
22
+
23
+ def test_ordered_arguments
24
+ table = "Users"
25
+ name = "age"
26
+
27
+ command = parse(table, name)
28
+ assert_instance_of(Groonga::Command::ColumnRemove, command)
29
+ assert_equal({
30
+ :table => table,
31
+ :name => name,
32
+ },
33
+ command.arguments)
34
+ end
35
+
36
+ private
37
+ def parse(*arguments)
38
+ super("column_remove", arguments, :output_type => false)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,43 @@
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 ColumnRenameCommandTest < Test::Unit::TestCase
20
+ class CommandLineTest < self
21
+ include GroongaCommandTestUtils::CommandLineCommandParser
22
+
23
+ def test_ordered_arguments
24
+ table = "Users"
25
+ name = "name"
26
+ new_name = "nick"
27
+
28
+ command = parse(table, name, new_name)
29
+ assert_instance_of(Groonga::Command::ColumnRename, command)
30
+ assert_equal({
31
+ :table => table,
32
+ :name => name,
33
+ :new_name => new_name,
34
+ },
35
+ command.arguments)
36
+ end
37
+
38
+ private
39
+ def parse(*arguments)
40
+ super("column_rename", arguments, :output_type => false)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,45 @@
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 DeleteCommandTest < Test::Unit::TestCase
20
+ class CommandLineTest < self
21
+ include GroongaCommandTestUtils::CommandLineCommandParser
22
+
23
+ def test_ordered_arguments
24
+ table = "Users"
25
+ key = "Alice"
26
+ id = "29"
27
+ filter = "age == 20"
28
+
29
+ command = parse(table, key, id, filter)
30
+ assert_instance_of(Groonga::Command::Delete, command)
31
+ assert_equal({
32
+ :table => table,
33
+ :key => key,
34
+ :id => id,
35
+ :filter => filter,
36
+ },
37
+ command.arguments)
38
+ end
39
+
40
+ private
41
+ def parse(*arguments)
42
+ super("delete", arguments, :output_type => false)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,44 @@
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
+ class GetCommandTest < Test::Unit::TestCase
20
+ class CommandLineTest < self
21
+ include GroongaCommandTestUtils::CommandLineCommandParser
22
+
23
+ def test_ordered_arguments
24
+ table = "Users"
25
+ key = "Alice"
26
+ output_columns = "name, address"
27
+
28
+ command = parse(table, key, output_columns)
29
+ assert_instance_of(Groonga::Command::Get, command)
30
+
31
+ expected_arguments = {
32
+ :table => table,
33
+ :key => key,
34
+ :output_columns => output_columns,
35
+ }
36
+ assert_equal(expected_arguments, command.arguments)
37
+ end
38
+
39
+ private
40
+ def parse(*arguments)
41
+ super("get", arguments, :output_type => false)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,49 @@
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 LoadCommandTest < Test::Unit::TestCase
20
+ class CommandLineTest < self
21
+ include GroongaCommandTestUtils::CommandLineCommandParser
22
+
23
+ def test_ordered_arguments
24
+ values = "[[\"Alice\"], [\"Bob\"]]"
25
+ table = "Users"
26
+ columns = "_key"
27
+ ifexists = "_key == \"Alice\""
28
+ input_type = "json"
29
+ each = "strlen(_key)"
30
+
31
+ command = parse(values, table, columns, ifexists, input_type, each)
32
+ assert_instance_of(Groonga::Command::Load, command)
33
+ assert_equal({
34
+ :values => values,
35
+ :table => table,
36
+ :columns => columns,
37
+ :ifexists => ifexists,
38
+ :input_type => input_type,
39
+ :each => each,
40
+ },
41
+ command.arguments)
42
+ end
43
+
44
+ private
45
+ def parse(*arguments)
46
+ super("load", arguments, :output_type => false)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,60 @@
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 SelectCommandTest < Test::Unit::TestCase
20
+ include GroongaCommandTestUtils::CommandLineCommandParser
21
+
22
+ def test_ordered_argument
23
+ table = "Users"
24
+ command = parse("select", [table], :output_type => false)
25
+
26
+ assert_instance_of(Groonga::Command::Select, command)
27
+ assert_equal({:table => table}, command.arguments)
28
+ end
29
+
30
+ def test_scorer
31
+ select = command(:table => "Users",
32
+ :filter => "age<=30",
33
+ :scorer => "_score = random()")
34
+ assert_equal("_score = random()", select.scorer)
35
+ end
36
+
37
+ private
38
+ def command(arguments)
39
+ Groonga::Command::Select.new("select", arguments)
40
+ end
41
+
42
+ class FilterTest < self
43
+ def test_parenthesis
44
+ filter = 'geo_in_rectangle(location,' +
45
+ '"35.73360x139.7394","62614x139.7714") && ' +
46
+ '((type == "たいやき" || type == "和菓子")) && ' +
47
+ 'keyword @ "たいやき" &! keyword @ "白" &! keyword @ "養殖"'
48
+ select = command(:table => "Users",
49
+ :filter => filter)
50
+ assert_equal(['geo_in_rectangle(location,' +
51
+ '"35.73360x139.7394","62614x139.7714")',
52
+ 'type == "たいやき"',
53
+ 'type == "和菓子"',
54
+ 'keyword @ "たいやき"',
55
+ 'keyword @ "白"',
56
+ 'keyword @ "養殖"'],
57
+ select.conditions)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,68 @@
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
+ class SuggestCommandTest < Test::Unit::TestCase
20
+ class CommandLineTest < self
21
+ include GroongaCommandTestUtils::CommandLineCommandParser
22
+
23
+ def test_ordered_arguments
24
+ types = "complete"
25
+ table = "Users"
26
+ column = "name"
27
+ query = "name:@ Ali"
28
+ sortby = "_score"
29
+ output_columns = "name"
30
+ offset = "0"
31
+ limit = "5"
32
+ frequency_threshold = "120"
33
+ conditional_probability_threshold = "0.3"
34
+ prefix_search = "yes"
35
+ similar_search = "yes"
36
+
37
+ arguments = [
38
+ types, table, column, query, sortby, output_columns,
39
+ offset, limit, frequency_threshold,
40
+ conditional_probability_threshold,
41
+ prefix_search, similar_search
42
+ ]
43
+ command = parse(*arguments)
44
+ assert_instance_of(Groonga::Command::Suggest, command)
45
+
46
+ expected_arguments = {
47
+ :types => types,
48
+ :table => table,
49
+ :column => column,
50
+ :query => query,
51
+ :sortby => sortby,
52
+ :output_columns => output_columns,
53
+ :offset => offset,
54
+ :limit => limit,
55
+ :frequency_threshold => frequency_threshold,
56
+ :conditional_probability_threshold => conditional_probability_threshold,
57
+ :prefix_search => prefix_search,
58
+ :similar_search => similar_search
59
+ }
60
+ assert_equal(expected_arguments, command.arguments)
61
+ end
62
+
63
+ private
64
+ def parse(*arguments)
65
+ super("suggest", arguments, :output_type => false)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,48 @@
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 TableCreateCommandTest < Test::Unit::TestCase
20
+ class CommandLineTest < self
21
+ include GroongaCommandTestUtils::CommandLineCommandParser
22
+
23
+ def test_ordered_arguments
24
+ name = "Users"
25
+ flags = "TABLE_PAT_KEY"
26
+ key_type = "ShortText"
27
+ value_type = "UInt32"
28
+ default_tokenizer = "TokenBigram"
29
+
30
+ command = parse(name, flags, key_type, value_type,
31
+ default_tokenizer)
32
+ assert_instance_of(Groonga::Command::TableCreate, command)
33
+ assert_equal({
34
+ :name => name,
35
+ :flags => flags,
36
+ :key_type => key_type,
37
+ :value_type => value_type,
38
+ :default_tokenizer => default_tokenizer,
39
+ },
40
+ command.arguments)
41
+ end
42
+
43
+ private
44
+ def parse(*arguments)
45
+ super("table_create", arguments, :output_type => false)
46
+ end
47
+ end
48
+ end
@@ -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
+ class TableRemoveCommandTest < Test::Unit::TestCase
20
+ class CommandLineTest < self
21
+ include GroongaCommandTestUtils::CommandLineCommandParser
22
+
23
+ def test_ordered_arguments
24
+ name = "Users"
25
+
26
+ command = parse(name)
27
+ assert_instance_of(Groonga::Command::TableRemove, command)
28
+ assert_equal({
29
+ :name => name,
30
+ },
31
+ command.arguments)
32
+ end
33
+
34
+ private
35
+ def parse(*arguments)
36
+ super("table_remove", arguments, :output_type => false)
37
+ end
38
+ end
39
+ end