groonga 0.9.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. metadata +38 -227
  2. data/AUTHORS +0 -5
  3. data/NEWS.ja.rdoc +0 -114
  4. data/NEWS.rdoc +0 -116
  5. data/README.ja.rdoc +0 -63
  6. data/README.rdoc +0 -64
  7. data/Rakefile +0 -216
  8. data/benchmark/common.rb +0 -49
  9. data/benchmark/read-write-many-small-items.rb +0 -144
  10. data/benchmark/write-many-small-items.rb +0 -135
  11. data/example/bookmark.rb +0 -161
  12. data/example/index-html.rb +0 -89
  13. data/example/search/config.ru +0 -211
  14. data/example/search/public/css/groonga.css +0 -122
  15. data/ext/.gitignore +0 -2
  16. data/ext/rb-grn-accessor.c +0 -52
  17. data/ext/rb-grn-array-cursor.c +0 -36
  18. data/ext/rb-grn-array.c +0 -210
  19. data/ext/rb-grn-column.c +0 -570
  20. data/ext/rb-grn-context.c +0 -655
  21. data/ext/rb-grn-database.c +0 -415
  22. data/ext/rb-grn-encoding-support.c +0 -64
  23. data/ext/rb-grn-encoding.c +0 -257
  24. data/ext/rb-grn-exception.c +0 -1110
  25. data/ext/rb-grn-expression-builder.c +0 -75
  26. data/ext/rb-grn-expression.c +0 -732
  27. data/ext/rb-grn-fix-size-column.c +0 -166
  28. data/ext/rb-grn-hash-cursor.c +0 -38
  29. data/ext/rb-grn-hash.c +0 -294
  30. data/ext/rb-grn-index-column.c +0 -488
  31. data/ext/rb-grn-logger.c +0 -325
  32. data/ext/rb-grn-object.c +0 -1335
  33. data/ext/rb-grn-operation.c +0 -198
  34. data/ext/rb-grn-patricia-trie-cursor.c +0 -39
  35. data/ext/rb-grn-patricia-trie.c +0 -488
  36. data/ext/rb-grn-procedure.c +0 -52
  37. data/ext/rb-grn-query.c +0 -260
  38. data/ext/rb-grn-record.c +0 -40
  39. data/ext/rb-grn-snippet.c +0 -328
  40. data/ext/rb-grn-table-cursor-key-support.c +0 -69
  41. data/ext/rb-grn-table-cursor.c +0 -246
  42. data/ext/rb-grn-table-key-support.c +0 -731
  43. data/ext/rb-grn-table.c +0 -2038
  44. data/ext/rb-grn-type.c +0 -181
  45. data/ext/rb-grn-utils.c +0 -769
  46. data/ext/rb-grn-variable-size-column.c +0 -36
  47. data/ext/rb-grn-variable.c +0 -108
  48. data/ext/rb-grn.h +0 -684
  49. data/ext/rb-groonga.c +0 -113
  50. data/extconf.rb +0 -216
  51. data/html/bar.svg +0 -153
  52. data/html/developer.html +0 -121
  53. data/html/developer.svg +0 -469
  54. data/html/download.svg +0 -253
  55. data/html/favicon.ico +0 -0
  56. data/html/favicon.xcf +0 -0
  57. data/html/footer.html.erb +0 -28
  58. data/html/head.html.erb +0 -4
  59. data/html/header.html.erb +0 -17
  60. data/html/index.html +0 -147
  61. data/html/install.svg +0 -636
  62. data/html/logo.xcf +0 -0
  63. data/html/ranguba.css +0 -248
  64. data/html/tutorial.svg +0 -559
  65. data/lib/groonga.rb +0 -83
  66. data/lib/groonga/expression-builder.rb +0 -285
  67. data/lib/groonga/patricia-trie.rb +0 -53
  68. data/lib/groonga/record.rb +0 -276
  69. data/lib/groonga/schema.rb +0 -916
  70. data/license/GPL +0 -340
  71. data/license/LGPL +0 -504
  72. data/license/RUBY +0 -59
  73. data/misc/grnop2ruby.rb +0 -49
  74. data/pkg-config.rb +0 -333
  75. data/src/rb-grn-table-cursor.c +0 -296
  76. data/test-unit/Rakefile +0 -40
  77. data/test-unit/TODO +0 -5
  78. data/test-unit/bin/testrb +0 -5
  79. data/test-unit/html/classic.html +0 -15
  80. data/test-unit/html/index.html +0 -25
  81. data/test-unit/html/index.html.ja +0 -27
  82. data/test-unit/lib/test/unit.rb +0 -323
  83. data/test-unit/lib/test/unit/assertionfailederror.rb +0 -25
  84. data/test-unit/lib/test/unit/assertions.rb +0 -1230
  85. data/test-unit/lib/test/unit/attribute.rb +0 -125
  86. data/test-unit/lib/test/unit/autorunner.rb +0 -353
  87. data/test-unit/lib/test/unit/collector.rb +0 -36
  88. data/test-unit/lib/test/unit/collector/descendant.rb +0 -23
  89. data/test-unit/lib/test/unit/collector/dir.rb +0 -108
  90. data/test-unit/lib/test/unit/collector/load.rb +0 -136
  91. data/test-unit/lib/test/unit/collector/objectspace.rb +0 -34
  92. data/test-unit/lib/test/unit/color-scheme.rb +0 -102
  93. data/test-unit/lib/test/unit/color.rb +0 -96
  94. data/test-unit/lib/test/unit/diff.rb +0 -724
  95. data/test-unit/lib/test/unit/error.rb +0 -130
  96. data/test-unit/lib/test/unit/exceptionhandler.rb +0 -39
  97. data/test-unit/lib/test/unit/failure.rb +0 -136
  98. data/test-unit/lib/test/unit/fixture.rb +0 -176
  99. data/test-unit/lib/test/unit/notification.rb +0 -129
  100. data/test-unit/lib/test/unit/omission.rb +0 -191
  101. data/test-unit/lib/test/unit/pending.rb +0 -150
  102. data/test-unit/lib/test/unit/priority.rb +0 -181
  103. data/test-unit/lib/test/unit/runner/console.rb +0 -52
  104. data/test-unit/lib/test/unit/runner/emacs.rb +0 -8
  105. data/test-unit/lib/test/unit/runner/tap.rb +0 -8
  106. data/test-unit/lib/test/unit/testcase.rb +0 -476
  107. data/test-unit/lib/test/unit/testresult.rb +0 -89
  108. data/test-unit/lib/test/unit/testsuite.rb +0 -110
  109. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +0 -14
  110. data/test-unit/lib/test/unit/ui/console/testrunner.rb +0 -464
  111. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +0 -63
  112. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +0 -92
  113. data/test-unit/lib/test/unit/ui/testrunner.rb +0 -28
  114. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +0 -77
  115. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +0 -41
  116. data/test-unit/lib/test/unit/util/backtracefilter.rb +0 -41
  117. data/test-unit/lib/test/unit/util/method-owner-finder.rb +0 -28
  118. data/test-unit/lib/test/unit/util/observable.rb +0 -90
  119. data/test-unit/lib/test/unit/util/procwrapper.rb +0 -48
  120. data/test-unit/lib/test/unit/version.rb +0 -7
  121. data/test-unit/sample/adder.rb +0 -13
  122. data/test-unit/sample/subtracter.rb +0 -12
  123. data/test-unit/sample/test_adder.rb +0 -20
  124. data/test-unit/sample/test_subtracter.rb +0 -20
  125. data/test-unit/sample/test_user.rb +0 -23
  126. data/test-unit/test/collector/test-descendant.rb +0 -133
  127. data/test-unit/test/collector/test-load.rb +0 -329
  128. data/test-unit/test/collector/test_dir.rb +0 -406
  129. data/test-unit/test/collector/test_objectspace.rb +0 -100
  130. data/test-unit/test/run-test.rb +0 -15
  131. data/test-unit/test/test-attribute.rb +0 -86
  132. data/test-unit/test/test-color-scheme.rb +0 -67
  133. data/test-unit/test/test-color.rb +0 -47
  134. data/test-unit/test/test-diff.rb +0 -518
  135. data/test-unit/test/test-emacs-runner.rb +0 -60
  136. data/test-unit/test/test-fixture.rb +0 -287
  137. data/test-unit/test/test-notification.rb +0 -33
  138. data/test-unit/test/test-omission.rb +0 -81
  139. data/test-unit/test/test-pending.rb +0 -70
  140. data/test-unit/test/test-priority.rb +0 -119
  141. data/test-unit/test/test-testcase.rb +0 -554
  142. data/test-unit/test/test_assertions.rb +0 -1151
  143. data/test-unit/test/test_error.rb +0 -26
  144. data/test-unit/test/test_failure.rb +0 -33
  145. data/test-unit/test/test_testresult.rb +0 -113
  146. data/test-unit/test/test_testsuite.rb +0 -129
  147. data/test-unit/test/testunit-test-util.rb +0 -14
  148. data/test-unit/test/ui/test_testrunmediator.rb +0 -20
  149. data/test-unit/test/util/test-method-owner-finder.rb +0 -38
  150. data/test-unit/test/util/test_backtracefilter.rb +0 -41
  151. data/test-unit/test/util/test_observable.rb +0 -102
  152. data/test-unit/test/util/test_procwrapper.rb +0 -36
  153. data/test/.gitignore +0 -1
  154. data/test/groonga-test-utils.rb +0 -106
  155. data/test/run-test.rb +0 -58
  156. data/test/test-array.rb +0 -97
  157. data/test/test-column.rb +0 -298
  158. data/test/test-context.rb +0 -73
  159. data/test/test-database.rb +0 -113
  160. data/test/test-encoding.rb +0 -33
  161. data/test/test-exception.rb +0 -93
  162. data/test/test-expression-builder.rb +0 -156
  163. data/test/test-expression.rb +0 -133
  164. data/test/test-fix-size-column.rb +0 -65
  165. data/test/test-gqtp.rb +0 -70
  166. data/test/test-hash.rb +0 -312
  167. data/test/test-index-column.rb +0 -81
  168. data/test/test-patricia-trie.rb +0 -189
  169. data/test/test-procedure.rb +0 -37
  170. data/test/test-query.rb +0 -22
  171. data/test/test-record.rb +0 -268
  172. data/test/test-remote.rb +0 -53
  173. data/test/test-schema.rb +0 -416
  174. data/test/test-snippet.rb +0 -121
  175. data/test/test-table-cursor.rb +0 -153
  176. data/test/test-table-offset-and-limit.rb +0 -102
  177. data/test/test-table-select-normalize.rb +0 -48
  178. data/test/test-table-select.rb +0 -145
  179. data/test/test-table.rb +0 -642
  180. data/test/test-type.rb +0 -61
  181. data/test/test-variable-size-column.rb +0 -98
  182. data/test/test-variable.rb +0 -28
  183. data/test/test-vector-column.rb +0 -76
  184. data/test/test-version.rb +0 -31
  185. data/text/TUTORIAL.ja.rdoc +0 -392
  186. data/text/expression.rdoc +0 -284
