rroonga 0.9.2-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. data/AUTHORS +5 -0
  2. data/NEWS.ja.rdoc +114 -0
  3. data/NEWS.rdoc +116 -0
  4. data/README.ja.rdoc +65 -0
  5. data/README.rdoc +66 -0
  6. data/Rakefile +217 -0
  7. data/benchmark/common.rb +49 -0
  8. data/benchmark/read-write-many-small-items.rb +144 -0
  9. data/benchmark/write-many-small-items.rb +135 -0
  10. data/example/bookmark.rb +161 -0
  11. data/example/index-html.rb +89 -0
  12. data/example/search/config.ru +211 -0
  13. data/example/search/public/css/groonga.css +122 -0
  14. data/ext/.gitignore +2 -0
  15. data/ext/libruby-groonga.a +0 -0
  16. data/ext/rb-grn-accessor.c +52 -0
  17. data/ext/rb-grn-array-cursor.c +36 -0
  18. data/ext/rb-grn-array.c +210 -0
  19. data/ext/rb-grn-column.c +573 -0
  20. data/ext/rb-grn-context.c +655 -0
  21. data/ext/rb-grn-database.c +472 -0
  22. data/ext/rb-grn-encoding-support.c +64 -0
  23. data/ext/rb-grn-encoding.c +257 -0
  24. data/ext/rb-grn-exception.c +1110 -0
  25. data/ext/rb-grn-expression-builder.c +75 -0
  26. data/ext/rb-grn-expression.c +735 -0
  27. data/ext/rb-grn-fix-size-column.c +166 -0
  28. data/ext/rb-grn-hash-cursor.c +38 -0
  29. data/ext/rb-grn-hash.c +294 -0
  30. data/ext/rb-grn-index-column.c +488 -0
  31. data/ext/rb-grn-logger.c +504 -0
  32. data/ext/rb-grn-object.c +1369 -0
  33. data/ext/rb-grn-operation.c +198 -0
  34. data/ext/rb-grn-patricia-trie-cursor.c +39 -0
  35. data/ext/rb-grn-patricia-trie.c +488 -0
  36. data/ext/rb-grn-procedure.c +52 -0
  37. data/ext/rb-grn-query.c +260 -0
  38. data/ext/rb-grn-record.c +40 -0
  39. data/ext/rb-grn-snippet.c +334 -0
  40. data/ext/rb-grn-table-cursor-key-support.c +69 -0
  41. data/ext/rb-grn-table-cursor.c +247 -0
  42. data/ext/rb-grn-table-key-support.c +731 -0
  43. data/ext/rb-grn-table.c +2141 -0
  44. data/ext/rb-grn-type.c +181 -0
  45. data/ext/rb-grn-utils.c +769 -0
  46. data/ext/rb-grn-variable-size-column.c +36 -0
  47. data/ext/rb-grn-variable.c +108 -0
  48. data/ext/rb-grn-view-accessor.c +53 -0
  49. data/ext/rb-grn-view-cursor.c +35 -0
  50. data/ext/rb-grn-view-record.c +41 -0
  51. data/ext/rb-grn-view.c +421 -0
  52. data/ext/rb-grn.h +700 -0
  53. data/ext/rb-groonga.c +117 -0
  54. data/extconf.rb +266 -0
  55. data/html/bar.svg +153 -0
  56. data/html/developer.html +117 -0
  57. data/html/developer.svg +469 -0
  58. data/html/download.svg +253 -0
  59. data/html/favicon.ico +0 -0
  60. data/html/favicon.xcf +0 -0
  61. data/html/footer.html.erb +28 -0
  62. data/html/head.html.erb +4 -0
  63. data/html/header.html.erb +17 -0
  64. data/html/index.html +147 -0
  65. data/html/install.svg +636 -0
  66. data/html/logo.xcf +0 -0
  67. data/html/ranguba.css +250 -0
  68. data/html/tutorial.svg +559 -0
  69. data/lib/groonga.rb +90 -0
  70. data/lib/groonga/context.rb +184 -0
  71. data/lib/groonga/expression-builder.rb +285 -0
  72. data/lib/groonga/patricia-trie.rb +53 -0
  73. data/lib/groonga/record.rb +311 -0
  74. data/lib/groonga/schema.rb +1191 -0
  75. data/lib/groonga/view-record.rb +56 -0
  76. data/license/GPL +340 -0
  77. data/license/LGPL +504 -0
  78. data/license/RUBY +59 -0
  79. data/misc/grnop2ruby.rb +49 -0
  80. data/pkg-config.rb +333 -0
  81. data/test-unit/Rakefile +40 -0
  82. data/test-unit/TODO +5 -0
  83. data/test-unit/bin/testrb +5 -0
  84. data/test-unit/html/classic.html +15 -0
  85. data/test-unit/html/index.html +25 -0
  86. data/test-unit/html/index.html.ja +27 -0
  87. data/test-unit/lib/test/unit.rb +323 -0
  88. data/test-unit/lib/test/unit/assertionfailederror.rb +25 -0
  89. data/test-unit/lib/test/unit/assertions.rb +1230 -0
  90. data/test-unit/lib/test/unit/attribute.rb +125 -0
  91. data/test-unit/lib/test/unit/autorunner.rb +360 -0
  92. data/test-unit/lib/test/unit/collector.rb +36 -0
  93. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  94. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  95. data/test-unit/lib/test/unit/collector/load.rb +136 -0
  96. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  97. data/test-unit/lib/test/unit/color-scheme.rb +102 -0
  98. data/test-unit/lib/test/unit/color.rb +96 -0
  99. data/test-unit/lib/test/unit/diff.rb +724 -0
  100. data/test-unit/lib/test/unit/error.rb +130 -0
  101. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  102. data/test-unit/lib/test/unit/failure.rb +136 -0
  103. data/test-unit/lib/test/unit/fixture.rb +176 -0
  104. data/test-unit/lib/test/unit/notification.rb +129 -0
  105. data/test-unit/lib/test/unit/omission.rb +191 -0
  106. data/test-unit/lib/test/unit/pending.rb +150 -0
  107. data/test-unit/lib/test/unit/priority.rb +180 -0
  108. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  109. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  110. data/test-unit/lib/test/unit/runner/tap.rb +8 -0
  111. data/test-unit/lib/test/unit/testcase.rb +476 -0
  112. data/test-unit/lib/test/unit/testresult.rb +89 -0
  113. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  114. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  115. data/test-unit/lib/test/unit/ui/console/testrunner.rb +466 -0
  116. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +63 -0
  117. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +92 -0
  118. data/test-unit/lib/test/unit/ui/testrunner.rb +28 -0
  119. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  120. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  121. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  122. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  123. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  124. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  125. data/test-unit/lib/test/unit/version.rb +7 -0
  126. data/test-unit/sample/adder.rb +13 -0
  127. data/test-unit/sample/subtracter.rb +12 -0
  128. data/test-unit/sample/test_adder.rb +20 -0
  129. data/test-unit/sample/test_subtracter.rb +20 -0
  130. data/test-unit/sample/test_user.rb +23 -0
  131. data/test-unit/test/collector/test-descendant.rb +133 -0
  132. data/test-unit/test/collector/test-load.rb +348 -0
  133. data/test-unit/test/collector/test_dir.rb +406 -0
  134. data/test-unit/test/collector/test_objectspace.rb +100 -0
  135. data/test-unit/test/run-test.rb +15 -0
  136. data/test-unit/test/test-attribute.rb +86 -0
  137. data/test-unit/test/test-color-scheme.rb +67 -0
  138. data/test-unit/test/test-color.rb +47 -0
  139. data/test-unit/test/test-diff.rb +518 -0
  140. data/test-unit/test/test-emacs-runner.rb +60 -0
  141. data/test-unit/test/test-fixture.rb +287 -0
  142. data/test-unit/test/test-notification.rb +33 -0
  143. data/test-unit/test/test-omission.rb +81 -0
  144. data/test-unit/test/test-pending.rb +70 -0
  145. data/test-unit/test/test-priority.rb +119 -0
  146. data/test-unit/test/test-testcase.rb +544 -0
  147. data/test-unit/test/test_assertions.rb +1151 -0
  148. data/test-unit/test/test_error.rb +26 -0
  149. data/test-unit/test/test_failure.rb +33 -0
  150. data/test-unit/test/test_testresult.rb +113 -0
  151. data/test-unit/test/test_testsuite.rb +129 -0
  152. data/test-unit/test/testunit-test-util.rb +14 -0
  153. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  154. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  155. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  156. data/test-unit/test/util/test_observable.rb +102 -0
  157. data/test-unit/test/util/test_procwrapper.rb +36 -0
  158. data/test/.gitignore +1 -0
  159. data/test/groonga-test-utils.rb +133 -0
  160. data/test/run-test.rb +58 -0
  161. data/test/test-array.rb +97 -0
  162. data/test/test-column.rb +316 -0
  163. data/test/test-context-select.rb +93 -0
  164. data/test/test-context.rb +73 -0
  165. data/test/test-database.rb +113 -0
  166. data/test/test-encoding.rb +33 -0
  167. data/test/test-exception.rb +93 -0
  168. data/test/test-expression-builder.rb +156 -0
  169. data/test/test-expression.rb +134 -0
  170. data/test/test-fix-size-column.rb +65 -0
  171. data/test/test-gqtp.rb +72 -0
  172. data/test/test-hash.rb +312 -0
  173. data/test/test-index-column.rb +81 -0
  174. data/test/test-logger.rb +37 -0
  175. data/test/test-patricia-trie.rb +189 -0
  176. data/test/test-procedure.rb +37 -0
  177. data/test/test-query.rb +22 -0
  178. data/test/test-record.rb +279 -0
  179. data/test/test-remote.rb +54 -0
  180. data/test/test-schema-view.rb +90 -0
  181. data/test/test-schema.rb +459 -0
  182. data/test/test-snippet.rb +130 -0
  183. data/test/test-table-cursor.rb +153 -0
  184. data/test/test-table-offset-and-limit.rb +102 -0
  185. data/test/test-table-select-normalize.rb +53 -0
  186. data/test/test-table-select.rb +150 -0
  187. data/test/test-table.rb +690 -0
  188. data/test/test-type.rb +71 -0
  189. data/test/test-variable-size-column.rb +98 -0
  190. data/test/test-variable.rb +28 -0
  191. data/test/test-vector-column.rb +76 -0
  192. data/test/test-version.rb +31 -0
  193. data/test/test-view.rb +72 -0
  194. data/text/TUTORIAL.ja.rdoc +392 -0
  195. data/text/expression.rdoc +284 -0
  196. data/vendor/local/bin/grntest.exe +0 -0
  197. data/vendor/local/bin/groonga.exe +0 -0
  198. data/vendor/local/bin/libgroonga.dll +0 -0
  199. data/vendor/local/bin/libmecab.dll +0 -0
  200. data/vendor/local/include/groonga.h +2285 -0
  201. data/vendor/local/lib/libgroonga.lib +0 -0
  202. metadata +280 -0
