groonga 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/NEWS.ja.rdoc +18 -3
  2. data/NEWS.rdoc +18 -3
  3. data/README.ja.rdoc +2 -0
  4. data/README.rdoc +2 -0
  5. data/Rakefile +14 -5
  6. data/TUTORIAL.ja.rdoc +82 -16
  7. data/benchmark/{read-write-small-many-items.rb → read-write-many-small-items.rb} +26 -23
  8. data/benchmark/{write-small-many-items.rb → write-many-small-items.rb} +26 -23
  9. data/example/bookmark.rb +49 -5
  10. data/ext/rb-grn-array.c +11 -1
  11. data/ext/rb-grn-column.c +132 -5
  12. data/ext/rb-grn-context.c +85 -80
  13. data/ext/rb-grn-database.c +182 -9
  14. data/ext/rb-grn-expression-builder.c +69 -0
  15. data/ext/rb-grn-expression.c +314 -0
  16. data/ext/rb-grn-fix-size-column.c +68 -89
  17. data/ext/rb-grn-hash.c +14 -5
  18. data/ext/rb-grn-index-column.c +14 -55
  19. data/ext/rb-grn-object.c +206 -75
  20. data/ext/rb-grn-operation.c +92 -0
  21. data/ext/rb-grn-patricia-trie.c +10 -32
  22. data/ext/rb-grn-query.c +9 -9
  23. data/ext/rb-grn-table-cursor.c +19 -80
  24. data/ext/rb-grn-table-key-support.c +33 -39
  25. data/ext/rb-grn-table.c +436 -79
  26. data/ext/rb-grn-type.c +10 -3
  27. data/ext/rb-grn-utils.c +131 -4
  28. data/ext/rb-grn-variable-size-column.c +36 -0
  29. data/ext/rb-grn-variable.c +90 -0
  30. data/ext/rb-grn.h +109 -56
  31. data/ext/rb-groonga.c +4 -0
  32. data/extconf.rb +39 -13
  33. data/html/index.html +2 -2
  34. data/lib/groonga.rb +22 -0
  35. data/lib/groonga/expression-builder.rb +141 -0
  36. data/lib/groonga/record.rb +25 -1
  37. data/lib/groonga/schema.rb +418 -0
  38. data/test/test-column.rb +11 -23
  39. data/test/test-context.rb +1 -1
  40. data/test/test-database.rb +60 -19
  41. data/test/test-expression-builder.rb +114 -0
  42. data/test/test-expression.rb +55 -0
  43. data/test/test-fix-size-column.rb +53 -0
  44. data/test/test-hash.rb +10 -3
  45. data/test/test-index-column.rb +24 -0
  46. data/test/test-patricia-trie.rb +9 -0
  47. data/test/test-procedure.rb +5 -5
  48. data/test/test-record.rb +71 -4
  49. data/test/test-schema.rb +207 -0
  50. data/test/test-table.rb +94 -12
  51. data/test/test-type.rb +18 -11
  52. data/test/test-variable-size-column.rb +53 -0
  53. data/test/test-variable.rb +28 -0
  54. metadata +18 -5
data/NEWS.ja.rdoc CHANGED
@@ -1,15 +1,30 @@
1
1
  = お知らせ
2
2
 