@@ -1,36 +0,0 @@
1
- # Author:: Nathaniel Talbott.
2
- # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
3
- # License:: Ruby license.
4
-
5
- require 'test/unit'
6
- require 'test/unit/util/procwrapper'
7
-
8
- module Test
9
- module Unit
10
- module Util
11
- class TC_ProcWrapper < TestCase
12
- def munge_proc(&a_proc)
13
- return a_proc
14
- end
15
- def setup
16
- @original = proc {}
17
- @munged = munge_proc(&@original)
18
- @wrapped_original = ProcWrapper.new(@original)
19
- @wrapped_munged = ProcWrapper.new(@munged)
20
- end
21
- def test_wrapping
22
- assert_same(@original, @wrapped_original.to_proc, "The wrapper should return what was wrapped")
23
- end
24
- def test_hashing
25
-
26
- assert_equal(@wrapped_original.hash, @wrapped_munged.hash, "The original and munged should have the same hash when wrapped")
27
- assert_equal(@wrapped_original, @wrapped_munged, "The wrappers should be equivalent")
28
-
29
- a_hash = {@wrapped_original => @original}
30
- assert(a_hash[@wrapped_original], "Should be able to access the wrapper in the hash")
31
- assert_equal(a_hash[@wrapped_original], @original, "Should be able to access the wrapper in the hash")
32
- end
33
- end
34
- end
35
- end
36
- end
data/test/.gitignore DELETED
@@ -1 +0,0 @@
1
- /.test-result
@@ -1,106 +0,0 @@
1
- # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
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 'fileutils'
17
- require 'pathname'
18
- require 'time'
19
- begin
20
- require 'json'
21
- rescue LoadError
22
- require 'rubygems'
23
- require 'json'
24
- end
25
- require 'pkg-config'
26
-
27
- require 'groonga'
28
-
29
- module GroongaTestUtils
30
- class << self
31
- def included(base)
32
- base.setup :setup_sandbox, :before => :prepend
33
- base.teardown :teardown_sandbox, :after => :append
34
- end
35
- end
36
-
37
- def setup_sandbox
38
- setup_tmp_directory
39
- setup_tables_directory
40
- setup_columns_directory
41
-
42
- setup_encoding
43
- setup_context
44
- end
45
-
46
- def setup_tmp_directory
47
- @tmp_dir = Pathname(File.dirname(__FILE__)) + "tmp"
48
- FileUtils.rm_rf(@tmp_dir.to_s)
49
- FileUtils.mkdir_p(@tmp_dir.to_s)
50
- end
51
-
52
- def setup_tables_directory
53
- @tables_dir = @tmp_dir + "tables"
54
- FileUtils.mkdir_p(@tables_dir.to_s)
55
- end
56
-
57
- def setup_columns_directory
58
- @columns_dir = @tmp_dir + "columns"
59
- FileUtils.mkdir_p(@columns_dir.to_s)
60
- end
61
-
62
- def setup_encoding
63
- Groonga::Encoding.default = nil
64
- end
65
-
66
- def setup_context
67
- Groonga::Context.default = nil
68
- Groonga::Context.default_options = nil
69
- end
70
-
71
- def context
72
- Groonga::Context.default
73
- end
74
-
75
- def encoding
76
- Groonga::Encoding.default
77
- end
78
-
79
- def setup_logger
80
- Groonga::Logger.register(:level => :dump) do |level, time, title, message, location|
81
- p [level, time, title, message, location]
82
- end
83
- end
84
-
85
- def setup_database
86
- @database_path = @tmp_dir + "database"
87
- @database = Groonga::Database.create(:path => @database_path.to_s)
88
- end
89
-
90
- def teardown_sandbox
91
- @database = nil
92
- GC.start
93
- teardown_tmp_directory
94
- end
95
-
96
- def teardown_tmp_directory
97
- FileUtils.rm_rf(@tmp_dir.to_s)
98
- end
99
-
100
- private
101
- def assert_equal_select_result(expected, actual)
102
- assert_equal(expected,
103
- actual.collect {|record| record.key},
104
- actual.expression.inspect)
105
- end
106
- end
data/test/run-test.rb DELETED
@@ -1,58 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Copyright (C) 2009 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 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
- $VERBOSE = true
19
-
20
- $KCODE = "u" if RUBY_VERSION < "1.9"
21
-
22
- base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
23
- test_unit_dir = File.join(base_dir, "test-unit", "lib")
24
- ext_dir = File.join(base_dir, "ext")
25
- lib_dir = File.join(base_dir, "lib")
26
- test_dir = File.join(base_dir, "test")
27
-
28
- make = nil
29
- if system("which gmake > /dev/null")
30
- make = "gmake"
31
- elsif system("which make > /dev/null")
32
- make = "make"
33
- end
34
- if make
35
- system("cd #{base_dir.dump} && #{make} > /dev/null") or exit(1)
36
- end
37
-
38
- $LOAD_PATH.unshift(test_unit_dir)
39
-
40
- require 'test/unit'
41
-
42
- ARGV.unshift("--priority-mode")
43
-
44
- $LOAD_PATH.unshift(ext_dir)
45
- $LOAD_PATH.unshift(lib_dir)
46
- $LOAD_PATH.unshift(base_dir)
47
-
48
- $LOAD_PATH.unshift(test_dir)
49
- require 'groonga-test-utils'
50
-
51
- pkg_config = File.join(base_dir, "vendor", "local", "lib", "pkgconfig")
52
- PackageConfig.prepend_default_path(pkg_config)
53
-
54
- Dir.glob("#{base_dir}/test/**/test{_,-}*.rb") do |file|
55
- require file.sub(/\.rb$/, '')
56
- end
57
-
58
- exit Test::Unit::AutoRunner.run(false)
data/test/test-array.rb DELETED
@@ -1,97 +0,0 @@
1
- # Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
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
- class ArrayTest < Test::Unit::TestCase
17
- include GroongaTestUtils
18
-
19
- setup :setup_database
20
-
21
- def test_inspect_size
22
- path = @tables_dir + "named.groonga"
23
- contain_table = Groonga::Array.create(:name => "name", :path => path.to_s)
24
- 3.times do
25
- contain_table.add
26
- end
27
- assert_equal("#<Groonga::Array " +
28
- "id: <#{contain_table.id}>, " +
29
- "name: <name>, " +
30
- "path: <#{path}>, " +
31
- "domain: (nil), " +
32
- "range: (nil), " +
33
- "flags: <>, " +
34
- "size: <3>>",
35
- contain_table.inspect)
36
- end
37
-
38
- def test_encoding
39
- array = Groonga::Array.create
40
- assert_false(array.respond_to?(:encoding))
41
- end
42
-
43
- def test_add
44
- users = Groonga::Array.create(:name => "Users")
45
- users.define_column("name", "Text")
46
- me = users.add(:name => "me")
47
- assert_equal("me", me[:name])
48
- end
49
-
50
- def test_define_index_column
51
- users = Groonga::Array.create(:name => "Users")
52
- users.define_column("name", "Text")
53
- bookmarks = Groonga::Array.create(:name => "Bookmarks")
54
- bookmarks.define_column("title", "Text")
55
- bookmarks.define_column("user", users)
56
-
57
- index = users.define_index_column("bookmarks", bookmarks,
58
- :source => "Bookmarks.user")
59
- morita = users.add(:name => "morita")
60
- gunyara_kun = users.add(:name => "gunyara-kun")
61
- groonga = bookmarks.add(:title => "groonga", :user => morita)
62
- google = bookmarks.add(:title => "google", :user => morita)
63
- python = bookmarks.add(:title => "Python", :user => gunyara_kun)
64
-
65
- assert_equal(["groonga", "google"],
66
- index.search(morita.id).collect {|record| record.key["title"]})
67
- end
68
-
69
- def test_create_duplicated_name
70
- Groonga::Array.create(:name => "Users")
71
- assert_raise(Groonga::InvalidArgument) do
72
- Groonga::Array.create(:name => "Users")
73
- end
74
- end
75
-
76
- def test_open_same_name
77
- users_created = Groonga::Array.create(:name => "Users")
78
- users_opened = Groonga::Array.open(:name => "Users")
79
- users_opened.add
80
- assert_equal(1, users_created.size)
81
- end
82
-
83
- def test_value
84
- users = Groonga::Array.create(:value_type => "Int32")
85
- user_id = users.add.id
86
- users.set_value(user_id, 29)
87
- assert_equal(29, users.value(user_id))
88
- end
89
-
90
- def test_column_value
91
- users = Groonga::Array.create(:name => "Users")
92
- name = users.define_column("name", "ShortText")
93
- morita_id = users.add.id
94
- users.set_column_value(morita_id, "name", "morita")
95
- assert_equal("morita", users.column_value(morita_id, "name"))
96
- end
97
- end
data/test/test-column.rb DELETED
@@ -1,298 +0,0 @@
1
- # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
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
- class ColumnTest < Test::Unit::TestCase
17
- include GroongaTestUtils
18
-
19
- def setup
20
- setup_database
21
-
22
- setup_users_table
23
- setup_bookmarks_table
24
- setup_indexes
25
- end
26
-
27
- def setup_users_table
28
- @users_path = @tables_dir + "users"
29
- @users = Groonga::Array.create(:name => "Users",
30
- :path => @users_path.to_s)
31
-
32
- @users_name_column_path = @columns_dir + "name"
33
- @users_name_column =
34
- @users.define_column("name", "ShortText",
35
- :path => @users_name_column_path.to_s)
36
- end
37
-
38
- def setup_bookmarks_table
39
- @bookmarks_path = @tables_dir + "bookmarks"
40
- @bookmarks = Groonga::Array.create(:name => "Bookmarks",
41
- :path => @bookmarks_path.to_s)
42
-
43
- @uri_column_path = @columns_dir + "uri"
44
- @bookmarks_uri = @bookmarks.define_column("uri", "ShortText",
45
- :path => @uri_column_path.to_s)
46
-
47
- @comment_column_path = @columns_dir + "comment"
48
- @bookmarks_comment =
49
- @bookmarks.define_column("comment", "Text",
50
- :path => @comment_column_path.to_s)
51
-
52
- @content_column_path = @columns_dir + "content"
53
- @bookmarks_content = @bookmarks.define_column("content", "LongText")
54
-
55
- @user_column_path = @columns_dir + "user"
56
- @bookmarks_user = @bookmarks.define_column("user", @users)
57
- end
58
-
59
- def setup_indexes
60
- @bookmarks_index_path = @tables_dir + "bookmarks-index"
61
- @bookmarks_index =
62
- Groonga::PatriciaTrie.create(:name => "bookmarks-index",
63
- :path => @bookmarks_index_path.to_s,
64
- :key_type => "ShortText")
65
- @bookmarks_index.default_tokenizer = "TokenBigram"
66
-
67
- @content_index_column_path = @columns_dir + "content-index"
68
- @bookmarks_index_content =
69
- @bookmarks_index.define_index_column("content", @bookmarks,
70
- :with_section => true,
71
- :with_weight => true,
72
- :with_position => true,
73
- :path => @content_index_column_path.to_s)
74
-
75
- @uri_index_column_path = @columns_dir + "uri-index"
76
- @bookmarks_index_uri =
77
- @bookmarks_index.define_index_column("uri", @bookmarks,
78
- :path => @uri_index_column_path.to_s)
79
- end
80
-
81
- def test_source_info
82
- @bookmarks_index_content.sources = [@bookmarks_content]
83
-
84
- groonga = @bookmarks.add
85
- groonga["content"] = "<html><body>groonga</body></html>"
86
-
87
- ruby = @bookmarks.add
88
- ruby["content"] = "<html><body>ruby</body></html>"
89
-
90
- assert_content_search([groonga], "groonga")
91
- assert_content_search([groonga, ruby], "html")
92
-
93
- assert_equal([@bookmarks_content], @bookmarks_index_content.sources)
94
- end
95
-
96
- def test_update_index_column
97
- groonga = @bookmarks.add
98
- groonga["content"] = "<html><body>groonga</body></html>"
99
-
100
- ruby = @bookmarks.add
101
- ruby["content"] = "<html><body>ruby</body></html>"
102
-
103
- @bookmarks_index_content[groonga.id] = groonga["content"]
104
- @bookmarks_index_content[ruby.id] = ruby["content"]
105
-
106
- assert_content_search([groonga], "groonga")
107
- assert_content_search([groonga, ruby], "html")
108
- end
109
-
110
- def test_range
111
- assert_equal(context[Groonga::Type::SHORT_TEXT], @bookmarks_uri.range)
112
- assert_equal(context[Groonga::Type::TEXT], @bookmarks_comment.range)
113
- assert_equal(context[Groonga::Type::LONG_TEXT], @bookmarks_content.range)
114
- assert_equal(@users, @bookmarks_user.range)
115
- assert_equal(@bookmarks, @bookmarks_index_content.range)
116
- assert_equal(@bookmarks, @bookmarks_index_uri.range)
117
- end
118
-
119
- def test_accessor
120
- posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
121
- posts.define_column("body", "Text")
122
- comments = Groonga::Hash.create(:name => "Comments",
123
- :key_type => "ShortText")
124
- content = comments.define_column("content", "ShortText")
125
- comments.define_column("post", posts)
126
-
127
- index = Groonga::PatriciaTrie.create(:name => "Terms",
128
- :key_type => "ShortText")
129
- index.default_tokenizer = "TokenBigram"
130
- content_index = index.define_index_column("content_index", comments,
131
- :with_position => true)
132
- content_index.source = content
133
-
134
- first_post = posts.add("Hello!")
135
- first_post["body"] = "World"
136
- hobby = posts.add("My Hobby")
137
- hobby["body"] = "Drive and Eat"
138
-
139
- friend = comments.add("Me too")
140
- friend["content"] = "I'm also like drive"
141
- friend["post"] = hobby
142
-
143
- result = content_index.search("drive")
144
- assert_equal([["I'm also like drive", "My Hobby"]],
145
- result.records.collect do |record|
146
- [record[".content"], record[".post._key"]]
147
- end)
148
- end
149
-
150
- def test_accessor_reference
151
- bookmark = @bookmarks.add
152
- assert_nil(@bookmarks_user[bookmark.id])
153
-
154
- daijiro = @users.add
155
- daijiro["name"] = "daijiro"
156
- @bookmarks_user[bookmark.id] = daijiro
157
- assert_equal(daijiro, @bookmarks_user[bookmark.id])
158
- end
159
-
160
- def test_array_set_with_key_of_table
161
- languages = Groonga::Hash.create(:name => "Languages",
162
- :key_type => "ShortText")
163
- sites = Groonga::Hash.create(:name => "Sites")
164
- sites.define_column("language", languages)
165
-
166
- languages.add("Ruby")
167
- taiyaki_ru = sites.add("http://taiyaki.ru/", :language => "Ruby")
168
- assert_equal("Ruby", taiyaki_ru[:language].key)
169
- end
170
-
171
- def test_local_name
172
- items = Groonga::Array.create(:name => "Items")
173
- title = items.define_column("title", "ShortText")
174
- assert_equal("Items.title", title.name)
175
- assert_equal("title", title.local_name)
176
- end
177
-
178
- def test_select_query
179
- populate_table_for_select
180
-
181
- result = @body.select("drive")
182
- assert_equal(["Drive and Eat"],
183
- result.records.collect do |record|
184
- record["body"]
185
- end)
186
- assert_equal("#<Groonga::Expression noname(?0:\"\")" +
187
- "{body GET_VALUE \"drive\" MATCH}>",
188
- result.expression.inspect)
189
- end
190
-
191
- def test_select_query_with_parser
192
- populate_table_for_select
193
-
194
- result = @body.select("body @ \"drive\"", :syntax => :script)
195
- assert_equal(["Drive and Eat"],
196
- result.records.collect do |record|
197
- record["body"]
198
- end)
199
- assert_equal("#<Groonga::Expression noname(?0:\"\")" +
200
- "{body GET_VALUE \"drive\" MATCH}>",
201
- result.expression.inspect)
202
- end
203
-
204
- def test_select_expression
205
- populate_table_for_select
206
-
207
- expression = Groonga::Expression.new
208
- variable = expression.define_variable(:domain => @posts)
209
- expression.append_object(variable)
210
- expression.parse("body:%drive", :syntax => :query)
211
- expression.compile
212
- result = @body.select(expression)
213
- assert_equal(["Drive and Eat"],
214
- result.records.collect do |record|
215
- record["body"]
216
- end)
217
- assert_equal("#<Groonga::Expression noname(?0:\"\")" +
218
- "{?0 body GET_VALUE \"drive\" MATCH}>",
219
- result.expression.inspect)
220
- end
221
-
222
- def test_select_with_block
223
- populate_table_for_select
224
-
225
- result = @body.select do |column|
226
- column =~ "drive"
227
- end
228
- assert_equal(["Drive and Eat"],
229
- result.records.collect do |record|
230
- record["body"]
231
- end)
232
- assert_equal("#<Groonga::Expression noname(?0:\"\")" +
233
- "{?0 body GET_VALUE \"drive\" MATCH}>",
234
- result.expression.inspect)
235
- end
236
-
237
- def test_set_time
238
- posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
239
- body = posts.define_column("issued", "Time")
240
-
241
- post = posts.add("hello", :issued => 123456)
242
- assert_equal(Time.at(123456), post[".issued"])
243
- post = posts.add("groonga", :issued => 1251380635)
244
- assert_equal(Time.parse("2009-08-27 22:43:55"), post[".issued"])
245
- post = posts.add("mroonga", :issued => 1251380635.1234567)
246
- assert_in_delta(Time.at(1251380635.1234567).usec, post[".issued"].usec, 10)
247
- end
248
-
249
- def test_set_nil_to_time
250
- posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
251
- body = posts.define_column("issued", "Time")
252
-
253
- post = posts.add("hello", :issued => nil)
254
- assert_equal(Time.at(0), post["issued"])
255
- end
256
-
257
- def test_bool
258
- posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
259
- hidden = posts.define_column("hidden", "Bool")
260
-
261
- post = posts.add("hello")
262
- assert_false(post["hidden"])
263
-
264
- post["hidden"] = true
265
- assert_true(post["hidden"])
266
-
267
- post["hidden"] = false
268
- assert_false(post["hidden"])
269
- end
270
-
271
- private
272
- def assert_content_search(expected_records, term)
273
- records = @bookmarks_index_content.search(term).records
274
- expected_contents = expected_records.collect do |record|
275
- record["content"]
276
- end
277
- actual_contents = records.collect do |record|
278
- record.key["content"]
279
- end
280
- assert_equal(expected_contents, actual_contents)
281
- end
282
-
283
- def populate_table_for_select
284
- @posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
285
- @body = @posts.define_column("body", "Text")
286
-
287
- index = Groonga::PatriciaTrie.create(:name => "Terms",
288
- :key_type => "ShortText",
289
- :key_normalize => true)
290
- index.default_tokenizer = "TokenBigram"
291
- body_index = index.define_index_column("body_index", @posts,
292
- :with_position => true,
293
- :source => @body)
294
-
295
- first_post = @posts.add("Hello!", :body => "World")
296
- hobby = @posts.add("My Hobby", :body => "Drive and Eat")
297
- end
298
- end