groonga 0.0.1

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 (148) hide show
  1. data/AUTHORS +1 -0
  2. data/NEWS.ja.rdoc +5 -0
  3. data/NEWS.rdoc +5 -0
  4. data/README.ja.rdoc +53 -0
  5. data/README.rdoc +54 -0
  6. data/Rakefile +209 -0
  7. data/TUTORIAL.ja.rdoc +160 -0
  8. data/benchmark/small-many-items.rb +175 -0
  9. data/example/bookmark.rb +38 -0
  10. data/ext/.gitignore +2 -0
  11. data/ext/rb-grn-accessor.c +52 -0
  12. data/ext/rb-grn-array-cursor.c +28 -0
  13. data/ext/rb-grn-array.c +168 -0
  14. data/ext/rb-grn-column.c +273 -0
  15. data/ext/rb-grn-context.c +333 -0
  16. data/ext/rb-grn-database.c +128 -0
  17. data/ext/rb-grn-encoding.c +163 -0
  18. data/ext/rb-grn-exception.c +1014 -0
  19. data/ext/rb-grn-hash-cursor.c +30 -0
  20. data/ext/rb-grn-hash.c +40 -0
  21. data/ext/rb-grn-logger.c +277 -0
  22. data/ext/rb-grn-object.c +985 -0
  23. data/ext/rb-grn-patricia-trie-cursor.c +30 -0
  24. data/ext/rb-grn-patricia-trie.c +40 -0
  25. data/ext/rb-grn-procedure.c +52 -0
  26. data/ext/rb-grn-query.c +207 -0
  27. data/ext/rb-grn-record.c +33 -0
  28. data/ext/rb-grn-snippet.c +274 -0
  29. data/ext/rb-grn-table-cursor-key-support.c +55 -0
  30. data/ext/rb-grn-table-cursor.c +294 -0
  31. data/ext/rb-grn-table-key-support.c +299 -0
  32. data/ext/rb-grn-table.c +706 -0
  33. data/ext/rb-grn-type.c +114 -0
  34. data/ext/rb-grn-utils.c +578 -0
  35. data/ext/rb-grn.h +346 -0
  36. data/ext/rb-groonga.c +98 -0
  37. data/extconf.rb +171 -0
  38. data/html/bar.svg +153 -0
  39. data/html/developer.html +121 -0
  40. data/html/developer.svg +469 -0
  41. data/html/download.svg +253 -0
  42. data/html/footer.html.erb +28 -0
  43. data/html/head.html.erb +4 -0
  44. data/html/header.html.erb +17 -0
  45. data/html/index.html +153 -0
  46. data/html/install.svg +636 -0
  47. data/html/logo.xcf +0 -0
  48. data/html/ranguba.css +248 -0
  49. data/html/tutorial.svg +559 -0
  50. data/lib/groonga.rb +50 -0
  51. data/lib/groonga/record.rb +98 -0
  52. data/license/GPL +340 -0
  53. data/license/LGPL +504 -0
  54. data/license/RUBY +59 -0
  55. data/pkg-config.rb +328 -0
  56. data/test-unit/Rakefile +35 -0
  57. data/test-unit/TODO +5 -0
  58. data/test-unit/bin/testrb +5 -0
  59. data/test-unit/html/classic.html +15 -0
  60. data/test-unit/html/index.html +25 -0
  61. data/test-unit/html/index.html.ja +27 -0
  62. data/test-unit/lib/test/unit.rb +342 -0
  63. data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
  64. data/test-unit/lib/test/unit/assertions.rb +1149 -0
  65. data/test-unit/lib/test/unit/attribute.rb +125 -0
  66. data/test-unit/lib/test/unit/autorunner.rb +306 -0
  67. data/test-unit/lib/test/unit/collector.rb +43 -0
  68. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  69. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  70. data/test-unit/lib/test/unit/collector/load.rb +135 -0
  71. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  72. data/test-unit/lib/test/unit/color-scheme.rb +86 -0
  73. data/test-unit/lib/test/unit/color.rb +96 -0
  74. data/test-unit/lib/test/unit/diff.rb +538 -0
  75. data/test-unit/lib/test/unit/error.rb +124 -0
  76. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  77. data/test-unit/lib/test/unit/failure.rb +110 -0
  78. data/test-unit/lib/test/unit/fixture.rb +176 -0
  79. data/test-unit/lib/test/unit/notification.rb +125 -0
  80. data/test-unit/lib/test/unit/omission.rb +143 -0
  81. data/test-unit/lib/test/unit/pending.rb +146 -0
  82. data/test-unit/lib/test/unit/priority.rb +161 -0
  83. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  84. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  85. data/test-unit/lib/test/unit/testcase.rb +360 -0
  86. data/test-unit/lib/test/unit/testresult.rb +89 -0
  87. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  88. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  89. data/test-unit/lib/test/unit/ui/console/testrunner.rb +220 -0
  90. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
  91. data/test-unit/lib/test/unit/ui/testrunner.rb +20 -0
  92. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  93. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  94. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  95. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  96. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  97. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  98. data/test-unit/lib/test/unit/version.rb +7 -0
  99. data/test-unit/sample/adder.rb +13 -0
  100. data/test-unit/sample/subtracter.rb +12 -0
  101. data/test-unit/sample/tc_adder.rb +18 -0
  102. data/test-unit/sample/tc_subtracter.rb +18 -0
  103. data/test-unit/sample/test_user.rb +22 -0
  104. data/test-unit/sample/ts_examples.rb +7 -0
  105. data/test-unit/test/collector/test-descendant.rb +135 -0
  106. data/test-unit/test/collector/test-load.rb +333 -0
  107. data/test-unit/test/collector/test_dir.rb +406 -0
  108. data/test-unit/test/collector/test_objectspace.rb +98 -0
  109. data/test-unit/test/run-test.rb +13 -0
  110. data/test-unit/test/test-attribute.rb +86 -0
  111. data/test-unit/test/test-color-scheme.rb +56 -0
  112. data/test-unit/test/test-color.rb +47 -0
  113. data/test-unit/test/test-diff.rb +477 -0
  114. data/test-unit/test/test-emacs-runner.rb +60 -0
  115. data/test-unit/test/test-fixture.rb +287 -0
  116. data/test-unit/test/test-notification.rb +33 -0
  117. data/test-unit/test/test-omission.rb +81 -0
  118. data/test-unit/test/test-pending.rb +70 -0
  119. data/test-unit/test/test-priority.rb +119 -0
  120. data/test-unit/test/test_assertions.rb +1082 -0
  121. data/test-unit/test/test_error.rb +26 -0
  122. data/test-unit/test/test_failure.rb +33 -0
  123. data/test-unit/test/test_testcase.rb +478 -0
  124. data/test-unit/test/test_testresult.rb +113 -0
  125. data/test-unit/test/test_testsuite.rb +129 -0
  126. data/test-unit/test/testunit-test-util.rb +14 -0
  127. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  128. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  129. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  130. data/test-unit/test/util/test_observable.rb +102 -0
  131. data/test-unit/test/util/test_procwrapper.rb +36 -0
  132. data/test/.gitignore +1 -0
  133. data/test/groonga-test-utils.rb +90 -0
  134. data/test/run-test.rb +54 -0
  135. data/test/test-column.rb +190 -0
  136. data/test/test-context.rb +90 -0
  137. data/test/test-database.rb +62 -0
  138. data/test/test-encoding.rb +33 -0
  139. data/test/test-exception.rb +85 -0
  140. data/test/test-procedure.rb +35 -0
  141. data/test/test-query.rb +22 -0
  142. data/test/test-record.rb +188 -0
  143. data/test/test-snippet.rb +121 -0
  144. data/test/test-table-cursor.rb +51 -0
  145. data/test/test-table.rb +447 -0
  146. data/test/test-type.rb +52 -0
  147. data/test/test-version.rb +31 -0
  148. metadata +213 -0
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ Kouhei Sutou <kou@clear-code.com>
data/NEWS.ja.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = お知らせ
2
+
3
+ == 0.0.1: 2009-04-30
4
+
5
+ * 最初のリリース!
data/NEWS.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = NEWS
2
+
3
+ == 0.0.1: 2009-04-30
4
+
5
+ * Initial release!
data/README.ja.rdoc ADDED
@@ -0,0 +1,53 @@
1
+ = はじめに
2
+
3
+ == 名前
4
+
5
+ Ruby/groonga
6
+
7
+ == 説明
8
+
9
+ 全文検索機能とカラムストア機能を提供するgroongaのRubyバイン
10
+ ディングです。
11
+
12
+ groongaのいわゆるDB-API層をRubyから使うための拡張ライブラリで
13
+ す。groongaのAPIをそのままRubyレベルに提供するのではなく、
14
+ Rubyらしく読み書きしやすいAPIとして提供します。高速・高機能な
15
+ groongaをRubyらしい書き方で利用できます。
16
+
17
+ groongaに関する情報は以下を参照して下さい。
18
+
19
+ * groonga: http://groonga.org/
20
+
21
+ == 作者
22
+
23
+ Kouhei Sutou <kou@clear-code.com>
24
+
25
+ == ライセンス
26
+
27
+ LGPL 2.1です。詳しくはlicense/LGPLを見てください。
28
+
29
+ pkg-config.rbはrcairoに付属しているもので、これはRubyライセ
30
+ ンスです。詳しくはlicense/RUBYとlicense/GPLを見てください。
31
+
32
+ == 依存ソフトウェア
33
+
34
+ * Ruby >= 1.8 (1.9.1対応)
35
+ * groonga >= 0.0.4
36
+
37
+ == インストール
38
+
39
+ % sudo gem install groonga
40
+
41
+ == ドキュメント
42
+
43
+ http://groonga.rubyforge.org/groonga/
44
+
45
+ == メーリングリスト
46
+
47
+ 質問、要望、バグ報告などはgroongaのMLにお願いします。
48
+
49
+ http://lists.sourceforge.jp/mailman/listinfo/groonga-dev
50
+
51
+ == 感謝
52
+
53
+ * ...
data/README.rdoc ADDED
@@ -0,0 +1,54 @@
1
+ = README
2
+
3
+ == Name
4
+
5
+ Ruby/groonga
6
+
7
+ == Description
8
+
9
+ Ruby bindings for groonga that provides full text search and
10
+ column store features.
11
+
12
+ Ruby/groonga is a extension library to use groonga's DB-API
13
+ layer. Ruby/groonga provides Rubyish readable and writable
14
+ API. You can use groonga's first and highly functional
15
+ features from Ruby.
16
+
17
+ See the following URL about groonga.
18
+
19
+ * groonga: http://groonga.org/
20
+
21
+ == Author
22
+
23
+ Kouhei Sutou <kou@clear-code.com>
24
+
25
+ == License
26
+
27
+ LGPL 2.1. See license/LGPL for details.
28
+
29
+ pkg-config.rb is a library that is bundled with rcairo. It's
30
+ distributed under Ruby license. See license/RUBY and
31
+ license/GPL for details.
32
+
33
+ == Dependencies
34
+
35
+ * Ruby >= 1.8 (including 1.9.1)
36
+ * groonga >= 0.0.4
37
+
38
+ == Install
39
+
40
+ % sudo gem install groonga
41
+
42
+ == Documents
43
+
44
+ Japanese only. Sorry.
45
+
46
+ http://groonga.rubyforge.org/groonga/
47
+
48
+ == Mailing list
49
+
50
+ http://rubyforge.org/mailman/listinfo/groonga-users-en
51
+
52
+ == Thanks
53
+
54
+ * ...
data/Rakefile ADDED
@@ -0,0 +1,209 @@
1
+ # -*- coding: utf-8; mode: ruby -*-
2
+ #
3
+ # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ require 'English'
19
+
20
+ require 'find'
21
+ require 'fileutils'
22
+ require 'pathname'
23
+ require 'erb'
24
+ require 'rubygems'
25
+ gem 'rdoc'
26
+ require 'hoe'
27
+
28
+ ENV["NODOT"] = "yes"
29
+
30
+ Hoe::SUPPORTED_TEST_FRAMEWORKS[:testunit2] = "test/run-test.rb"
31
+
32
+ base_dir = File.join(File.dirname(__FILE__))
33
+ truncate_base_dir = Proc.new do |x|
34
+ x.gsub(/^#{Regexp.escape(base_dir + File::SEPARATOR)}/, '')
35
+ end
36
+
37
+ groonga_ext_dir = File.join(base_dir, 'ext')
38
+ groonga_lib_dir = File.join(base_dir, 'lib')
39
+ $LOAD_PATH.unshift(groonga_ext_dir)
40
+ $LOAD_PATH.unshift(groonga_lib_dir)
41
+ ENV["RUBYLIB"] = "#{groonga_lib_dir}:#{groonga_ext_dir}:#{ENV['RUBYLIB']}"
42
+
43
+ def guess_version
44
+ require 'groonga'
45
+ Groonga.bindings_version
46
+ end
47
+
48
+ groonga_win32_dir = "groonga"
49
+ FileUtils.rm_rf(groonga_win32_dir)
50
+
51
+ manifest = File.join(base_dir, "Manifest.txt")
52
+ manifest_contents = []
53
+ base_dir_included_components = %w(AUTHORS Rakefile
54
+ README.rdoc README.ja.rdoc
55
+ NEWS.rdoc NEWS.ja.rdoc
56
+ TUTORIAL.ja.rdoc
57
+ extconf.rb pkg-config.rb)
58
+ excluded_components = %w(.cvsignore .gdb_history CVS depend Makefile pkg
59
+ .svn .git doc vendor .test-result)
60
+ excluded_suffixes = %w(.png .ps .pdf .o .so .a .txt .~)
61
+ Find.find(base_dir) do |target|
62
+ target = truncate_base_dir[target]
63
+ components = target.split(File::SEPARATOR)
64
+ if components.size == 1 and !File.directory?(target)
65
+ next unless base_dir_included_components.include?(components[0])
66
+ end
67
+ Find.prune if (excluded_components - components) != excluded_components
68
+ next if excluded_suffixes.include?(File.extname(target))
69
+ manifest_contents << target if File.file?(target)
70
+ end
71
+
72
+ File.open(manifest, "w") do |f|
73
+ f.puts manifest_contents.sort.join("\n")
74
+ end
75
+
76
+ # For Hoe's no user friendly default behavior. :<
77
+ File.open("README.txt", "w") {|file| file << "= Dummy README\n== XXX\n"}
78
+ FileUtils.cp("NEWS.rdoc", "History.txt")
79
+ at_exit do
80
+ FileUtils.rm_f("README.txt")
81
+ FileUtils.rm_f("History.txt")
82
+ FileUtils.rm_f(manifest)
83
+ end
84
+
85
+ def cleanup_white_space(entry)
86
+ entry.gsub(/(\A\n+|\n+\z)/, '') + "\n"
87
+ end
88
+
89
+ ENV["VERSION"] ||= guess_version
90
+ version = ENV["VERSION"]
91
+ project = Hoe.new('groonga', version) do |project|
92
+ project.rubyforge_name = 'groonga'
93
+ authors = File.join(base_dir, "AUTHORS")
94
+ project.author = File.readlines(authors).collect do |line|
95
+ if /\s*<[^<>]*>$/ =~ line
96
+ $PREMATCH
97
+ else
98
+ nil
99
+ end
100
+ end.compact
101
+ project.email = ['groonga-users-en@rubyforge.org',
102
+ 'groonga-dev@lists.sourceforge.jp']
103
+ project.url = 'http://groonga.rubyforge.org/'
104
+ project.testlib = :testunit2
105
+ project.test_globs = ["test/run-test.rb"]
106
+ project.spec_extras = {
107
+ :extensions => ['extconf.rb'],
108
+ :require_paths => ["lib", "ext"],
109
+ :extra_rdoc_files => Dir.glob("*.rdoc"),
110
+ }
111
+ project.readme_file = "README.ja.rdoc"
112
+
113
+ news_of_current_release = File.read("NEWS.rdoc").split(/^==\s.*$/)[1]
114
+ project.changes = cleanup_white_space(news_of_current_release)
115
+
116
+ entries = File.read("README.rdoc").split(/^==\s(.*)$/)
117
+ description = cleanup_white_space(entries[entries.index("Description") + 1])
118
+ project.summary, project.description, = description.split(/\n\n+/, 3)
119
+
120
+ project.need_tar = false
121
+ project.remote_rdoc_dir = "groonga"
122
+ end
123
+
124
+ project.spec.dependencies.delete_if {|dependency| dependency.name == "hoe"}
125
+
126
+ if /mswin32/ =~ project.spec.platform.to_s
127
+ project.spec.extensions = []
128
+ project.spec.files += ["ext/groonga.so", "ext/libruby-groonga.a"]
129
+
130
+ FileUtils.cp_r(File.expand_path("~/.wine/drive_c/groonga-dev"),
131
+ groonga_win32_dir)
132
+ groonga_files = []
133
+ Find.find(groonga_win32_dir) do |f|
134
+ groonga_files << f
135
+ end
136
+ project.spec.files += groonga_files
137
+ end
138
+
139
+ ObjectSpace.each_object(Rake::RDocTask) do |rdoc_task|
140
+ t_option_index = rdoc_task.options.index("-t")
141
+ rdoc_task.options[t_option_index, 2] = nil
142
+ rdoc_task.title = "Ruby/groonga - #{version}"
143
+
144
+ rdoc_task.rdoc_files = ["ext/rb-groonga.c"] + Dir.glob("ext/rb-grn-*.c")
145
+ rdoc_task.rdoc_files += Dir.glob("lib/*.rb")
146
+ rdoc_task.rdoc_files += Dir.glob("*.rdoc")
147
+ end
148
+
149
+ task :publish_docs => [:prepare_docs_for_publishing]
150
+
151
+
152
+ include ERB::Util
153
+
154
+ def apply_template(file, head, header, footer)
155
+ content = File.read(file)
156
+ content = content.sub(/lang="en"/, 'lang="ja"')
157
+
158
+ title = nil
159
+ content = content.sub(/<title>(.+?)<\/title>/) do
160
+ title = $1
161
+ head.result(binding)
162
+ end
163
+
164
+ content = content.sub(/<body(?:.*?)>/) do |body_start|
165
+ "#{body_start}\n#{header.result(binding)}\n"
166
+ end
167
+
168
+ content = content.sub(/<\/body/) do |body_end|
169
+ "\n#{footer.result(binding)}\n#{body_end}"
170
+ end
171
+
172
+ File.open(file, "w") do |file|
173
+ file.print(content)
174
+ end
175
+ end
176
+
177
+ def erb_template(name)
178
+ file = File.join("html", "#{name}.html.erb")
179
+ template = File.read(file)
180
+ erb = ERB.new(template, nil, "-")
181
+ erb.filename = file
182
+ erb
183
+ end
184
+
185
+ task :prepare_docs_for_publishing do
186
+ head = erb_template("head")
187
+ header = erb_template("header")
188
+ footer = erb_template("footer")
189
+ Find.find("doc") do |file|
190
+ if /\.html\z/ =~ file and /_(?:c|rb)\.html\z/ !~ file
191
+ apply_template(file, head, header, footer)
192
+ end
193
+ end
194
+ end
195
+
196
+ task :publish_html do
197
+ config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
198
+ host = "#{config["username"]}@rubyforge.org"
199
+
200
+ rsync_args = "-av --exclude '*.erb' --exclude '*.svg' --exclude .svn"
201
+ remote_dir = "/var/www/gforge-projects/#{project.rubyforge_name}/"
202
+ sh "rsync #{rsync_args} html/ #{host}:#{remote_dir}"
203
+ end
204
+
205
+ # fix Hoe's incorrect guess.
206
+ project.spec.executables.clear
207
+ # project.lib_files = project.spec.files.grep(%r|^src/lib/|)
208
+
209
+ task(:release).prerequisites.reject! {|name| name == "clean"}
data/TUTORIAL.ja.rdoc ADDED
@@ -0,0 +1,160 @@
1
+ = チュートリアル
2
+
3
+ このページでは簡単なアプリケーションの作成を通して
4
+ Ruby/groongaの新しいSennaの操作方法を紹介します。
5
+
6
+ == インストール
7
+
8
+ Ruby/groongaはRubyGemsでインストールできます。
9
+
10
+ % sudo gem install groonga
11
+
12
+ == データベースの作成
13
+
14
+ 簡単なブックマークアプリケーション用のデータベースを作ってみ
15
+ ます。以下のようにgroongaライブラリを読み込んでirbを起動しま
16
+ す。
17
+
18
+ % irb --simple-prompt -rubygems -rgroonga
19
+ >>
20
+
21
+ まず、エンコーディングを設定します。ここではUTF-8を利用します。
22
+
23
+ >> $KCODE = "UTF-8"
24
+ => "UTF-8"
25
+ >> Groonga::Context.default_options = {:encoding => :utf8}
26
+ => {:encoding=>:utf8}
27
+
28
+ それでは、ファイルを指定してデータベースを作成します。
29
+
30
+ >> Groonga::Database.create(:path => "/tmp/bookmark.db")
31
+ => #<Groonga::Database id: <nil>, name: (anonymous), path: </tmp/bookmark.db>, domain: <nil>, range: <nil>>
32
+
33
+ ここで作成したデータベースは、これ以降、暗黙のうちに利用され
34
+ ます。最初にデータベースを作成したら特に意識する必要はありま
35
+ せん。
36
+
37
+ == テーブルの定義
38
+
39
+ groongaには以下の3種類のテーブルがあります。
40
+
41
+ [Groonga::Hash]
42
+ ハッシュテーブル。主キーでレコードを管理します。キーと完全
43
+ 一致するレコードを非常に高速に検索することができます。
44
+ [Groonga::PatriciaTrie]
45
+ パトリシアトライ。ハッシュテーブルに比べて完全一致検索の速
46
+ 度がやや遅いですが、前方一致検索・共通接頭辞探索などの検索
47
+ が行えます。またカーソルを用いてキーの昇降順にレコードを取
48
+ り出すことができます。
49
+ [Groonga::Array]
50
+ 配列。主キーの存在しないテーブルです。レコードはIDによって
51
+ 識別します。
52
+
53
+ ここではハッシュテーブルを利用して、+<items>+という名前のテー
54
+ ブルを作成します。
55
+
56
+ >> items = Groonga::Hash.create(:name => "<items>", :persistent => true)
57
+ => #<Groonga::Hash id: <18>, name: <<items>>, path: </tmp/bookmark.db.0000012>, domain: <nil>, range: <nil>, encoding: <:utf8>, size: <0>>
58
+
59
+
60
+ これで+<items>+という名前のテーブルが作成できました。
61
+
62
+ テーブルはRubyのHashのように扱えます。
63
+
64
+ 例えば、以下のように+size+でテーブルに登録されているレコード
65
+ の件数を取得できます。
66
+
67
+ >> items.size
68
+ 0
69
+
70
+ == レコードを追加する
71
+
72
+ items>テーブルにレコードを追加します。
73
+
74
+ >> items.add("http://ja.wikipedia.org/wiki/Ruby")
75
+ => #<Groonga::Record:0x7f0ece6aeaf8 @table=#<Groonga::Hash id: <18>, name: <<items>>, path: </tmp/bookmark.db.0000012>, domain: <nil>, range: <nil>, encoding: <:utf8>, size: <1>>, @id=1>
76
+ >> items.add("http://www.ruby-lang.org/")
77
+ => #<Groonga::Record:0x7f0ece6a9fa8 @table=#<Groonga::Hash id: <18>, name: <<items>>, path: </tmp/bookmark.db.0000012>, domain: <nil>, range: <nil>, encoding: <:utf8>, size: <2>>, @id=2>
78
+
79
+ 件数を確認すると確かに2件増えています。
80
+
81
+ >> items.size
82
+ => 2
83
+
84
+ 主キーを指定してレコードを取り出す時には以下のようにします。
85
+
86
+ >> items["http://ja.wikipedia.org/wiki/Ruby"]
87
+ => #<Groonga::Record:0x7f0ece699ab8 @table=#<Groonga::Hash id: <18>, name: <<items>>, path: </tmp/bookmark.db.0000012>, domain: <nil>, range: <nil>, encoding: <:utf8>, size: <2>>, @id=1>
88
+
89
+ == 全文検索を行う
90
+
91
+ 各itemのタイトル文字列を登録して、全文検索できるようにしてみ
92
+ ましょう。
93
+
94
+ まず+<items>+テーブルに+title+という名前のカラムを追加します。
95
+
96
+ >> title_colum = items.define_column("title", "<text>")
97
+ => #<Groonga::VarSizeColumn id: <19>, name: <<items>.title>, path: (temporary), domain: <#<Groonga::Hash id: <18>, name: <<items>>, path: </tmp/bookmark.db.0000012>, domain: <nil>, range: <nil>, encoding: <:utf8>, size: <2>>>, range: <#<Groonga::Type id: <7>, name: <<text>>, path: (temporary), domain: <nil>, range: <65536>>>>
98
+
99
+ 2番目の引数は、追加するカラムのデータ型を示しています。
100
+ +<int>+、+<text>+、+<longtext>+等の型が基本型として用意されて
101
+ います。
102
+
103
+ 全文検索するためには、文字列を分解して得られる各単語を格納す
104
+ るためのテーブルを別途しなければなりません。ここでは<terms>と
105
+ いう名前でテーブルを定義します。
106
+
107
+ >> terms = Groonga::Hash.create(:name => "<terms>",
108
+ :key_type => "<shorttext>",
109
+ :persistent => true)
110
+ => #<Groonga::Hash id: <21>, name: <<terms>>, path: </tmp/bookmark.db.0000015>, domain: <#<Groonga::Type id: <6>, name: <<shorttext>>, path: (temporary), domain: <nil>, range: <4096>>>, range: <nil>, encoding: <:utf8>, size: <0>>
111
+
112
+ +<items>+テーブルの+title+カラムに対するインデックスを定義し
113
+ ます。
114
+
115
+ >> title_index_column = terms.define_column("item_title", items,
116
+ :type => "index",
117
+ :with_position => true)
118
+ => #<Groonga::IndexColumn id: <22>, name: <<terms>.item_title>, path: (temporary), domain: <#<Groonga::Hash id: <21>, name: <<terms>>, path: </tmp/bookmark.db.0000015>, domain: <#<Groonga::Type id: <6>, name: <<shorttext>>, path: (temporary), domain: <nil>, range: <4096>>>, range: <nil>, encoding: <:utf8>, size: <0>>>, range: <#<Groonga::Hash id: <18>, name: <<items>>, path: </tmp/bookmark.db.0000012>, domain: <nil>, range: <nil>, encoding: <:utf8>, size: <2>>>>
119
+
120
+ インデックス用カラムに、検索対象の+<items>+テーブルの+title+
121
+ カラムを設定します。
122
+
123
+ >> title_index_column.source = title_column
124
+ => #<Groonga::VarSizeColumn id: <19>, name: <<items>.title>, path: (temporary), domain: <#<Groonga::Hash id: <18>, name: <<items>>, path: </tmp/bookmark.db.0000012>, domain: <nil>, range: <nil>, encoding: <:utf8>, size: <2>>>, range: <#<Groonga::Type id: <7>, name: <<text>>, path: (temporary), domain: <nil>, range: <65536>>>>
125
+
126
+ 少し違和感を感じるかも知れませんが、+<items>+テーブルのカラムに
127
+ 対するインデックスは、 +<terms>+テーブルのカラムとして定義しま
128
+ す。
129
+
130
+ +<items>+にレコードが登録されると、その中に含まれる単語に該当
131
+ するレコードが+<terms>+に自動的に追加されるようになります。
132
+
133
+ +<terms>+は、文書に含まれる語彙に相当する、やや特殊なテーブル
134
+ だと言えます。しかし、他のテーブルと同様に語彙テーブルには自
135
+ 由にカラムを追加し、単語毎の様々な属性を管理することができま
136
+ す。これはある種の検索処理を行う際には非常に便利に機能します。
137
+
138
+ これでテーブルの定義は完了です。
139
+
140
+ 先ほど登録した各レコードの+title+カラムに値をセットします。
141
+
142
+ >> items["http://ja.wikipedia.org/wiki/Ruby"]["title"] = "Ruby"
143
+ => "Ruby"
144
+ >> items["http://www.ruby-lang.org/"]["title"] = "オブジェクトスクリプト言語Ruby"
145
+ "オブジェクトスクリプト言語Ruby"
146
+
147
+ 以下のようにして検索することができます。
148
+
149
+ >> title_index_column.saerch("Ruby").collect {|record| record.key.key}
150
+ ["http://ja.wikipedia.org/wiki/Ruby", "http://www.ruby-lang.org/"]
151
+
152
+ 検索結果はGroonga::Hashで返されます。ハッシュのキーに見つかっ
153
+ た+<items>+のレコードが入っています。上の例ではrecord.keyで
154
+ +<items>+のレコードを取得して、さらにそのキーを指定して
155
+ (record.key.key)で+<items>+のキーを返しています。
156
+
157
+
158
+ == マルチユーザ向けのブックマークアプリケーション
159
+
160
+ つづく。。。