@@ -0,0 +1,130 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2009-2010 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
+ class SnippetTest < Test::Unit::TestCase
19
+ include GroongaTestUtils
20
+
21
+ def setup_encoding
22
+ Groonga::Encoding.default = :utf8
23
+ end
24
+
25
+ def test_new_without_arguments
26
+ assert_nothing_raised do
27
+ Groonga::Snippet.new
28
+ end
29
+ end
30
+
31
+ def test_execute
32
+ snippet = Groonga::Snippet.new
33
+ snippet.add_keyword("検索", :open_tag => "[[", :close_tag => "]]")
34
+ assert_equal(["groonga は組み込み型の全文[[検索]]エンジンライブラリです。DBMSやスクリプト",
35
+ "組み込むことによって、その全文[[検索]]機能を強化することができます。ま"],
36
+ snippet.execute(text))
37
+ end
38
+
39
+ def test_execute_with_nil
40
+ snippet = Groonga::Snippet.new
41
+ snippet.add_keyword("検索", :open_tag => "[[", :close_tag => "]]")
42
+ message = "snippet text must be String: <nil>"
43
+ assert_raise(Groonga::InvalidArgument.new(message)) do
44
+ snippet.execute(nil)
45
+ end
46
+ end
47
+
48
+ def test_invalid_encoding
49
+ Groonga::Context.default.encoding = :shift_jis
50
+ snippet = Groonga::Snippet.new
51
+ snippet.add_keyword("検索")
52
+ assert_equal([], snippet.execute(text))
53
+ end
54
+
55
+ def test_default_tag
56
+ snippet = Groonga::Snippet.new(:default_open_tag => "<<",
57
+ :default_close_tag => ">>")
58
+ snippet.add_keyword("全文")
59
+ assert_equal(["groonga は組み込み型の<<全文>>検索エンジンライブラリです。DBMSやスクリプト",
60
+ "等に組み込むことによって、その<<全文>>検索機能を強化することができます"],
61
+ snippet.execute(text))
62
+ end
63
+
64
+ def test_width
65
+ snippet = Groonga::Snippet.new(:width => 30,
66
+ :default_open_tag => "{",
67
+ :default_close_tag => "}")
68
+ snippet.add_keyword("データ")
69
+ assert_equal(["基づく{データ}ストア機",
70
+ "高速\nな{データ}ストア"],
71
+ snippet.execute(text))
72
+ end
73
+
74
+ def test_max_results
75
+ snippet = Groonga::Snippet.new(:width => 30,
76
+ :max_results => 1,
77
+ :default_open_tag => "{",
78
+ :default_close_tag => "}")
79
+ snippet.add_keyword("データ")
80
+ assert_equal(["基づく{データ}ストア機"],
81
+ snippet.execute(text))
82
+ end
83
+
84
+ def test_normalize
85
+ options_without_normalize = {
86
+ :width => 30,
87
+ :default_open_tag => "{",
88
+ :default_close_tag => "}",
89
+ }
90
+ snippet = Groonga::Snippet.new(options_without_normalize)
91
+ snippet.add_keyword("処理系等")
92
+ assert_equal([], snippet.execute(text))
93
+
94
+ options_with_normalize = options_without_normalize.merge(:normalize => true)
95
+ snippet = Groonga::Snippet.new(options_with_normalize)
96
+ snippet.add_keyword("処理系等")
97
+ assert_equal(["ト言語{処理\n系等}に組"],
98
+ snippet.execute(text))
99
+ end
100
+
101
+ def test_html_escape
102
+ text = "groonga は組み込み型の全文検索エンジン&データストアライブラリです。"
103
+ options_without_html_escape = {
104
+ :width => 30,
105
+ :default_open_tag => "<",
106
+ :default_close_tag => ">",
107
+ }
108
+ snippet = Groonga::Snippet.new(options_without_html_escape)
109
+ snippet.add_keyword("エンジン")
110
+ assert_equal(["文検索<エンジン>&デー"],
111
+ snippet.execute(text))
112
+
113
+ options_with_html_escape =
114
+ options_without_html_escape.merge(:html_escape => true)
115
+ snippet = Groonga::Snippet.new(options_with_html_escape)
116
+ snippet.add_keyword("エンジン")
117
+ assert_equal(["文検索<エンジン>&amp;デー"],
118
+ snippet.execute(text))
119
+ end
120
+
121
+ private
122
+ def text
123
+ <<-EOT
124
+ groonga は組み込み型の全文検索エンジンライブラリです。DBMSやスクリプト言語処理
125
+ 系等に組み込むことによって、その全文検索機能を強化することができます。また、リ
126
+ レーショナルモデルに基づくデータストア機能を内包しており、groonga単体でも高速
127
+ なデータストアサーバとして使用することができます。
128
+ EOT
129
+ end
130
+ end
@@ -0,0 +1,153 @@
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 TableCursorTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ def setup
20
+ setup_database
21
+
22
+ @bookmarks_path = @tables_dir + "table"
23
+ @bookmarks = Groonga::PatriciaTrie.create(:name => "Bookmarks",
24
+ :path => @bookmarks_path.to_s)
25
+ @groonga_bookmark = @bookmarks.add("groonga")
26
+ @cutter_bookmark = @bookmarks.add("Cutter")
27
+ @ruby_bookmark = @bookmarks.add("Ruby")
28
+ end
29
+
30
+ def test_open
31
+ keys = []
32
+ @bookmarks.open_cursor do |cursor|
33
+ while cursor.next
34
+ keys << cursor.key
35
+ end
36
+ end
37
+ assert_equal(["Cutter", "Ruby", "groonga"],
38
+ keys)
39
+ end
40
+
41
+ def test_open_ascendent
42
+ record_and_key_list = []
43
+ @bookmarks.open_cursor(:order => :ascending) do |cursor|
44
+ record_and_key_list = cursor.collect {|record| [record, cursor.key]}
45
+ end
46
+ assert_equal([[@cutter_bookmark, "Cutter"],
47
+ [@ruby_bookmark, "Ruby"],
48
+ [@groonga_bookmark, "groonga"]],
49
+ record_and_key_list)
50
+ end
51
+
52
+ def test_without_limit_and_offset
53
+ users = create_users
54
+ add_users(users)
55
+ results = []
56
+ users.open_cursor do |cursor|
57
+ cursor.each do |record|
58
+ results << record["name"]
59
+ end
60
+ end
61
+
62
+ assert_equal((100..199).collect {|i| "user#{i}"},
63
+ results)
64
+ end
65
+
66
+ def test_with_limit
67
+ users = create_users
68
+ add_users(users)
69
+ results = []
70
+ users.open_cursor(:limit => 20) do |cursor|
71
+ cursor.each do |record|
72
+ results << record["name"]
73
+ end
74
+ end
75
+
76
+ assert_equal((100...120).collect {|i| "user#{i}"},
77
+ results)
78
+ end
79
+
80
+ def test_with_offset
81
+ users = create_users
82
+ add_users(users)
83
+ results = []
84
+ users.open_cursor(:offset => 20) do |cursor|
85
+ cursor.each do |record|
86
+ results << record["name"]
87
+ end
88
+ end
89
+
90
+ assert_equal((120...200).collect {|i| "user#{i}"},
91
+ results)
92
+ end
93
+
94
+ def test_with_limit_and_offset
95
+ users = create_users
96
+ add_users(users)
97
+ results = []
98
+ users.open_cursor(:limit => 20, :offset => 20) do |cursor|
99
+ cursor.each do |record|
100
+ results << record["name"]
101
+ end
102
+ end
103
+
104
+ assert_equal((120...140).collect {|i| "user#{i}"},
105
+ results)
106
+ end
107
+
108
+ def test_delete
109
+ users = create_users
110
+ add_users(users)
111
+
112
+ users.open_cursor(:limit => 20) do |cursor|
113
+ 20.times do
114
+ cursor.next
115
+ cursor.delete
116
+ end
117
+ end
118
+
119
+ results = []
120
+ users.open_cursor do |cursor|
121
+ cursor.each do |record|
122
+ results << record["name"]
123
+ end
124
+ end
125
+
126
+ assert_equal((120...200).collect {|i| "user#{i}"},
127
+ results)
128
+ end
129
+
130
+ def test_patricia_trie_cursor_key
131
+ sites = Groonga::PatriciaTrie.create(:name => "Sites")
132
+ sites.add("http://groonga.org/")
133
+ sites.open_cursor do |cursor|
134
+ cursor.next
135
+ assert_equal("http://groonga.org/", cursor.key)
136
+ end
137
+ end
138
+
139
+ private
140
+ def create_users
141
+ users = Groonga::Array.create(:name => "Users")
142
+ users.define_column("name", "ShortText")
143
+ users
144
+ end
145
+
146
+ def add_users(users)
147
+ (0...100).to_a.each do |i|
148
+ user = users.add
149
+ user["name"] = "user#{i + 100}"
150
+ end
151
+ users
152
+ end
153
+ end
@@ -0,0 +1,102 @@
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
+ module TestOffsetAndLimitSupport
17
+ def test_zero_and_positive_offset
18
+ assert_equal(((100 + 0)...200).to_a, ids(:offset => 0))
19
+ assert_equal(((100 + 32)...200).to_a, ids(:offset => 32))
20
+ assert_equal(((100 + 99)...200).to_a, ids(:offset => 99))
21
+ assert_raise(Groonga::InvalidArgument) do
22
+ ids(:offset => 100)
23
+ end
24
+ end
25
+
26
+ def test_negative_offset
27
+ assert_equal(((200 - 1)...200).to_a, ids(:offset => -1))
28
+ assert_equal(((200 - 32)...200).to_a, ids(:offset => -32))
29
+ assert_equal(((200 - 100)...200).to_a, ids(:offset => -100))
30
+ assert_raise(Groonga::InvalidArgument) do
31
+ ids(:offset => -101)
32
+ end
33
+ end
34
+
35
+ def test_zero_and_positive_limit
36
+ all_ids = (100...200).to_a
37
+ assert_equal(all_ids[0, 0], ids(:limit => 0))
38
+ assert_equal(all_ids[0, 32], ids(:limit => 32))
39
+ assert_equal(all_ids[0, 100], ids(:limit => 100))
40
+ assert_nothing_raised do
41
+ ids(:limit => 101)
42
+ end
43
+ end
44
+
45
+ def test_negative_limit
46
+ all_ids = (100...200).to_a
47
+ assert_equal(all_ids[0..-1], ids(:limit => -1))
48
+ assert_equal(all_ids[0..-32], ids(:limit => -32))
49
+ assert_equal(all_ids[0..-100], ids(:limit => -100))
50
+ assert_raise(Groonga::InvalidArgument) do
51
+ ids(:offset => -101)
52
+ end
53
+ end
54
+
55
+ private
56
+ def create_bookmarks
57
+ @bookmarks = Groonga::Array.create(:name => "Bookmarks")
58
+ @bookmarks.define_column("id", "Int32")
59
+ @bookmarks
60
+ end
61
+
62
+ def add_ids
63
+ 100.times do |i|
64
+ bookmark = @bookmarks.add
65
+ bookmark["id"] = i + 100
66
+ end
67
+ @bookmarks
68
+ end
69
+ end
70
+
71
+ class TestOffsetAndLimit < Test::Unit::TestCase
72
+ include GroongaTestUtils
73
+ def setup
74
+ setup_database
75
+ @bookmarks = create_bookmarks
76
+ add_ids
77
+ end
78
+ end
79
+
80
+ class TestTableCursorOffsetAndLimit < TestOffsetAndLimit
81
+ include TestOffsetAndLimitSupport
82
+
83
+ private
84
+ def ids(options={})
85
+ @bookmarks.open_cursor(options) do |cursor|
86
+ cursor.collect do |record|
87
+ record["id"]
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ class TestTableSortOffsetAndLimit < TestOffsetAndLimit
94
+ include TestOffsetAndLimitSupport
95
+
96
+ private
97
+ def ids(options={})
98
+ @bookmarks.sort([:key => "id", :order => :asc], options).collect do |record|
99
+ record["id"]
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,53 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2009 SHIDARA Yoji <dara@shidara.net>
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
+ class TableSelectNormalizeTest < Test::Unit::TestCase
19
+ include GroongaTestUtils
20
+
21
+ setup :setup_database
22
+
23
+ setup
24
+ def setup_comments
25
+ @comments = Groonga::Array.create(:name => "Comments")
26
+ @comments.define_column("content", "Text")
27
+ @comments.define_column("created_at", "Time")
28
+ terms = Groonga::PatriciaTrie.create(:name => "Terms",
29
+ :default_tokenizer => "TokenBigram",
30
+ :key_normalize => true)
31
+ terms.define_index_column("comment_content", @comments,
32
+ :with_section => true,
33
+ :source => "Comments.content")
34
+ @japanese_comment =
35
+ @comments.add(:content => "うちのボロTV(アナログ...)はまだ現役です",
36
+ :created_at => Time.parse("2009-06-09"))
37
+ end
38
+
39
+ def test_select_query_with_japanese
40
+ result = @comments.select("content:@ボロTV")
41
+ assert_equal_select_result([@japanese_comment], result)
42
+ end
43
+
44
+ def test_select_query_with_japanese_parenthesis
45
+ result = @comments.select("content:@)は")
46
+ assert_equal_select_result([@japanese_comment], result)
47
+ end
48
+
49
+ def test_select_query_only_in_japanese
50
+ result = @comments.select("content:@うちの")
51
+ assert_equal_select_result([@japanese_comment], result)
52
+ end
53
+ end
@@ -0,0 +1,150 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2009-2010 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
+ class TableSelectTest < Test::Unit::TestCase
19
+ include GroongaTestUtils
20
+
21
+ setup :setup_database
22
+
23
+ setup
24
+ def setup_comments
25
+ @users = Groonga::Hash.create(:name => "Users", :key_type => "ShortText")
26
+
27
+ @comments = Groonga::Array.create(:name => "Comments")
28
+ @comments.define_column("content", "Text")
29
+ @comments.define_column("created_at", "Time")
30
+ @comments.define_column("user", "Users")
31
+
32
+ terms = Groonga::PatriciaTrie.create(:name => "Terms",
33
+ :default_tokenizer => "TokenBigram")
34
+ terms.define_index_column("comment_content", @comments,
35
+ :with_section => true,
36
+ :source => "content")
37
+ @comment1 = @comments.add(:content => "Hello Good-bye!",
38
+ :created_at => Time.parse("2009-08-09"),
39
+ :user => "morita")
40
+ @comment2 = @comments.add(:content => "Hello World",
41
+ :created_at => Time.parse("2009-07-09"))
42
+ @comment3 = @comments.add(:content => "test",
43
+ :created_at => Time.parse("2009-06-09"),
44
+ :user => "gunyara-kun")
45
+ @japanese_comment =
46
+ @comments.add(:content => "うちのボロTVはまだ現役です",
47
+ :created_at => Time.parse("2009-06-09"),
48
+ :user => "darashi")
49
+ end
50
+
51
+ def test_select_sub_expression
52
+ result = @comments.select do |record|
53
+ record.match("Hello", "content") &
54
+ (record["created_at"] < Time.parse("2009-08-01"))
55
+ end
56
+ assert_equal_select_result([@comment2], result)
57
+ end
58
+
59
+ def test_select_query
60
+ result = @comments.select("content:@Hello")
61
+ assert_equal_select_result([@comment1, @comment2], result)
62
+ end
63
+
64
+ def test_select_query_with_parser
65
+ result = @comments.select("content @ \"Hello\"", :syntax => :script)
66
+ assert_equal_select_result([@comment1, @comment2], result)
67
+ end
68
+
69
+ def test_select_query_with_default_column
70
+ result = @comments.select("Hello", {:default_column => 'content'})
71
+ assert_equal_select_result([@comment1, @comment2], result)
72
+ end
73
+
74
+ def test_select_expression
75
+ expression = Groonga::Expression.new
76
+ variable = expression.define_variable(:domain => @comments)
77
+ expression.append_object(variable)
78
+ expression.parse("content:@Hello", :syntax => :query)
79
+ expression.compile
80
+ result = @comments.select(expression)
81
+ assert_equal(expression, result.expression)
82
+ assert_equal_select_result([@comment1, @comment2], result)
83
+ end
84
+
85
+ def test_select_query_with_block
86
+ result = @comments.select("content:@Hello") do |record|
87
+ record["created_at"] < Time.parse("2009-08-01")
88
+ end
89
+ assert_equal_select_result([@comment2], result)
90
+ end
91
+
92
+ def test_select_query_with_block_match
93
+ result = @comments.select("content:@Hello") do |record|
94
+ record.match("World", "content")
95
+ end
96
+ assert_equal_select_result([@comment2], result)
97
+ end
98
+
99
+ def test_select_without_block
100
+ assert_equal_select_result([@comment1, @comment2,
101
+ @comment3, @japanese_comment],
102
+ @comments.select)
103
+ end
104
+
105
+ def test_select_query_japanese
106
+ result = @comments.select("content:@ボロTV")
107
+ assert_equal_select_result([@japanese_comment], result)
108
+ end
109
+
110
+ def test_select_but_query
111
+ result = @comments.select do |record|
112
+ record["content"].match "Hello -World"
113
+ end
114
+ assert_equal_select_result([@comment1], result)
115
+ end
116
+
117
+ def test_select_query_with_three_terms
118
+ result = @comments.select do |record|
119
+ record["content"].match "Say Hello World"
120
+ end
121
+ assert_equal_select_result([], result)
122
+ end
123
+
124
+ def test_select_query_with_brackets
125
+ result = @comments.select do |record|
126
+ record["content"].match "Say (Hello World)"
127
+ end
128
+ assert_equal_select_result([], result)
129
+ end
130
+
131
+ def test_select_equal_reference_column_by_key
132
+ result = @comments.select do |record|
133
+ record["user"] == "darashi"
134
+ end
135
+ assert_equal_select_result([@japanese_comment], result)
136
+ end
137
+
138
+ def test_select_not_equal_reference_column_by_key
139
+ result = @comments.select('user != "darashi"', :syntax => :script)
140
+ assert_equal_select_result([@comment1, @comment2, @comment3],
141
+ result)
142
+ end
143
+
144
+ def test_select_equal_reference_column_by_nonexistent_key
145
+ result = @comments.select do |record|
146
+ record["user"] == "nonexistent"
147
+ end
148
+ assert_equal_select_result([], result)
149
+ end
150
+ end