rroonga 0.9.2-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +5 -0
- data/NEWS.ja.rdoc +114 -0
- data/NEWS.rdoc +116 -0
- data/README.ja.rdoc +65 -0
- data/README.rdoc +66 -0
- data/Rakefile +217 -0
- data/benchmark/common.rb +49 -0
- data/benchmark/read-write-many-small-items.rb +144 -0
- data/benchmark/write-many-small-items.rb +135 -0
- data/example/bookmark.rb +161 -0
- data/example/index-html.rb +89 -0
- data/example/search/config.ru +211 -0
- data/example/search/public/css/groonga.css +122 -0
- data/ext/.gitignore +2 -0
- data/ext/libruby-groonga.a +0 -0
- data/ext/rb-grn-accessor.c +52 -0
- data/ext/rb-grn-array-cursor.c +36 -0
- data/ext/rb-grn-array.c +210 -0
- data/ext/rb-grn-column.c +573 -0
- data/ext/rb-grn-context.c +655 -0
- data/ext/rb-grn-database.c +472 -0
- data/ext/rb-grn-encoding-support.c +64 -0
- data/ext/rb-grn-encoding.c +257 -0
- data/ext/rb-grn-exception.c +1110 -0
- data/ext/rb-grn-expression-builder.c +75 -0
- data/ext/rb-grn-expression.c +735 -0
- data/ext/rb-grn-fix-size-column.c +166 -0
- data/ext/rb-grn-hash-cursor.c +38 -0
- data/ext/rb-grn-hash.c +294 -0
- data/ext/rb-grn-index-column.c +488 -0
- data/ext/rb-grn-logger.c +504 -0
- data/ext/rb-grn-object.c +1369 -0
- data/ext/rb-grn-operation.c +198 -0
- data/ext/rb-grn-patricia-trie-cursor.c +39 -0
- data/ext/rb-grn-patricia-trie.c +488 -0
- data/ext/rb-grn-procedure.c +52 -0
- data/ext/rb-grn-query.c +260 -0
- data/ext/rb-grn-record.c +40 -0
- data/ext/rb-grn-snippet.c +334 -0
- data/ext/rb-grn-table-cursor-key-support.c +69 -0
- data/ext/rb-grn-table-cursor.c +247 -0
- data/ext/rb-grn-table-key-support.c +731 -0
- data/ext/rb-grn-table.c +2141 -0
- data/ext/rb-grn-type.c +181 -0
- data/ext/rb-grn-utils.c +769 -0
- data/ext/rb-grn-variable-size-column.c +36 -0
- data/ext/rb-grn-variable.c +108 -0
- data/ext/rb-grn-view-accessor.c +53 -0
- data/ext/rb-grn-view-cursor.c +35 -0
- data/ext/rb-grn-view-record.c +41 -0
- data/ext/rb-grn-view.c +421 -0
- data/ext/rb-grn.h +700 -0
- data/ext/rb-groonga.c +117 -0
- data/extconf.rb +266 -0
- data/html/bar.svg +153 -0
- data/html/developer.html +117 -0
- data/html/developer.svg +469 -0
- data/html/download.svg +253 -0
- data/html/favicon.ico +0 -0
- data/html/favicon.xcf +0 -0
- data/html/footer.html.erb +28 -0
- data/html/head.html.erb +4 -0
- data/html/header.html.erb +17 -0
- data/html/index.html +147 -0
- data/html/install.svg +636 -0
- data/html/logo.xcf +0 -0
- data/html/ranguba.css +250 -0
- data/html/tutorial.svg +559 -0
- data/lib/groonga.rb +90 -0
- data/lib/groonga/context.rb +184 -0
- data/lib/groonga/expression-builder.rb +285 -0
- data/lib/groonga/patricia-trie.rb +53 -0
- data/lib/groonga/record.rb +311 -0
- data/lib/groonga/schema.rb +1191 -0
- data/lib/groonga/view-record.rb +56 -0
- data/license/GPL +340 -0
- data/license/LGPL +504 -0
- data/license/RUBY +59 -0
- data/misc/grnop2ruby.rb +49 -0
- data/pkg-config.rb +333 -0
- data/test-unit/Rakefile +40 -0
- data/test-unit/TODO +5 -0
- data/test-unit/bin/testrb +5 -0
- data/test-unit/html/classic.html +15 -0
- data/test-unit/html/index.html +25 -0
- data/test-unit/html/index.html.ja +27 -0
- data/test-unit/lib/test/unit.rb +323 -0
- data/test-unit/lib/test/unit/assertionfailederror.rb +25 -0
- data/test-unit/lib/test/unit/assertions.rb +1230 -0
- data/test-unit/lib/test/unit/attribute.rb +125 -0
- data/test-unit/lib/test/unit/autorunner.rb +360 -0
- data/test-unit/lib/test/unit/collector.rb +36 -0
- data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
- data/test-unit/lib/test/unit/collector/dir.rb +108 -0
- data/test-unit/lib/test/unit/collector/load.rb +136 -0
- data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
- data/test-unit/lib/test/unit/color-scheme.rb +102 -0
- data/test-unit/lib/test/unit/color.rb +96 -0
- data/test-unit/lib/test/unit/diff.rb +724 -0
- data/test-unit/lib/test/unit/error.rb +130 -0
- data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
- data/test-unit/lib/test/unit/failure.rb +136 -0
- data/test-unit/lib/test/unit/fixture.rb +176 -0
- data/test-unit/lib/test/unit/notification.rb +129 -0
- data/test-unit/lib/test/unit/omission.rb +191 -0
- data/test-unit/lib/test/unit/pending.rb +150 -0
- data/test-unit/lib/test/unit/priority.rb +180 -0
- data/test-unit/lib/test/unit/runner/console.rb +52 -0
- data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
- data/test-unit/lib/test/unit/runner/tap.rb +8 -0
- data/test-unit/lib/test/unit/testcase.rb +476 -0
- data/test-unit/lib/test/unit/testresult.rb +89 -0
- data/test-unit/lib/test/unit/testsuite.rb +110 -0
- data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +466 -0
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +63 -0
- data/test-unit/lib/test/unit/ui/tap/testrunner.rb +92 -0
- data/test-unit/lib/test/unit/ui/testrunner.rb +28 -0
- data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
- data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
- data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
- data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
- data/test-unit/lib/test/unit/util/observable.rb +90 -0
- data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
- data/test-unit/lib/test/unit/version.rb +7 -0
- data/test-unit/sample/adder.rb +13 -0
- data/test-unit/sample/subtracter.rb +12 -0
- data/test-unit/sample/test_adder.rb +20 -0
- data/test-unit/sample/test_subtracter.rb +20 -0
- data/test-unit/sample/test_user.rb +23 -0
- data/test-unit/test/collector/test-descendant.rb +133 -0
- data/test-unit/test/collector/test-load.rb +348 -0
- data/test-unit/test/collector/test_dir.rb +406 -0
- data/test-unit/test/collector/test_objectspace.rb +100 -0
- data/test-unit/test/run-test.rb +15 -0
- data/test-unit/test/test-attribute.rb +86 -0
- data/test-unit/test/test-color-scheme.rb +67 -0
- data/test-unit/test/test-color.rb +47 -0
- data/test-unit/test/test-diff.rb +518 -0
- data/test-unit/test/test-emacs-runner.rb +60 -0
- data/test-unit/test/test-fixture.rb +287 -0
- data/test-unit/test/test-notification.rb +33 -0
- data/test-unit/test/test-omission.rb +81 -0
- data/test-unit/test/test-pending.rb +70 -0
- data/test-unit/test/test-priority.rb +119 -0
- data/test-unit/test/test-testcase.rb +544 -0
- data/test-unit/test/test_assertions.rb +1151 -0
- data/test-unit/test/test_error.rb +26 -0
- data/test-unit/test/test_failure.rb +33 -0
- data/test-unit/test/test_testresult.rb +113 -0
- data/test-unit/test/test_testsuite.rb +129 -0
- data/test-unit/test/testunit-test-util.rb +14 -0
- data/test-unit/test/ui/test_testrunmediator.rb +20 -0
- data/test-unit/test/util/test-method-owner-finder.rb +38 -0
- data/test-unit/test/util/test_backtracefilter.rb +41 -0
- data/test-unit/test/util/test_observable.rb +102 -0
- data/test-unit/test/util/test_procwrapper.rb +36 -0
- data/test/.gitignore +1 -0
- data/test/groonga-test-utils.rb +133 -0
- data/test/run-test.rb +58 -0
- data/test/test-array.rb +97 -0
- data/test/test-column.rb +316 -0
- data/test/test-context-select.rb +93 -0
- data/test/test-context.rb +73 -0
- data/test/test-database.rb +113 -0
- data/test/test-encoding.rb +33 -0
- data/test/test-exception.rb +93 -0
- data/test/test-expression-builder.rb +156 -0
- data/test/test-expression.rb +134 -0
- data/test/test-fix-size-column.rb +65 -0
- data/test/test-gqtp.rb +72 -0
- data/test/test-hash.rb +312 -0
- data/test/test-index-column.rb +81 -0
- data/test/test-logger.rb +37 -0
- data/test/test-patricia-trie.rb +189 -0
- data/test/test-procedure.rb +37 -0
- data/test/test-query.rb +22 -0
- data/test/test-record.rb +279 -0
- data/test/test-remote.rb +54 -0
- data/test/test-schema-view.rb +90 -0
- data/test/test-schema.rb +459 -0
- data/test/test-snippet.rb +130 -0
- data/test/test-table-cursor.rb +153 -0
- data/test/test-table-offset-and-limit.rb +102 -0
- data/test/test-table-select-normalize.rb +53 -0
- data/test/test-table-select.rb +150 -0
- data/test/test-table.rb +690 -0
- data/test/test-type.rb +71 -0
- data/test/test-variable-size-column.rb +98 -0
- data/test/test-variable.rb +28 -0
- data/test/test-vector-column.rb +76 -0
- data/test/test-version.rb +31 -0
- data/test/test-view.rb +72 -0
- data/text/TUTORIAL.ja.rdoc +392 -0
- data/text/expression.rdoc +284 -0
- data/vendor/local/bin/grntest.exe +0 -0
- data/vendor/local/bin/groonga.exe +0 -0
- data/vendor/local/bin/libgroonga.dll +0 -0
- data/vendor/local/bin/libmecab.dll +0 -0
- data/vendor/local/include/groonga.h +2285 -0
- data/vendor/local/lib/libgroonga.lib +0 -0
- metadata +280 -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
|
data/test/test-logger.rb
ADDED
@@ -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,189 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
|
3
|
+
#
|
4
|
+
# This library is free software; you can redistribute it and/or
|
5
|
+
# modify it under the terms of the GNU Lesser General Public
|
6
|
+
# License version 2.1 as published by the Free Software Foundation.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
16
|
+
|
17
|
+
class PatriciaTrieTest < Test::Unit::TestCase
|
18
|
+
include GroongaTestUtils
|
19
|
+
|
20
|
+
setup :setup_database
|
21
|
+
|
22
|
+
def test_encoding
|
23
|
+
assert_equal(Groonga::Encoding.default,
|
24
|
+
Groonga::PatriciaTrie.create.encoding)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_tokenizer
|
28
|
+
trie = Groonga::PatriciaTrie.create
|
29
|
+
assert_nil(trie.default_tokenizer)
|
30
|
+
trie.default_tokenizer = "TokenTrigram"
|
31
|
+
assert_equal(Groonga::Context.default["TokenTrigram"],
|
32
|
+
trie.default_tokenizer)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_search
|
36
|
+
users = Groonga::Array.create(:name => "Users")
|
37
|
+
user_name = users.define_column("name", "ShortText")
|
38
|
+
|
39
|
+
bookmarks = Groonga::PatriciaTrie.create(:name => "Bookmarks",
|
40
|
+
:key_type => "ShortText")
|
41
|
+
bookmark_user_id = bookmarks.define_column("user_id", users)
|
42
|
+
|
43
|
+
daijiro = users.add
|
44
|
+
daijiro["name"] = "daijiro"
|
45
|
+
gunyarakun = users.add
|
46
|
+
gunyarakun["name"] = "gunyarakun"
|
47
|
+
|
48
|
+
groonga = bookmarks.add("http://groonga.org/")
|
49
|
+
groonga["user_id"] = daijiro
|
50
|
+
|
51
|
+
records = bookmarks.search("http://groonga.org/")
|
52
|
+
assert_equal(["daijiro"],
|
53
|
+
records.records.collect {|record| record[".user_id.name"]})
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_add
|
57
|
+
users = Groonga::PatriciaTrie.create(:name => "Users")
|
58
|
+
users.define_column("address", "<text>")
|
59
|
+
me = users.add("me", :address => "me@example.com")
|
60
|
+
assert_equal("me@example.com", me[:address])
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_default_tokenizer_on_create
|
64
|
+
terms = Groonga::PatriciaTrie.create(:name => "Terms",
|
65
|
+
:default_tokenizer => "TokenUnigram")
|
66
|
+
assert_equal(context[Groonga::Type::UNIGRAM],
|
67
|
+
terms.default_tokenizer)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_duplicated_name
|
71
|
+
Groonga::PatriciaTrie.create(:name => "Users")
|
72
|
+
assert_raise(Groonga::InvalidArgument) do
|
73
|
+
Groonga::PatriciaTrie.create(:name => "Users")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_open_same_name
|
78
|
+
users_created = Groonga::PatriciaTrie.create(:name => "Users")
|
79
|
+
users_opened = Groonga::PatriciaTrie.open(:name => "Users")
|
80
|
+
users_opened.add("morita")
|
81
|
+
assert_equal(1, users_created.size)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_has_key?
|
85
|
+
users = Groonga::PatriciaTrie.create(:name => "Users")
|
86
|
+
assert_false(users.has_key?("morita"))
|
87
|
+
users.add("morita")
|
88
|
+
assert_true(users.has_key?("morita"))
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_scan
|
92
|
+
Groonga::Context.default_options = {:encoding => "utf-8"}
|
93
|
+
words = Groonga::PatriciaTrie.create(:key_type => "ShortText",
|
94
|
+
:key_normalize => true)
|
95
|
+
words.add("リンク")
|
96
|
+
arupaka = words.add("アルパカ")
|
97
|
+
words.add("アルパカ(生物)")
|
98
|
+
adventure_of_link = words.add('リンクの冒険')
|
99
|
+
words.add('冒険')
|
100
|
+
gaxtu = words.add('ガッ')
|
101
|
+
muteki = words.add('MUTEKI')
|
102
|
+
assert_equal([[muteki, "muTEki", 0, 6],
|
103
|
+
[adventure_of_link, "リンクの冒険", 7, 18],
|
104
|
+
[arupaka, "アルパカ", 42, 12],
|
105
|
+
[gaxtu, "ガッ", 55, 6]],
|
106
|
+
words.scan('muTEki リンクの冒険 ミリバール アルパカ ガッ'))
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_tag_keys
|
110
|
+
Groonga::Context.default_options = {:encoding => "utf-8"}
|
111
|
+
words = Groonga::PatriciaTrie.create(:key_type => "ShortText",
|
112
|
+
:key_normalize => true)
|
113
|
+
words.add('リンク')
|
114
|
+
words.add('リンクの冒険')
|
115
|
+
words.add('冒険')
|
116
|
+
words.add('㍊')
|
117
|
+
words.add('ガッ')
|
118
|
+
words.add('MUTEKI')
|
119
|
+
|
120
|
+
text = 'muTEki リンクの冒険 マッチしない ミリバール ガッ おわり'
|
121
|
+
actual = words.tag_keys(text) do |record, word|
|
122
|
+
"<#{word}(#{record.key})>"
|
123
|
+
end
|
124
|
+
assert_equal("<muTEki(muteki)> " +
|
125
|
+
"<リンクの冒険(リンクの冒険)> " +
|
126
|
+
"マッチしない " +
|
127
|
+
"<ミリバール(ミリバール)> " +
|
128
|
+
"<ガッ(ガッ)> " +
|
129
|
+
"おわり",
|
130
|
+
actual)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_tag_keys_with_last_match
|
134
|
+
Groonga::Context.default_options = {:encoding => "utf-8"}
|
135
|
+
words = Groonga::PatriciaTrie.create(:key_type => "ShortText",
|
136
|
+
:key_normalize => true)
|
137
|
+
words.add('ガッ')
|
138
|
+
words.add('MUTEKI')
|
139
|
+
|
140
|
+
text = 'muTEki マッチしない ガッ'
|
141
|
+
actual = words.tag_keys(text) do |record, word|
|
142
|
+
"<#{word}(#{record.key})>"
|
143
|
+
end
|
144
|
+
assert_equal("<muTEki(muteki)> " +
|
145
|
+
"マッチしない " +
|
146
|
+
"<ガッ(ガッ)>",
|
147
|
+
actual)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_tag_keys_with_no_match
|
151
|
+
Groonga::Context.default_options = {:encoding => "utf-8"}
|
152
|
+
words = Groonga::PatriciaTrie.create(:key_type => "ShortText",
|
153
|
+
:key_normalize => true)
|
154
|
+
|
155
|
+
words.add('無敵')
|
156
|
+
words.add('BOUKEN')
|
157
|
+
|
158
|
+
text = 'muTEki リンクの冒険'
|
159
|
+
actual = words.tag_keys(text) do |record, word|
|
160
|
+
"<#{word}(#{record.key})>"
|
161
|
+
end
|
162
|
+
assert_equal(text, actual)
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_prefix_search
|
166
|
+
paths = Groonga::PatriciaTrie.create(:name => "Paths",
|
167
|
+
:key_type => 'ShortText')
|
168
|
+
root_path = paths.add('/')
|
169
|
+
tmp_path = paths.add('/tmp')
|
170
|
+
usr_bin_path = paths.add('/usr/bin')
|
171
|
+
usr_local_bin_path = paths.add('/usr/local/bin')
|
172
|
+
|
173
|
+
records = paths.prefix_search('/')
|
174
|
+
assert_equal(["/usr/local/bin", "/usr/bin", "/tmp", "/"],
|
175
|
+
records.records.collect {|record| record["._key"]})
|
176
|
+
|
177
|
+
records = paths.prefix_search('/usr')
|
178
|
+
assert_equal(["/usr/local/bin", "/usr/bin"],
|
179
|
+
records.records.collect {|record| record["._key"]})
|
180
|
+
|
181
|
+
records = paths.prefix_search('/usr/local')
|
182
|
+
assert_equal(["/usr/local/bin"],
|
183
|
+
records.records.collect {|record| record["._key"]})
|
184
|
+
|
185
|
+
records = paths.prefix_search('nonexistent')
|
186
|
+
assert_equal([],
|
187
|
+
records.records.collect {|record| record["._key"]})
|
188
|
+
end
|
189
|
+
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
|
data/test/test-query.rb
ADDED
@@ -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
|
data/test/test-record.rb
ADDED
@@ -0,0 +1,279 @@
|
|
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_path = @tables_dir + "addresses"
|
30
|
+
@addresses = Groonga::Array.create(:name => "Addresses",
|
31
|
+
:path => @addresses_path.to_s)
|
32
|
+
|
33
|
+
@addresses_mail_column_path = @columns_dir + "mail"
|
34
|
+
@addresses_mail_column =
|
35
|
+
@addresses.define_column("mail", "ShortText",
|
36
|
+
:path => @addresses_mail_column_path.to_s)
|
37
|
+
end
|
38
|
+
|
39
|
+
def setup_users_table
|
40
|
+
@users_path = @tables_dir + "users"
|
41
|
+
@users = Groonga::Array.create(:name => "Users",
|
42
|
+
:path => @users_path.to_s)
|
43
|
+
|
44
|
+
@users_name_column_path = @columns_dir + "name"
|
45
|
+
@users_name_column =
|
46
|
+
@users.define_column("name", "ShortText",
|
47
|
+
:path => @users_name_column_path.to_s)
|
48
|
+
|
49
|
+
@users_addresses_column_path = @columns_dir + "addresses"
|
50
|
+
@users_addresses_column =
|
51
|
+
@users.define_column("addresses", @addresses,
|
52
|
+
:path => @users_addresses_column_path.to_s,
|
53
|
+
:type => "vector")
|
54
|
+
end
|
55
|
+
|
56
|
+
def setup_bookmarks_table
|
57
|
+
@bookmarks_path = @tables_dir + "bookmarks"
|
58
|
+
@bookmarks = Groonga::Array.create(:name => "Bookmarks",
|
59
|
+
:value_type => "Int32",
|
60
|
+
:path => @bookmarks_path.to_s)
|
61
|
+
|
62
|
+
@uri_column_path = @columns_dir + "uri"
|
63
|
+
@bookmarks_uri = @bookmarks.define_column("uri", "ShortText",
|
64
|
+
:path => @uri_column_path.to_s)
|
65
|
+
|
66
|
+
@rate_column_path = @columns_dir + "rate"
|
67
|
+
@bookmarks_rate = @bookmarks.define_column("rate", "Int32",
|
68
|
+
:path => @rate_column_path.to_s)
|
69
|
+
|
70
|
+
@comment_column_path = @columns_dir + "comment"
|
71
|
+
@bookmarks_comment =
|
72
|
+
@bookmarks.define_column("comment", "Text",
|
73
|
+
:path => @comment_column_path.to_s)
|
74
|
+
|
75
|
+
@content_column_path = @columns_dir + "content"
|
76
|
+
@bookmarks_content = @bookmarks.define_column("content", "LongText")
|
77
|
+
|
78
|
+
@user_column_path = @columns_dir + "user"
|
79
|
+
@bookmarks_user = @bookmarks.define_column("user", @users)
|
80
|
+
end
|
81
|
+
|
82
|
+
def setup_indexes
|
83
|
+
@bookmarks_index_path = @tables_dir + "bookmarks-index"
|
84
|
+
@bookmarks_index =
|
85
|
+
Groonga::PatriciaTrie.create(:name => "BookmarksIndex",
|
86
|
+
:path => @bookmarks_index_path.to_s)
|
87
|
+
@bookmarks_index.default_tokenizer = "TokenBigram"
|
88
|
+
|
89
|
+
@content_index_column_path = @columns_dir + "content-index"
|
90
|
+
@bookmarks_content_index =
|
91
|
+
@bookmarks_index.define_index_column("content", @bookmarks,
|
92
|
+
:with_section => true,
|
93
|
+
:with_weight => true,
|
94
|
+
:with_position => true,
|
95
|
+
:path => @content_index_column_path.to_s)
|
96
|
+
@bookmarks_content_index.source = @bookmarks_content
|
97
|
+
|
98
|
+
@uri_index_column_path = @columns_dir + "uri-index"
|
99
|
+
@bookmarks_uri_index =
|
100
|
+
@bookmarks_index.define_index_column("uri", @bookmarks,
|
101
|
+
:with_position => true,
|
102
|
+
:path => @uri_index_column_path.to_s)
|
103
|
+
@bookmarks_uri_index.source = @bookmarks_uri
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_column_accessor
|
107
|
+
groonga = @bookmarks.add
|
108
|
+
|
109
|
+
groonga["uri"] = "http://groonga.org/"
|
110
|
+
assert_equal("http://groonga.org/", groonga["uri"])
|
111
|
+
|
112
|
+
groonga["comment"] = "fulltext search engine"
|
113
|
+
assert_equal("fulltext search engine", groonga["comment"])
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_have_column?
|
117
|
+
groonga = @bookmarks.add
|
118
|
+
assert_true(groonga.have_column?(:uri))
|
119
|
+
assert_false(groonga.have_column?(:nonexistent))
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_get_nonexistent_column
|
123
|
+
groonga = @bookmarks.add
|
124
|
+
assert_raise(Groonga::NoSuchColumn) do
|
125
|
+
groonga["nonexistent"]
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_set_nonexistent_column
|
130
|
+
groonga = @bookmarks.add
|
131
|
+
assert_raise(Groonga::NoSuchColumn) do
|
132
|
+
groonga["nonexistent"] = "value"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_set_object_id
|
137
|
+
groonga = @bookmarks.add
|
138
|
+
daijiro = @users.add
|
139
|
+
daijiro["name"] = "daijiro"
|
140
|
+
assert_nil(groonga["user"])
|
141
|
+
groonga["user"] = daijiro.id
|
142
|
+
assert_equal(daijiro, groonga["user"])
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_set_nil
|
146
|
+
groonga = @bookmarks.add
|
147
|
+
groonga["content"] = nil
|
148
|
+
assert_nil(groonga["content"])
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_delete
|
152
|
+
bookmark1 = @bookmarks.add
|
153
|
+
bookmark2 = @bookmarks.add
|
154
|
+
bookmark3 = @bookmarks.add
|
155
|
+
|
156
|
+
assert_equal(3, @bookmarks.size)
|
157
|
+
bookmark2.delete
|
158
|
+
assert_equal(2, @bookmarks.size)
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_key
|
162
|
+
documents = Groonga::PatriciaTrie.create(:name => "Documents",
|
163
|
+
:key_type => "ShortText")
|
164
|
+
reference = documents.add("reference")
|
165
|
+
assert_equal("reference", reference.key)
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_value
|
169
|
+
bookmark = @bookmarks.add
|
170
|
+
assert_equal(0, bookmark.value)
|
171
|
+
bookmark.value = 100
|
172
|
+
assert_equal(100, bookmark.value)
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_reference_column?
|
176
|
+
bookmark = @bookmarks.add
|
177
|
+
assert_false(bookmark.reference_column?("uri"))
|
178
|
+
assert_true(bookmark.reference_column?("user"))
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_score
|
182
|
+
groonga = @bookmarks.add
|
183
|
+
groonga["content"] = "full text search search search engine."
|
184
|
+
|
185
|
+
google = @bookmarks.add
|
186
|
+
google["content"] = "Web search engine."
|
187
|
+
|
188
|
+
results = @bookmarks_content_index.search("search")
|
189
|
+
assert_equal([[groonga.id, 3], [google.id, 1]],
|
190
|
+
results.collect do |record|
|
191
|
+
[record.id, record.score]
|
192
|
+
end)
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_increment!
|
196
|
+
groonga = @bookmarks.add
|
197
|
+
assert_equal(0, groonga["rate"])
|
198
|
+
groonga.increment!("rate")
|
199
|
+
assert_equal(1, groonga["rate"])
|
200
|
+
groonga.increment!("rate", 2)
|
201
|
+
assert_equal(3, groonga["rate"])
|
202
|
+
groonga.increment!("rate", -2)
|
203
|
+
assert_equal(1, groonga["rate"])
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_decrement!
|
207
|
+
groonga = @bookmarks.add
|
208
|
+
assert_equal(0, groonga["rate"])
|
209
|
+
groonga.decrement!("rate")
|
210
|
+
assert_equal(-1, groonga["rate"])
|
211
|
+
groonga.decrement!("rate", 2)
|
212
|
+
assert_equal(-3, groonga["rate"])
|
213
|
+
groonga.decrement!("rate", -2)
|
214
|
+
assert_equal(-1, groonga["rate"])
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_lock
|
218
|
+
groonga = @bookmarks.add
|
219
|
+
|
220
|
+
assert_not_predicate(groonga, :locked?)
|
221
|
+
groonga.lock
|
222
|
+
assert_predicate(groonga, :locked?)
|
223
|
+
groonga.unlock
|
224
|
+
assert_not_predicate(groonga, :locked?)
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_lock_failed
|
228
|
+
groonga = @bookmarks.add
|
229
|
+
|
230
|
+
groonga.lock
|
231
|
+
assert_raise(Groonga::ResourceDeadlockAvoided) do
|
232
|
+
groonga.lock
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_lock_block
|
237
|
+
groonga = @bookmarks.add
|
238
|
+
|
239
|
+
assert_not_predicate(groonga, :locked?)
|
240
|
+
groonga.lock do
|
241
|
+
assert_predicate(groonga, :locked?)
|
242
|
+
end
|
243
|
+
assert_not_predicate(groonga, :locked?)
|
244
|
+
end
|
245
|
+
|
246
|
+
def test_clear_lock
|
247
|
+
groonga = @bookmarks.add
|
248
|
+
|
249
|
+
assert_not_predicate(groonga, :locked?)
|
250
|
+
groonga.lock
|
251
|
+
assert_predicate(groonga, :locked?)
|
252
|
+
groonga.clear_lock
|
253
|
+
assert_not_predicate(groonga, :locked?)
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_attributes
|
257
|
+
values = {
|
258
|
+
"uri" => "http://groonga.org/",
|
259
|
+
"rate" => 5,
|
260
|
+
"comment" => "Grate!"
|
261
|
+
}
|
262
|
+
groonga = @bookmarks.add(values)
|
263
|
+
assert_equal(values.merge("id" => groonga.id,
|
264
|
+
"content" => nil,
|
265
|
+
"user" => nil),
|
266
|
+
groonga.attributes)
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_dynamic_accessor
|
270
|
+
groonga = @bookmarks.add
|
271
|
+
assert_equal([],
|
272
|
+
["uri", "uri="] - groonga.methods.collect {|name| name.to_s})
|
273
|
+
assert_equal([true, true],
|
274
|
+
[groonga.respond_to?(:uri),
|
275
|
+
groonga.respond_to?(:uri=)])
|
276
|
+
groonga.uri = "http://groonga.org/"
|
277
|
+
assert_equal("http://groonga.org/", groonga.uri)
|
278
|
+
end
|
279
|
+
end
|