rroonga 0.9.2-x86-mingw32

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 (199) 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 +206 -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 +230 -0
  13. data/example/search/public/css/groonga.css +122 -0
  14. data/ext/.gitignore +2 -0
  15. data/ext/groonga/extconf.rb +93 -0
  16. data/ext/groonga/rb-grn-accessor.c +52 -0
  17. data/ext/groonga/rb-grn-array-cursor.c +36 -0
  18. data/ext/groonga/rb-grn-array.c +210 -0
  19. data/ext/groonga/rb-grn-column.c +573 -0
  20. data/ext/groonga/rb-grn-context.c +662 -0
  21. data/ext/groonga/rb-grn-database.c +472 -0
  22. data/ext/groonga/rb-grn-encoding-support.c +64 -0
  23. data/ext/groonga/rb-grn-encoding.c +257 -0
  24. data/ext/groonga/rb-grn-exception.c +1110 -0
  25. data/ext/groonga/rb-grn-expression-builder.c +75 -0
  26. data/ext/groonga/rb-grn-expression.c +731 -0
  27. data/ext/groonga/rb-grn-fix-size-column.c +166 -0
  28. data/ext/groonga/rb-grn-hash-cursor.c +38 -0
  29. data/ext/groonga/rb-grn-hash.c +294 -0
  30. data/ext/groonga/rb-grn-index-column.c +488 -0
  31. data/ext/groonga/rb-grn-logger.c +504 -0
  32. data/ext/groonga/rb-grn-object.c +1369 -0
  33. data/ext/groonga/rb-grn-operation.c +198 -0
  34. data/ext/groonga/rb-grn-patricia-trie-cursor.c +39 -0
  35. data/ext/groonga/rb-grn-patricia-trie.c +488 -0
  36. data/ext/groonga/rb-grn-procedure.c +52 -0
  37. data/ext/groonga/rb-grn-query.c +260 -0
  38. data/ext/groonga/rb-grn-record.c +40 -0
  39. data/ext/groonga/rb-grn-snippet.c +334 -0
  40. data/ext/groonga/rb-grn-table-cursor-key-support.c +69 -0
  41. data/ext/groonga/rb-grn-table-cursor.c +247 -0
  42. data/ext/groonga/rb-grn-table-key-support.c +714 -0
  43. data/ext/groonga/rb-grn-table.c +1977 -0
  44. data/ext/groonga/rb-grn-type.c +181 -0
  45. data/ext/groonga/rb-grn-utils.c +769 -0
  46. data/ext/groonga/rb-grn-variable-size-column.c +36 -0
  47. data/ext/groonga/rb-grn-variable.c +108 -0
  48. data/ext/groonga/rb-grn-view-accessor.c +53 -0
  49. data/ext/groonga/rb-grn-view-cursor.c +35 -0
  50. data/ext/groonga/rb-grn-view-record.c +41 -0
  51. data/ext/groonga/rb-grn-view.c +421 -0
  52. data/ext/groonga/rb-grn.h +698 -0
  53. data/ext/groonga/rb-groonga.c +107 -0
  54. data/extconf.rb +130 -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/1.8/groonga.so +0 -0
  70. data/lib/1.9/groonga.so +0 -0
  71. data/lib/groonga.rb +90 -0
  72. data/lib/groonga/context.rb +184 -0
  73. data/lib/groonga/expression-builder.rb +324 -0
  74. data/lib/groonga/patricia-trie.rb +85 -0
  75. data/lib/groonga/record.rb +311 -0
  76. data/lib/groonga/schema.rb +1191 -0
  77. data/lib/groonga/view-record.rb +56 -0
  78. data/license/GPL +340 -0
  79. data/license/LGPL +504 -0
  80. data/license/RUBY +59 -0
  81. data/misc/grnop2ruby.rb +49 -0
  82. data/pkg-config.rb +333 -0
  83. data/rroonga-build.rb +57 -0
  84. data/test-unit/Rakefile +40 -0
  85. data/test-unit/TODO +5 -0
  86. data/test-unit/bin/testrb +5 -0
  87. data/test-unit/html/classic.html +15 -0
  88. data/test-unit/html/index.html +25 -0
  89. data/test-unit/html/index.html.ja +27 -0
  90. data/test-unit/lib/test/unit.rb +323 -0
  91. data/test-unit/lib/test/unit/assertionfailederror.rb +25 -0
  92. data/test-unit/lib/test/unit/assertions.rb +1230 -0
  93. data/test-unit/lib/test/unit/attribute.rb +125 -0
  94. data/test-unit/lib/test/unit/autorunner.rb +360 -0
  95. data/test-unit/lib/test/unit/collector.rb +36 -0
  96. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  97. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  98. data/test-unit/lib/test/unit/collector/load.rb +144 -0
  99. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  100. data/test-unit/lib/test/unit/color-scheme.rb +102 -0
  101. data/test-unit/lib/test/unit/color.rb +96 -0
  102. data/test-unit/lib/test/unit/diff.rb +724 -0
  103. data/test-unit/lib/test/unit/error.rb +130 -0
  104. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  105. data/test-unit/lib/test/unit/failure.rb +136 -0
  106. data/test-unit/lib/test/unit/fixture.rb +176 -0
  107. data/test-unit/lib/test/unit/notification.rb +129 -0
  108. data/test-unit/lib/test/unit/omission.rb +191 -0
  109. data/test-unit/lib/test/unit/pending.rb +150 -0
  110. data/test-unit/lib/test/unit/priority.rb +180 -0
  111. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  112. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  113. data/test-unit/lib/test/unit/runner/tap.rb +8 -0
  114. data/test-unit/lib/test/unit/testcase.rb +476 -0
  115. data/test-unit/lib/test/unit/testresult.rb +89 -0
  116. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  117. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  118. data/test-unit/lib/test/unit/ui/console/testrunner.rb +466 -0
  119. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +63 -0
  120. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +92 -0
  121. data/test-unit/lib/test/unit/ui/testrunner.rb +28 -0
  122. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  123. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  124. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  125. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  126. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  127. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  128. data/test-unit/lib/test/unit/version.rb +7 -0
  129. data/test-unit/sample/adder.rb +13 -0
  130. data/test-unit/sample/subtracter.rb +12 -0
  131. data/test-unit/sample/test_adder.rb +20 -0
  132. data/test-unit/sample/test_subtracter.rb +20 -0
  133. data/test-unit/sample/test_user.rb +23 -0
  134. data/test-unit/test/collector/test-descendant.rb +133 -0
  135. data/test-unit/test/collector/test-load.rb +442 -0
  136. data/test-unit/test/collector/test_dir.rb +406 -0
  137. data/test-unit/test/collector/test_objectspace.rb +100 -0
  138. data/test-unit/test/run-test.rb +15 -0
  139. data/test-unit/test/test-attribute.rb +86 -0
  140. data/test-unit/test/test-color-scheme.rb +67 -0
  141. data/test-unit/test/test-color.rb +47 -0
  142. data/test-unit/test/test-diff.rb +518 -0
  143. data/test-unit/test/test-emacs-runner.rb +60 -0
  144. data/test-unit/test/test-fixture.rb +287 -0
  145. data/test-unit/test/test-notification.rb +33 -0
  146. data/test-unit/test/test-omission.rb +81 -0
  147. data/test-unit/test/test-pending.rb +70 -0
  148. data/test-unit/test/test-priority.rb +119 -0
  149. data/test-unit/test/test-testcase.rb +544 -0
  150. data/test-unit/test/test_assertions.rb +1151 -0
  151. data/test-unit/test/test_error.rb +26 -0
  152. data/test-unit/test/test_failure.rb +33 -0
  153. data/test-unit/test/test_testresult.rb +113 -0
  154. data/test-unit/test/test_testsuite.rb +129 -0
  155. data/test-unit/test/testunit-test-util.rb +14 -0
  156. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  157. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  158. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  159. data/test-unit/test/util/test_observable.rb +102 -0
  160. data/test-unit/test/util/test_procwrapper.rb +36 -0
  161. data/test/.gitignore +1 -0
  162. data/test/groonga-test-utils.rb +134 -0
  163. data/test/run-test.rb +58 -0
  164. data/test/test-array.rb +90 -0
  165. data/test/test-column.rb +316 -0
  166. data/test/test-context-select.rb +93 -0
  167. data/test/test-context.rb +73 -0
  168. data/test/test-database.rb +113 -0
  169. data/test/test-encoding.rb +33 -0
  170. data/test/test-exception.rb +93 -0
  171. data/test/test-expression-builder.rb +217 -0
  172. data/test/test-expression.rb +134 -0
  173. data/test/test-fix-size-column.rb +65 -0
  174. data/test/test-gqtp.rb +72 -0
  175. data/test/test-hash.rb +305 -0
  176. data/test/test-index-column.rb +81 -0
  177. data/test/test-logger.rb +37 -0
  178. data/test/test-patricia-trie.rb +205 -0
  179. data/test/test-procedure.rb +37 -0
  180. data/test/test-query.rb +22 -0
  181. data/test/test-record.rb +243 -0
  182. data/test/test-remote.rb +54 -0
  183. data/test/test-schema-view.rb +90 -0
  184. data/test/test-schema.rb +459 -0
  185. data/test/test-snippet.rb +130 -0
  186. data/test/test-table-cursor.rb +153 -0
  187. data/test/test-table-offset-and-limit.rb +102 -0
  188. data/test/test-table-select-normalize.rb +53 -0
  189. data/test/test-table-select.rb +150 -0
  190. data/test/test-table.rb +594 -0
  191. data/test/test-type.rb +71 -0
  192. data/test/test-variable-size-column.rb +98 -0
  193. data/test/test-variable.rb +28 -0
  194. data/test/test-vector-column.rb +76 -0
  195. data/test/test-version.rb +31 -0
  196. data/test/test-view.rb +72 -0
  197. data/text/TUTORIAL.ja.rdoc +392 -0
  198. data/text/expression.rdoc +284 -0
  199. metadata +276 -0