3
+ == 0.0.3: 2009-07-18
4
+
5
+ * [#26145] Groonga::TableKeySupport#has_key?の追加 [Tasuku SUENAGA]
6
+ * [#26146] カラム名が存在しない場合はGroonga::Record#[]が例外
7
+ をあげるように変更 [Tasuku SUENAGA]
8
+ * 32ビット環境をサポート [niku]
9
+ * N-gramインデックスサーチのテストを追加 [dara]
10
+ * APIの追加
11
+ * Groonga::Record#incemrent!
12
+ * Groonga::Record#decemrent!
13
+ * Groonga::Record#lock
14
+ * Groonga::Table#lock
15
+ * Groonga::Schema: スキーマ定義用DSL
16
+ * Groonga::Expression
17
+
3
18
  == 0.0.2: 2009-06-04
4
19
 
5
- * groonga 0.0.9対応 [mori]
20
+ * groonga 0.0.8対応 [mori]
6
21
  * 性能向上: キー、値、ドメイン、レンジをキャッシュ
7
22
  * API改良
8
23
  * ドキュメントの追加
9
24
  * Ruby 1.9対応
10
25
  * バグ修正:
11
- ** インストール処理の修正 [Tasuku SUENAGA]
12
- ** メモリリーク修正
26
+ * インストール処理の修正 [Tasuku SUENAGA]
27
+ * メモリリーク修正
13
28
 
14
29
  == 0.0.1: 2009-04-30
15
30
 
data/NEWS.rdoc CHANGED
@@ -1,15 +1,30 @@
1
1
  = NEWS
2
2
 
3
+ == 0.0.3: 2009-07-18
4
+
5
+ * [#26145] Added Groonga::TableKeySupport#has_key? [Tasuku SUENAGA]
6
+ * [#26146] Groonga::Record#[] raises an exception for nonexistent
7
+ column name. [Tasuku SUENAGA]
8
+ * Supported 32bit environment [niku]
9
+ * Added a test for N-gram index search [dara]
10
+ * Added APIs
11
+ * Groonga::Record#incemrent!
12
+ * Groonga::Record#decemrent!
13
+ * Groonga::Record#lock
14
+ * Groonga::Table#lock
15
+ * Groonga::Schema: A DSL for schema definition
16
+ * Groonga::Expression
17
+
3
18
  == 0.0.2: 2009-06-04
4
19
 
5
- * Supported groonga 0.0.9 [mori]
20
+ * Supported groonga 0.0.8 [mori]
6
21
  * Improved preformance: cache key, value, domain and range
7
22
  * Improved API
8
23
  * Added documents
9
24
  * Supported Ruby 1.9
10
25
  * Bug fixes:
11
- ** Fixed install process [Tasuku SUENAGA]
12
- ** Fixed memory leaks
26
+ * Fixed install process [Tasuku SUENAGA]
27
+ * Fixed memory leaks
13
28
 
14
29
  == 0.0.1: 2009-04-30
15
30
 
data/README.ja.rdoc CHANGED
@@ -52,3 +52,5 @@ http://lists.sourceforge.jp/mailman/listinfo/groonga-dev
52
52
 
53
53
  * 森さん: 最新groonga対応パッチをくれました。
54
54
  * グニャラくん: バグレポートしてくれました。
55
+ * にくさん: バグレポートしてくれました。
56
+ * daraさん: テストを書いてくれました。
data/README.rdoc CHANGED
@@ -53,3 +53,5 @@ http://rubyforge.org/mailman/listinfo/groonga-users-en
53
53
 
54
54
  * mori: sent patches to support the latest groonga.
55
55
  * Tasuku SUENAGA: sent bug reports.
56
+ * niku: sent bug reports.
57
+ * dara: wrote tests.
data/Rakefile CHANGED
@@ -27,8 +27,6 @@ require 'hoe'
27
27
 
28
28
  ENV["NODOT"] = "yes"
29
29
 
30
- Hoe::Test::SUPPORTED_TEST_FRAMEWORKS[:testunit2] = "test/run-test.rb"
31
-
32
30
  base_dir = File.join(File.dirname(__FILE__))
33
31
  truncate_base_dir = Proc.new do |x|
34
32
  x.gsub(/^#{Regexp.escape(base_dir + File::SEPARATOR)}/, '')
@@ -88,7 +86,11 @@ end
88
86
 
89
87
  ENV["VERSION"] ||= guess_version
90
88
  version = ENV["VERSION"]
91
- project = Hoe.new('groonga', version) do |project|
89
+ project = nil
90
+ Hoe.spec('groonga') do |_project|
91
+ Hoe::Test::SUPPORTED_TEST_FRAMEWORKS[:testunit2] = "test/run-test.rb"
92
+ project = _project
93
+ project.version = version
92
94
  project.rubyforge_name = 'groonga'
93
95
  authors = File.join(base_dir, "AUTHORS")
94
96
  project.author = File.readlines(authors).collect do |line|
@@ -137,12 +139,13 @@ if /mswin32/ =~ project.spec.platform.to_s
137
139
  end
138
140
 
139
141
  ObjectSpace.each_object(Rake::RDocTask) do |rdoc_task|
140
- t_option_index = rdoc_task.options.index("-t")
142
+ options = rdoc_task.options
143
+ t_option_index = options.index("--title") || options.index("-t")
141
144
  rdoc_task.options[t_option_index, 2] = nil
142
145
  rdoc_task.title = "Ruby/groonga - #{version}"
143
146
 
144
147
  rdoc_task.rdoc_files = ["ext/rb-groonga.c"] + Dir.glob("ext/rb-grn-*.c")
145
- rdoc_task.rdoc_files += Dir.glob("lib/*.rb")
148
+ rdoc_task.rdoc_files += Dir.glob("lib/**/*.rb")
146
149
  rdoc_task.rdoc_files += Dir.glob("*.rdoc")
147
150
  end
148
151
 
@@ -202,6 +205,12 @@ task :publish_html do
202
205
  sh "rsync #{rsync_args} html/ #{host}:#{remote_dir}"
203
206
  end
204
207
 
208
+ task :tag do
209
+ repository = "svn+ssh://rubyforge.org/var/svn/groonga/groonga"
210
+ sh("svn cp -m 'release #{version}!!!' " +
211
+ "#{repository}/trunk #{repository}/tags/#{version}")
212
+ end
213
+
205
214
  # fix Hoe's incorrect guess.
206
215
  project.spec.executables.clear
207
216
  # project.lib_files = project.spec.files.grep(%r|^src/lib/|)
data/TUTORIAL.ja.rdoc CHANGED
@@ -28,7 +28,7 @@ Ruby/groongaはRubyGemsでインストールできます。
28
28
  それでは、ファイルを指定してデータベースを作成します。
29
29
 
30
30
  >> Groonga::Database.create(:path => "/tmp/bookmark.db")
31
- => #<Groonga::Database id: <nil>, name: (anonymous), path: </tmp/bookmark.db>, domain: <nil>, range: <nil>>
31
+ => #<Groonga::Database ...>
32
32
 
33
33
  ここで作成したデータベースは、これ以降、暗黙のうちに利用され
34
34
  ます。最初にデータベースを作成したら特に意識する必要はありま
@@ -54,7 +54,7 @@ groongaには以下の3種類のテーブルがあります。
54
54
  ブルを作成します。
55
55
 
56
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>>
57
+ => #<Groonga::Hash ...>
58
58
 
59
59
 
60
60
  これで<tt><items></tt>という名前のテーブルが作成できました。
@@ -69,7 +69,7 @@ groongaには以下の3種類のテーブルがあります。
69
69
 
70
70
  == レコードを追加する
71
71
 
72
- items>テーブルにレコードを追加します。
72
+ <tt><items></tt>テーブルにレコードを追加します。
73
73
 
74
74
  >> items.add("http://ja.wikipedia.org/wiki/Ruby")
75
75
  => #<Groonga::Record ...>
@@ -93,7 +93,7 @@ items>テーブルにレコードを追加します。
93
93
 
94
94
  まず<tt><items></tt>テーブルに+title+という名前のカラムを追加します。
95
95
 
96
- >> title_colum = items.define_column("title", "<text>", :persistent => true)
96
+ >> title_column = items.define_column("title", "<text>", :persistent => true)
97
97
  => #<Groonga::VarSizeColumn ...>
98
98
 
99
99
  2番目の引数は、追加するカラムのデータ型を示しています。
@@ -125,9 +125,9 @@ N-gramを利用した全文検索では、分解したN文字とその出現位
125
125
  単語格納用テーブルの準備ができたので、<tt><items></tt>テーブ
126
126
  ルの+title+カラムに対するインデックスを定義します。
127
127
 
128
- >> terms.define_index_column("item_title", items,
129
- :persistent => true,
130
- :source => "<items>.title")
128
+ >> title_index_column = terms.define_index_column("item_title", items,
129
+ :persistent => true,
130
+ :source => "<items>.title")
131
131
  => #<Groonga::IndexColumn ...>
132
132
 
133
133
  少し違和感を感じるかも知れませんが、<tt><items></tt>テーブル
@@ -155,7 +155,7 @@ N-gramを利用した全文検索では、分解したN文字とその出現位
155
155
 
156
156
  以下のようにして検索することができます。
157
157
 
158
- >> title_index_column.saerch("Ruby").collect {|record| record.key.key}
158
+ >> title_index_column.search("Ruby").collect {|record| record.key.key}
159
159
  ["http://ja.wikipedia.org/wiki/Ruby", "http://www.ruby-lang.org/"]
160
160
 
161
161
  検索結果はGroonga::Hashで返されます。ハッシュのキーに見つかっ
@@ -249,11 +249,11 @@ http://qwik.jp/senna/senna2.files/rect4605.png
249
249
  >> @items = items
250
250
  >> @comments = comments
251
251
  >> def add_bookmark(url, title, author, content, issued)
252
- >> item = @items.find(url) || @items.add(url, :title => title)
253
- >> @comments.add(:item => item,
254
- >> :author => author,
255
- >> :content => content,
256
- >> :issued => issued)
252
+ >> item = @items.find(url) || @items.add(url, :title => title)
253
+ >> @comments.add(:item => item,
254
+ >> :author => author,
255
+ >> :content => content,
256
+ >> :issued => issued)
257
257
  >> end
258
258
 
259
259
  +itmes+と+comments+をインスタンス変数に代入しているのはメソッ
@@ -261,9 +261,9 @@ http://qwik.jp/senna/senna2.files/rect4605.png
261
261
 
262
262
  +add_bookmark+は以下のような手順を実行しています。
263
263
 
264
- * <tt><items></tt>テーブルに該当ページのレコードがあるかどうか調べる。
265
- * レコードがなければ追加する。
266
- * <tt><comments></tt>テーブルにレコードを登録する。
264
+ * <tt><items></tt>テーブルに該当ページのレコードがあるかどうか調べる。
265
+ * レコードがなければ追加する。
266
+ * <tt><comments></tt>テーブルにレコードを登録する。
267
267
 
268
268
  作成したメソッドを呼び出していくつかブックマークを登録してみ
269
269
  ましょう。
@@ -281,4 +281,70 @@ http://qwik.jp/senna/senna2.files/rect4605.png
281
281
 
282
282
  == 全文検索その2
283
283
 
284
+ 登録したレコードに対して全文検索を実行してみます。
285
+
286
+ >> records = comments.select do |record|
287
+ >> record["content"] =~ "LISP"
288
+ >> end
289
+ >> records.each do |record|
290
+ >> record = record.key
291
+ >> p [record.id,
292
+ >> record[".issued"],
293
+ >> record[".item.title"],
294
+ >> record[".author.name"],
295
+ >> record[".content"]]
296
+ >> end
297
+ [1, Sat Aug 18 18:40:26 +0900 2007, "[翻訳]JavaScript: 世界で最も誤解されたプログラミング言語", "モリタン", "JavaScript LISP"]
298
+ [2, Mon Aug 20 09:11:32 +0900 2007, "なんでも継続", "モリタン", "継続 LISP Scheme"]
299
+ [3, Mon Aug 20 09:13:13 +0900 2007, "末尾再帰", "タポロボ", "末尾再帰 Scheme LISP"]
300
+ [4, Mon Aug 20 09:11:32 +0900 2007, "なんでも継続", "タポロボ", "トランポリン LISP continuation"]
301
+
302
+ カラムへのアクセスは、カラム名を+.+で繋いで複合データ型の要素
303
+ を再帰的に辿ることができます。(同様の出力を普通のRDBで実現す
304
+ るためには、<tt><items></tt>テーブル、<tt><comments></tt>テー
305
+ ブル、<tt><users></tt>テーブルのJOIN操作が必要になります。)
306
+
307
+ 上の式の中で、肝心の検索処理は、第一引数の式を評価する時点で
308
+ 完了していて、レコードセットオブジェクトとしてメモリに蓄積さ
309
+ れています。
310
+
311
+ >> records
312
+ #<Groonga::Hash ..., size: <4>>
313
+
314
+ レコードセットは、出力する前に様々に加工することができます。
315
+
316
+ 以下は、日付で降順にソートしてから出力した例です。
317
+
318
+ >> records.sort([{:key => ".issued", :order => "descending"}]).each do |record|
319
+ >> record = record.key
320
+ >> p [record.id,
321
+ >> record[".issued"],
322
+ >> record[".item.title"],
323
+ >> record[".author.name"],
324
+ >> record[".content"]]
325
+ >> end
326
+ [3, Mon Aug 20 09:13:13 +0900 2007, "末尾再帰", "タポロボ", "末尾再帰 Scheme LISP"]
327
+ [2, Mon Aug 20 09:11:32 +0900 2007, "なんでも継続", "モリタン", "継続 LISP Scheme"]
328
+ [4, Mon Aug 20 09:11:32 +0900 2007, "なんでも継続", "タポロボ", "トランポリン LISP continuation"]
329
+ [1, Sat Aug 18 18:40:26 +0900 2007, "[翻訳]JavaScript: 世界で最も誤解されたプログラミング言語", "モリタン", "JavaScript LISP"]
330
+
331
+ 同じitemが何度も出てくると検索結果が見にくいので、item毎にグ
332
+ ループ化してみます。
333
+
334
+ >> records.group([".item"]).each do |record|
335
+ >> item = record.key
336
+ >> p [record[".:nsubrecs"],
337
+ >> item.key,
338
+ >> item[".title"]]
339
+ >> end
340
+ [1, "http://d.hatena.ne.jp/brazil/20050829/1125321936", "[翻訳]JavaScript: 世界で最も誤解されたプログラミング言語"]
341
+ [2, "http://practical-scheme.net/docs/cont-j.html", "なんでも継続"]
342
+ [1, "http://d.hatena.ne.jp/higepon/20070815/1187192864", "末尾再帰"]
343
+
344
+ +.:nsubrecs+というのはグループ化した単位に含まれるレコードの
345
+ 件数を示します。SQLで言えば、GROUP BY句を含むクエリのcount 関
346
+ 数のような働きです。
347
+
348
+ == 少し複雑な検索
349
+
284
350
  つづく。。。
@@ -3,30 +3,33 @@
3
3
  # This benchmark is based on Tokyo Cabinet's benchmark at
4
4
  # http://alpha.mixi.co.jp/blog/?p=791
5
5
  #
6
- # On my environment at 2009/05/16:
7
- # % for x in {0..9}; do ruby benchmark/read-write-small-many-items.rb $x; done
6
+ # On my environment at 2009/07/14:
7
+ # % for x in {0..9}; do ruby benchmark/read-write-many-small-items.rb $x; done
8
8
  # user system total real memory
9
- # Hash 1.440000 0.120000 1.560000 ( 2.018838) 47.230MB
10
- # groonga: Hash: memory 1.780000 0.170000 1.950000 ( 2.331934) 30.582MB
11
- # groonga: Trie: memory 2.220000 0.150000 2.370000 ( 2.788049) 22.594MB
12
- # groonga: Hash: file 1.810000 0.170000 1.980000 ( 2.389940) 30.590MB
13
- # groonga: Trie: file 2.170000 0.150000 2.320000 ( 2.862775) 22.594MB
14
- # Localmemcache: file 1.710000 0.240000 1.950000 ( 2.311414) 46.410MB
15
- # TC: Hash: memory 1.540000 0.180000 1.720000 ( 2.048307) 49.180MB
16
- # TC: Tree: memory 1.410000 0.160000 1.570000 ( 1.891273) 37.691MB
17
- # TC: Hash: file 2.420000 2.950000 5.370000 ( 7.122531) 9.258MB
18
- # TC: Tree: file 2.080000 0.220000 2.300000 ( 2.876335) 13.234MB
9
+ # Hash 0.850000 0.170000 1.020000 ( 1.050703) 46.957MB
10
+ # groonga: Hash: memory 1.080000 0.180000 1.260000 ( 1.251981) 30.152MB
11
+ # groonga: Trie: memory 1.300000 0.120000 1.420000 ( 1.429549) 22.199MB
12
+ # groonga: Hash: file 1.070000 0.190000 1.260000 ( 1.276910) 30.156MB
13
+ # groonga: Trie: file 1.280000 0.150000 1.430000 ( 1.423066) 22.203MB
14
+ # Localmemcache: file 1.320000 0.150000 1.470000 ( 1.497013) 45.984MB
15
+ # TC: Hash: memory 0.940000 0.250000 1.190000 ( 1.248141) 48.758MB
16
+ # TC: Tree: memory 0.890000 0.140000 1.030000 ( 1.067693) 37.270MB
17
+ # TC: Hash: file 1.740000 2.390000 4.130000 ( 4.141555) 8.848MB
18
+ # TC: Tree: file 1.290000 0.180000 1.470000 ( 1.476853) 12.805MB
19
19
  #
20
- # Ruby: Debian GNU/Linux sid at 2009/05/16:
21
- # ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]
22
- # groonga: HEAD at 2009/05/16: ed49074fbc217b97c0b0b8d675f2417f9490c87e
23
- # Ruby/Groonga: trunk at 2009/05/16: r321
24
- # Localmemcache: HEAD at 2009/05/16: 6f8cfbd3a103c2be8d54834a65deb096d7cda34f
25
- # Tokyo Cabinet: 1.4.20
26
- # Tokyo Cabinet Ruby: 1.23
20
+ # CPU: Intel(R) Core(TM)2 Duo 2.33GHz
21
+ # Memory: 2GB
22
+ # Ruby: Debian GNU/Linux sid at 2009/07/14:
23
+ # ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]
24
+ # groonga: HEAD at 2009/07/14: fdaf58df5dd0195c10624eabee3e3f522f4af3f9
25
+ # Ruby/Groonga: trunk at 2009/07/14: r479
26
+ # Localmemcache: HEAD at 2009/07/14: 3121629016344dfd10f7533ca8ec68a0006cca21
27
+ # Tokyo Cabinet: 1.4.29
28
+ # Tokyo Cabinet Ruby: 1.27
27
29
  #
28
- # NOTE: All C source codes are built with "-g -O0"
29
- # option. They will be more faster with "-O2" option.
30
+ # NOTE:
31
+ # * groonga, Localmemcache and Tokyo Cabinet are built with "-O3" option.
32
+ # * Ruby bindings of them are built with "-O2" option.
30
33
 
31
34
  require File.join(File.dirname(__FILE__), "common.rb")
32
35
 
@@ -99,9 +102,9 @@ begin
99
102
  require 'localmemcache'
100
103
 
101
104
  item("Localmemcache: file") do
102
- LocalMemCache.drop(:namespace => "read-write-small-many-items",
105
+ LocalMemCache.drop(:namespace => "read-write-many-small-items",
103
106
  :force => true)
104
- @db = LocalMemCache.new(:namespace => "read-write-small-many-items")
107
+ @db = LocalMemCache.new(:namespace => "read-write-many-small-items")
105
108
  values.each do |value|
106
109
  @db[value] = value
107
110
  @db[value]
@@ -3,30 +3,33 @@
3
3
  # This benchmark is based on Tokyo Cabinet's benchmark at
4
4
  # http://alpha.mixi.co.jp/blog/?p=791
5
5
  #
6
- # On my environment at 2009/05/16:
7
- # % for x in {0..9}; do ruby benchmark/write-small-many-items.rb $x; done
6
+ # On my environment at 2009/07/14:
7
+ # % for x in {0..9}; do ruby benchmark/write-many-small-items.rb $x; done
8
8
  # user system total real memory
9
- # Hash 1.090000 0.180000 1.270000 ( 1.565159) 47.090MB
10
- # groonga: Hash: memory 0.930000 0.140000 1.070000 ( 1.364338) 23.473MB
11
- # groonga: Trie: memory 1.170000 0.120000 1.290000 ( 1.601229) 15.480MB
12
- # groonga: Hash: file 0.980000 0.170000 1.150000 ( 1.398126) 23.477MB
13
- # groonga: Trie: file 1.220000 0.130000 1.350000 ( 1.744243) 15.484MB
14
- # Localmemcache: file 1.100000 0.210000 1.310000 ( 1.734014) 39.301MB
15
- # TC: Hash: memory 0.710000 0.130000 0.840000 ( 1.061472) 42.055MB
16
- # TC: Tree: memory 0.640000 0.150000 0.790000 ( 1.040223) 30.566MB
17
- # TC: Hash: file 1.310000 2.370000 3.680000 ( 5.028978) 2.133MB
18
- # TC: Tree: file 1.030000 0.200000 1.230000 ( 1.666725) 6.086MB
9
+ # Hash 0.650000 0.130000 0.780000 ( 0.799843) 46.957MB
10
+ # groonga: Hash: memory 0.650000 0.130000 0.780000 ( 0.781058) 23.477MB
11
+ # groonga: Trie: memory 0.690000 0.180000 0.870000 ( 0.862132) 15.516MB
12
+ # groonga: Hash: file 0.660000 0.120000 0.780000 ( 0.780952) 23.480MB
13
+ # groonga: Trie: file 0.660000 0.190000 0.850000 ( 0.867515) 15.520MB
14
+ # Localmemcache: file 0.900000 0.150000 1.050000 ( 1.052692) 39.312MB
15
+ # TC: Hash: memory 0.480000 0.150000 0.630000 ( 0.636297) 42.062MB
16
+ # TC: Tree: memory 0.440000 0.150000 0.590000 ( 0.593117) 30.570MB
17
+ # TC: Hash: file 1.000000 1.820000 2.820000 ( 2.989515) 2.160MB
18
+ # TC: Tree: file 0.720000 0.130000 0.850000 ( 0.877557) 6.102MB
19
19
  #
20
- # Ruby: Debian GNU/Linux sid at 2009/05/16:
21
- # ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]
22
- # groonga: HEAD at 2009/05/16: ed49074fbc217b97c0b0b8d675f2417f9490c87e
23
- # Ruby/Groonga: trunk at 2009/05/16: r321
24
- # Localmemcache: HEAD at 2009/05/16: 6f8cfbd3a103c2be8d54834a65deb096d7cda34f
25
- # Tokyo Cabinet: 1.4.20
26
- # Tokyo Cabinet Ruby: 1.23
20
+ # CPU: Intel(R) Core(TM)2 Duo 2.33GHz
21
+ # Memory: 2GB
22
+ # Ruby: Debian GNU/Linux sid at 2009/07/14:
23
+ # ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]
24
+ # groonga: HEAD at 2009/07/14: fdaf58df5dd0195c10624eabee3e3f522f4af3f9
25
+ # Ruby/Groonga: trunk at 2009/07/14: r479
26
+ # Localmemcache: HEAD at 2009/07/14: 3121629016344dfd10f7533ca8ec68a0006cca21
27
+ # Tokyo Cabinet: 1.4.29
28
+ # Tokyo Cabinet Ruby: 1.27
27
29
  #
28
- # NOTE: All C source codes are built with "-g -O0"
29
- # option. They will be more faster with "-O2" option.
30
+ # NOTE:
31
+ # * groonga, Localmemcache and Tokyo Cabinet are built with "-O3" option.
32
+ # * Ruby bindings of them are built with "-O2" option.
30
33
 
31
34
  require File.join(File.dirname(__FILE__), "common.rb")
32
35
 
@@ -94,8 +97,8 @@ begin
94
97
  require 'localmemcache'
95
98
 
96
99
  item("Localmemcache: file") do
97
- LocalMemCache.drop(:namespace => "write-small-many-items", :force => true)
98
- @db = LocalMemCache.new(:namespace => "write-small-many-items")
100
+ LocalMemCache.drop(:namespace => "write-many-small-items", :force => true)
101
+ @db = LocalMemCache.new(:namespace => "write-many-small-items")
99
102
  values.each do |value|
100
103
  @db[value] = value
101
104
  end
data/example/bookmark.rb CHANGED
@@ -1,14 +1,32 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- require "rubygems"
5
- require "groonga"
4
+ base_dir = File.join(File.dirname(__FILE__), "..")
5
+ groonga_ext_dir = File.join(base_dir, 'ext')
6
+ groonga_lib_dir = File.join(base_dir, 'lib')
7
+ $LOAD_PATH.unshift(groonga_ext_dir)
8
+ $LOAD_PATH.unshift(groonga_lib_dir)
9
+
10
+ begin
11
+ require "groonga"
12
+ rescue LoadError
13
+ require "rubygems"
14
+ require "groonga"
15
+ end
6
16
 
7
17
  $KCODE = "UTF-8"
8
18
  Groonga::Context.default_options = {:encoding => :utf8}
9
19
 
10
20
  path = ARGV[0]
11
- persistent = !path.nil?
21
+ if path.nil?
22
+ require 'tmpdir'
23
+ require 'fileutils'
24
+ temporary_directory = File.join(Dir.tmpdir, "ruby-groonga")
25
+ FileUtils.mkdir_p(temporary_directory)
26
+ at_exit {FileUtils.rm_rf(temporary_directory)}
27
+ path = File.join(temporary_directory, "db")
28
+ end
29
+ persistent = true
12
30
 
13
31
  p Groonga::Database.create(:path => path)
14
32
 
@@ -79,8 +97,34 @@ p add_bookmark("http://practical-scheme.net/docs/cont-j.html",
79
97
  "なんでも継続", "taporobo", "トランポリン LISP continuation",
80
98
  1187568692)
81
99
 
82
- terms.column("comment_content").search("LISP").each do |record|
100
+
101
+ records = comments.select do |record|
102
+ record["content"] =~ "LISP"
103
+ end
104
+
105
+ records.each do |record|
106
+ record = record.key
107
+ p [record.id,
108
+ record[".issued"],
109
+ record[".item.title"],
110
+ record[".author.name"],
111
+ record[".content"]]
112
+ end
113
+
114
+ p records
115
+
116
+ records.sort([{:key => ".issued", :order => "descending"}]).each do |record|
83
117
  record = record.key
84
- p [record[".issued"], record[".item.title"], record[".author.name"],
118
+ p [record.id,
119
+ record[".issued"],
120
+ record[".item.title"],
121
+ record[".author.name"],
85
122
  record[".content"]]
86
123
  end
124
+
125
+ records.group([".item"]).each do |record|
126
+ item = record.key
127
+ p [record[".:nsubrecs"],
128
+ item.key,
129
+ item[".title"]]
130
+ end