@@ -0,0 +1,81 @@
1
+ # -*- coding: utf-8 -*-
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
+ class IndexColumnTest < Test::Unit::TestCase
19
+ include GroongaTestUtils
20
+
21
+ def setup
22
+ setup_database
23
+ end
24
+
25
+ def test_array_set_with_record
26
+ articles = Groonga::Array.create(:name => "Articles")
27
+ articles.define_column("content", "Text")
28
+
29
+ terms = Groonga::Hash.create(:name => "Terms",
30
+ :default_tokenizer => "TokenBigram")
31
+ content_index = terms.define_index_column("content", articles,
32
+ :with_section => true)
33
+
34
+ content = <<-EOC
35
+ groonga は組み込み型の全文検索エンジンライブラリです。
36
+ DBMSやスクリプト言語処理系等に組み込むことによって、その
37
+ 全文検索機能を強化することができます。また、リレーショナ
38
+ ルモデルに基づくデータストア機能を内包しており、groonga
39
+ 単体でも高速なデータストアサーバとして使用することができ
40
+ ます。
41
+
42
+ ■全文検索方式
43
+ 転置索引型の全文検索エンジンです。転置索引は圧縮されてファ
44
+ イルに格納され、検索時のディスク読み出し量を小さく、かつ
45
+ 局所的に抑えるように設計されています。用途に応じて以下の
46
+ 索引タイプを選択できます。
47
+ EOC
48
+
49
+ groonga = articles.add(:content => content)
50
+
51
+ content.split(/\n{2,}/).each_with_index do |sentence, i|
52
+ content_index[groonga] = {:value => sentence, :section => i + 1}
53
+ end
54
+ assert_equal([groonga],
55
+ content_index.search("エンジン").collect {|record| record.key})
56
+ end
57
+
58
+ def test_shorter_query_than_ngram
59
+ articles = Groonga::Array.create(:name => "Articles")
60
+ articles.define_column("content", "Text")
61
+
62
+ terms = Groonga::PatriciaTrie.create(:name => "Terms",
63
+ :default_tokenizer => "TokenBigram")
64
+ content_index = terms.define_index_column("content", articles,
65
+ :source => "Articles.content")
66
+ articles.add(:content => 'l')
67
+ articles.add(:content => 'll')
68
+ articles.add(:content => 'hello')
69
+
70
+ assert_search(["hello"], content_index, "he")
71
+ assert_search(["ll", "hello"], content_index, "ll")
72
+ assert_search(["l", "ll", "hello"], content_index, "l")
73
+ end
74
+
75
+ def assert_search(expected, content_index, keyword)
76
+ result = content_index.search(keyword).collect do |entry|
77
+ entry.key["content"]
78
+ end
79
+ assert_equal(expected, result)
80
+ end
81
+ end
@@ -0,0 +1,37 @@
1
+ # Copyright (C) 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 LoggerTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ def setup
20
+ @default_log_path = Groonga::Logger.log_path
21
+ @default_query_log_path = Groonga::Logger.query_log_path
22
+ end
23
+
24
+ def teardown
25
+ Groonga::Logger.log_path = @default_log_path
26
+ Groonga::Logger.query_log_path = @default_query_log_path
27
+ end
28
+
29
+ def test_reopen
30
+ if File.exist?(@default_log_path)
31
+ FileUtils.mv(@default_log_path, "#{@default_log_path}.old")
32
+ end
33
+ assert_false(File.exist?(@default_log_path))
34
+ Groonga::Logger.reopen
35
+ assert_true(File.exist?(@default_log_path))
36
+ end
37
+ end
@@ -0,0 +1,205 @@
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 PatriciaTrieTest < Test::Unit::TestCase
19
+ include GroongaTestUtils
20
+ include ERB::Util
21
+
22
+ setup :setup_database
23
+
24
+ def test_encoding
25
+ assert_equal(Groonga::Encoding.default,
26
+ Groonga::PatriciaTrie.create.encoding)
27
+ end
28
+
29
+ def test_tokenizer
30
+ trie = Groonga::PatriciaTrie.create
31
+ assert_nil(trie.default_tokenizer)
32
+ trie.default_tokenizer = "TokenTrigram"
33
+ assert_equal(Groonga::Context.default["TokenTrigram"],
34
+ trie.default_tokenizer)
35
+ end
36
+
37
+ def test_search
38
+ users = Groonga::Array.create(:name => "Users")
39
+ user_name = users.define_column("name", "ShortText")
40
+
41
+ bookmarks = Groonga::PatriciaTrie.create(:name => "Bookmarks",
42
+ :key_type => "ShortText")
43
+ bookmark_user_id = bookmarks.define_column("user_id", users)
44
+
45
+ daijiro = users.add
46
+ daijiro["name"] = "daijiro"
47
+ gunyarakun = users.add
48
+ gunyarakun["name"] = "gunyarakun"
49
+
50
+ groonga = bookmarks.add("http://groonga.org/")
51
+ groonga["user_id"] = daijiro
52
+
53
+ records = bookmarks.search("http://groonga.org/")
54
+ assert_equal(["daijiro"],
55
+ records.records.collect {|record| record[".user_id.name"]})
56
+ end
57
+
58
+ def test_add
59
+ users = Groonga::PatriciaTrie.create(:name => "Users")
60
+ users.define_column("address", "<text>")
61
+ me = users.add("me", :address => "me@example.com")
62
+ assert_equal("me@example.com", me[:address])
63
+ end
64
+
65
+ def test_default_tokenizer_on_create
66
+ terms = Groonga::PatriciaTrie.create(:name => "Terms",
67
+ :default_tokenizer => "TokenUnigram")
68
+ assert_equal(context[Groonga::Type::UNIGRAM],
69
+ terms.default_tokenizer)
70
+ end
71
+
72
+ def test_duplicated_name
73
+ Groonga::PatriciaTrie.create(:name => "Users")
74
+ assert_raise(Groonga::InvalidArgument) do
75
+ Groonga::PatriciaTrie.create(:name => "Users")
76
+ end
77
+ end
78
+
79
+ def test_has_key?
80
+ users = Groonga::PatriciaTrie.create(:name => "Users")
81
+ assert_false(users.has_key?("morita"))
82
+ users.add("morita")
83
+ assert_true(users.has_key?("morita"))
84
+ end
85
+
86
+ def test_scan
87
+ Groonga::Context.default_options = {:encoding => "utf-8"}
88
+ words = Groonga::PatriciaTrie.create(:key_type => "ShortText",
89
+ :key_normalize => true)
90
+ words.add("リンク")
91
+ arupaka = words.add("アルパカ")
92
+ words.add("アルパカ(生物)")
93
+ adventure_of_link = words.add('リンクの冒険')
94
+ words.add('冒険')
95
+ gaxtu = words.add('ガッ')
96
+ muteki = words.add('MUTEKI')
97
+ assert_equal([[muteki, "muTEki", 0, 6],
98
+ [adventure_of_link, "リンクの冒険", 7, 18],
99
+ [arupaka, "アルパカ", 42, 12],
100
+ [gaxtu, "ガッ", 55, 6]],
101
+ words.scan('muTEki リンクの冒険 ミリバール アルパカ ガッ'))
102
+ end
103
+
104
+ def test_tag_keys
105
+ Groonga::Context.default_options = {:encoding => "utf-8"}
106
+ words = Groonga::PatriciaTrie.create(:key_type => "ShortText",
107
+ :key_normalize => true)
108
+ words.add('リンク')
109
+ words.add('リンクの冒険')
110
+ words.add('冒険')
111
+ words.add('㍊')
112
+ words.add('ガッ')
113
+ words.add('MUTEKI')
114
+
115
+ text = 'muTEki リンクの冒険 マッチしない ミリバール ガッ おわり'
116
+ actual = words.tag_keys(text) do |record, word|
117
+ "<#{word}(#{record.key})>"
118
+ end
119
+ assert_equal("<muTEki(muteki)> " +
120
+ "<リンクの冒険(リンクの冒険)> " +
121
+ "マッチしない " +
122
+ "<ミリバール(ミリバール)> " +
123
+ "<ガッ(ガッ)> " +
124
+ "おわり",
125
+ actual)
126
+ end
127
+
128
+ def test_tag_keys_other_text_handler
129
+ Groonga::Context.default_options = {:encoding => "utf-8"}
130
+ words = Groonga::PatriciaTrie.create(:key_type => "ShortText",
131
+ :key_normalize => true)
132
+ words.add('ガッ')
133
+ words.add('MUTEKI')
134
+
135
+ text = 'muTEki マッチしない <> ガッ'
136
+ other_text_handler = Proc.new do |string|
137
+ h(string)
138
+ end
139
+ options = {:other_text_handler => other_text_handler}
140
+ actual = words.tag_keys(text, options) do |record, word|
141
+ "<span class=\"keyword\">#{h(word)}(#{h(record.key)})</span>\n"
142
+ end
143
+ assert_equal("<span class=\"keyword\">muTEki(muteki)</span>\n" +
144
+ " マッチしない &lt;&gt; " +
145
+ "<span class=\"keyword\">ガッ(ガッ)</span>\n",
146
+ actual)
147
+ end
148
+
149
+ def test_tag_keys_with_last_match
150
+ Groonga::Context.default_options = {:encoding => "utf-8"}
151
+ words = Groonga::PatriciaTrie.create(:key_type => "ShortText",
152
+ :key_normalize => true)
153
+ words.add('ガッ')
154
+ words.add('MUTEKI')
155
+
156
+ text = 'muTEki マッチしない ガッ'
157
+ actual = words.tag_keys(text) do |record, word|
158
+ "<#{word}(#{record.key})>"
159
+ end
160
+ assert_equal("<muTEki(muteki)> " +
161
+ "マッチしない " +
162
+ "<ガッ(ガッ)>",
163
+ actual)
164
+ end
165
+
166
+ def test_tag_keys_with_no_match
167
+ Groonga::Context.default_options = {:encoding => "utf-8"}
168
+ words = Groonga::PatriciaTrie.create(:key_type => "ShortText",
169
+ :key_normalize => true)
170
+
171
+ words.add('無敵')
172
+ words.add('BOUKEN')
173
+
174
+ text = 'muTEki リンクの冒険'
175
+ actual = words.tag_keys(text) do |record, word|
176
+ "<#{word}(#{record.key})>"
177
+ end
178
+ assert_equal(text, actual)
179
+ end
180
+
181
+ def test_prefix_search
182
+ paths = Groonga::PatriciaTrie.create(:name => "Paths",
183
+ :key_type => 'ShortText')
184
+ root_path = paths.add('/')
185
+ tmp_path = paths.add('/tmp')
186
+ usr_bin_path = paths.add('/usr/bin')
187
+ usr_local_bin_path = paths.add('/usr/local/bin')
188
+
189
+ records = paths.prefix_search('/')
190
+ assert_equal(["/usr/local/bin", "/usr/bin", "/tmp", "/"],
191
+ records.records.collect {|record| record["._key"]})
192
+
193
+ records = paths.prefix_search('/usr')
194
+ assert_equal(["/usr/local/bin", "/usr/bin"],
195
+ records.records.collect {|record| record["._key"]})
196
+
197
+ records = paths.prefix_search('/usr/local')
198
+ assert_equal(["/usr/local/bin"],
199
+ records.records.collect {|record| record["._key"]})
200
+
201
+ records = paths.prefix_search('nonexistent')
202
+ assert_equal([],
203
+ records.records.collect {|record| record["._key"]})
204
+ end
205
+ end
@@ -0,0 +1,37 @@
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 ProcedureTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ setup :setup_database
20
+
21
+ def test_builtins
22
+ assert_equal_procedure("TokenDelimit", Groonga::Procedure::DELIMIT)
23
+ assert_equal_procedure("TokenUnigram", Groonga::Procedure::UNIGRAM)
24
+ assert_equal_procedure("TokenBigram", Groonga::Procedure::BIGRAM)
25
+ assert_equal_procedure("TokenTrigram", Groonga::Procedure::TRIGRAM)
26
+ assert_equal_procedure("TokenMecab", Groonga::Procedure::MECAB,
27
+ :accept_nil => true)
28
+ end
29
+
30
+ private
31
+ def assert_equal_procedure(expected_name, id, options={})
32
+ procedure = Groonga::Context.default[id]
33
+ expected_name = nil if procedure.nil? and options[:accept_nil]
34
+ assert_equal(expected_name,
35
+ procedure ? procedure.name : procedure)
36
+ end
37
+ end
@@ -0,0 +1,22 @@
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 QueryTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ def test_new
20
+ Groonga::Query.new("groonga text")
21
+ end
22
+ end
@@ -0,0 +1,243 @@
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 RecordTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ def setup
20
+ setup_database
21
+
22
+ setup_addresses_table
23
+ setup_users_table
24
+ setup_bookmarks_table
25
+ setup_indexes
26
+ end
27
+
28
+ def setup_addresses_table
29
+ @addresses = Groonga::Array.create(:name => "Addresses")
30
+ @addresses.define_column("mail", "ShortText")
31
+ end
32
+
33
+ def setup_users_table
34
+ @users = Groonga::Array.create(:name => "Users")
35
+ @users.define_column("name", "ShortText")
36
+ @users.define_column("addresses", @addresses, :type => "vector")
37
+ end
38
+
39
+ def setup_bookmarks_table
40
+ @bookmarks = Groonga::Array.create(:name => "Bookmarks",
41
+ :value_type => "Int32")
42
+ @bookmarks.define_column("uri", "ShortText")
43
+ @bookmarks.define_column("rate", "Int32")
44
+ @bookmarks.define_column("comment", "Text")
45
+ @bookmarks.define_column("content", "LongText")
46
+ @bookmarks.define_column("user", @users)
47
+ end
48
+
49
+ def setup_indexes
50
+ @bookmarks_index = Groonga::PatriciaTrie.create(:name => "BookmarksIndex")
51
+ @bookmarks_index.default_tokenizer = "TokenBigram"
52
+
53
+ @bookmarks_content_index =
54
+ @bookmarks_index.define_index_column("content", @bookmarks,
55
+ :with_section => true,
56
+ :with_weight => true,
57
+ :with_position => true,
58
+ :source => "Bookmarks.content")
59
+ @bookmarks_index.define_index_column("uri", @bookmarks,
60
+ :with_position => true,
61
+ :source => "Bookmarks.uri")
62
+ end
63
+
64
+ def test_column_accessor
65
+ groonga = @bookmarks.add
66
+
67
+ groonga["uri"] = "http://groonga.org/"
68
+ assert_equal("http://groonga.org/", groonga["uri"])
69
+
70
+ groonga["comment"] = "fulltext search engine"
71
+ assert_equal("fulltext search engine", groonga["comment"])
72
+ end
73
+
74
+ def test_have_column?
75
+ groonga = @bookmarks.add
76
+ assert_true(groonga.have_column?(:uri))
77
+ assert_false(groonga.have_column?(:nonexistent))
78
+ end
79
+
80
+ def test_get_nonexistent_column
81
+ groonga = @bookmarks.add
82
+ assert_raise(Groonga::NoSuchColumn) do
83
+ groonga["nonexistent"]
84
+ end
85
+ end
86
+
87
+ def test_set_nonexistent_column
88
+ groonga = @bookmarks.add
89
+ assert_raise(Groonga::NoSuchColumn) do
90
+ groonga["nonexistent"] = "value"
91
+ end
92
+ end
93
+
94
+ def test_set_object_id
95
+ groonga = @bookmarks.add
96
+ daijiro = @users.add
97
+ daijiro["name"] = "daijiro"
98
+ assert_nil(groonga["user"])
99
+ groonga["user"] = daijiro.id
100
+ assert_equal(daijiro, groonga["user"])
101
+ end
102
+
103
+ def test_set_nil
104
+ groonga = @bookmarks.add
105
+ groonga["content"] = nil
106
+ assert_nil(groonga["content"])
107
+ end
108
+
109
+ def test_delete
110
+ bookmark1 = @bookmarks.add
111
+ bookmark2 = @bookmarks.add
112
+ bookmark3 = @bookmarks.add
113
+
114
+ assert_equal(3, @bookmarks.size)
115
+ bookmark2.delete
116
+ assert_equal(2, @bookmarks.size)
117
+ end
118
+
119
+ def test_key
120
+ documents = Groonga::PatriciaTrie.create(:name => "Documents",
121
+ :key_type => "ShortText")
122
+ reference = documents.add("reference")
123
+ assert_equal("reference", reference.key)
124
+ end
125
+
126
+ def test_value
127
+ bookmark = @bookmarks.add
128
+ assert_equal(0, bookmark.value)
129
+ bookmark.value = 100
130
+ assert_equal(100, bookmark.value)
131
+ end
132
+
133
+ def test_reference_column?
134
+ bookmark = @bookmarks.add
135
+ assert_false(bookmark.reference_column?("uri"))
136
+ assert_true(bookmark.reference_column?("user"))
137
+ end
138
+
139
+ def test_score
140
+ groonga = @bookmarks.add
141
+ groonga["content"] = "full text search search search engine."
142
+
143
+ google = @bookmarks.add
144
+ google["content"] = "Web search engine."
145
+
146
+ results = @bookmarks_content_index.search("search")
147
+ assert_equal([[groonga.id, 3], [google.id, 1]],
148
+ results.collect do |record|
149
+ [record.id, record.score]
150
+ end)
151
+ end
152
+
153
+ def test_increment!
154
+ groonga = @bookmarks.add
155
+ assert_equal(0, groonga["rate"])
156
+ groonga.increment!("rate")
157
+ assert_equal(1, groonga["rate"])
158
+ groonga.increment!("rate", 2)
159
+ assert_equal(3, groonga["rate"])
160
+ groonga.increment!("rate", -2)
161
+ assert_equal(1, groonga["rate"])
162
+ end
163
+
164
+ def test_decrement!
165
+ groonga = @bookmarks.add
166
+ assert_equal(0, groonga["rate"])
167
+ groonga.decrement!("rate")
168
+ assert_equal(-1, groonga["rate"])
169
+ groonga.decrement!("rate", 2)
170
+ assert_equal(-3, groonga["rate"])
171
+ groonga.decrement!("rate", -2)
172
+ assert_equal(-1, groonga["rate"])
173
+ end
174
+
175
+ def test_lock
176
+ groonga = @bookmarks.add
177
+
178
+ assert_not_predicate(groonga, :locked?)
179
+ groonga.lock
180
+ assert_predicate(groonga, :locked?)
181
+ groonga.unlock
182
+ assert_not_predicate(groonga, :locked?)
183
+ end
184
+
185
+ def test_lock_failed
186
+ groonga = @bookmarks.add
187
+
188
+ groonga.lock
189
+ assert_raise(Groonga::ResourceDeadlockAvoided) do
190
+ groonga.lock
191
+ end
192
+ end
193
+
194
+ def test_lock_block
195
+ groonga = @bookmarks.add
196
+
197
+ assert_not_predicate(groonga, :locked?)
198
+ groonga.lock do
199
+ assert_predicate(groonga, :locked?)
200
+ end
201
+ assert_not_predicate(groonga, :locked?)
202
+ end
203
+
204
+ def test_clear_lock
205
+ groonga = @bookmarks.add
206
+
207
+ assert_not_predicate(groonga, :locked?)
208
+ groonga.lock
209
+ assert_predicate(groonga, :locked?)
210
+ groonga.clear_lock
211
+ assert_not_predicate(groonga, :locked?)
212
+ end
213
+
214
+ def test_attributes
215
+ values = {
216
+ "uri" => "http://groonga.org/",
217
+ "rate" => 5,
218
+ "comment" => "Grate!"
219
+ }
220
+ groonga = @bookmarks.add(values)
221
+ assert_equal(values.merge("id" => groonga.id,
222
+ "content" => nil,
223
+ "user" => nil),
224
+ groonga.attributes)
225
+ end
226
+
227
+ def test_dynamic_accessor
228
+ groonga = @bookmarks.add
229
+ assert_equal([],
230
+ ["uri", "uri="] - groonga.methods.collect {|name| name.to_s})
231
+ assert_equal([true, true],
232
+ [groonga.respond_to?(:uri),
233
+ groonga.respond_to?(:uri=)])
234
+ groonga.uri = "http://groonga.org/"
235
+ assert_equal("http://groonga.org/", groonga.uri)
236
+ end
237
+
238
+ def test_method_chain
239
+ morita = @users.add(:name => "morita")
240
+ groonga = @bookmarks.add(:user => morita, :uri => "http://groonga.org")
241
+ assert_equal("morita", groonga.user.name)
242
+ end
243
+ end