rroonga 0.9.2-x86-mingw32
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 +206 -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 +230 -0
- data/example/search/public/css/groonga.css +122 -0
- data/ext/.gitignore +2 -0
- data/ext/groonga/extconf.rb +93 -0
- data/ext/groonga/rb-grn-accessor.c +52 -0
- data/ext/groonga/rb-grn-array-cursor.c +36 -0
- data/ext/groonga/rb-grn-array.c +210 -0
- data/ext/groonga/rb-grn-column.c +573 -0
- data/ext/groonga/rb-grn-context.c +662 -0
- data/ext/groonga/rb-grn-database.c +472 -0
- data/ext/groonga/rb-grn-encoding-support.c +64 -0
- data/ext/groonga/rb-grn-encoding.c +257 -0
- data/ext/groonga/rb-grn-exception.c +1110 -0
- data/ext/groonga/rb-grn-expression-builder.c +75 -0
- data/ext/groonga/rb-grn-expression.c +731 -0
- data/ext/groonga/rb-grn-fix-size-column.c +166 -0
- data/ext/groonga/rb-grn-hash-cursor.c +38 -0
- data/ext/groonga/rb-grn-hash.c +294 -0
- data/ext/groonga/rb-grn-index-column.c +488 -0
- data/ext/groonga/rb-grn-logger.c +504 -0
- data/ext/groonga/rb-grn-object.c +1369 -0
- data/ext/groonga/rb-grn-operation.c +198 -0
- data/ext/groonga/rb-grn-patricia-trie-cursor.c +39 -0
- data/ext/groonga/rb-grn-patricia-trie.c +488 -0
- data/ext/groonga/rb-grn-procedure.c +52 -0
- data/ext/groonga/rb-grn-query.c +260 -0
- data/ext/groonga/rb-grn-record.c +40 -0
- data/ext/groonga/rb-grn-snippet.c +334 -0
- data/ext/groonga/rb-grn-table-cursor-key-support.c +69 -0
- data/ext/groonga/rb-grn-table-cursor.c +247 -0
- data/ext/groonga/rb-grn-table-key-support.c +714 -0
- data/ext/groonga/rb-grn-table.c +1977 -0
- data/ext/groonga/rb-grn-type.c +181 -0
- data/ext/groonga/rb-grn-utils.c +769 -0
- data/ext/groonga/rb-grn-variable-size-column.c +36 -0
- data/ext/groonga/rb-grn-variable.c +108 -0
- data/ext/groonga/rb-grn-view-accessor.c +53 -0
- data/ext/groonga/rb-grn-view-cursor.c +35 -0
- data/ext/groonga/rb-grn-view-record.c +41 -0
- data/ext/groonga/rb-grn-view.c +421 -0
- data/ext/groonga/rb-grn.h +698 -0
- data/ext/groonga/rb-groonga.c +107 -0
- data/extconf.rb +130 -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/1.8/groonga.so +0 -0
- data/lib/1.9/groonga.so +0 -0
- data/lib/groonga.rb +90 -0
- data/lib/groonga/context.rb +184 -0
- data/lib/groonga/expression-builder.rb +324 -0
- data/lib/groonga/patricia-trie.rb +85 -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/rroonga-build.rb +57 -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 +144 -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 +442 -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 +134 -0
- data/test/run-test.rb +58 -0
- data/test/test-array.rb +90 -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 +217 -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 +305 -0
- data/test/test-index-column.rb +81 -0
- data/test/test-logger.rb +37 -0
- data/test/test-patricia-trie.rb +205 -0
- data/test/test-procedure.rb +37 -0
- data/test/test-query.rb +22 -0
- data/test/test-record.rb +243 -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 +594 -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
- metadata +276 -0
data/benchmark/common.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
def memory_usage()
|
5
|
+
status = `cat /proc/#{$$}/status`
|
6
|
+
lines = status.split("\n")
|
7
|
+
lines.each do |line|
|
8
|
+
if line =~ /^VmRSS:/
|
9
|
+
line.gsub!(/.*:\s*(\d+).*/, '\1')
|
10
|
+
return line.to_i / 1024.0
|
11
|
+
end
|
12
|
+
end
|
13
|
+
return -1;
|
14
|
+
end
|
15
|
+
|
16
|
+
@items = []
|
17
|
+
|
18
|
+
def item(label, &block)
|
19
|
+
@items << [label, block]
|
20
|
+
end
|
21
|
+
|
22
|
+
def report(index=0)
|
23
|
+
width = @items.collect do |label, _|
|
24
|
+
label.length
|
25
|
+
end.max
|
26
|
+
|
27
|
+
label, block = @items[index]
|
28
|
+
if label.nil?
|
29
|
+
puts "unavailable report ID: #{index}"
|
30
|
+
puts "available IDs:"
|
31
|
+
@items.each_with_index do |(label, block), i|
|
32
|
+
puts "#{i}: #{label}"
|
33
|
+
end
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
|
37
|
+
if index.zero?
|
38
|
+
puts(" " * (width - 1) + Benchmark::Tms::CAPTION.rstrip + "memory".rjust(14))
|
39
|
+
end
|
40
|
+
# GC.disable
|
41
|
+
before = memory_usage
|
42
|
+
result = Benchmark.measure(&block)
|
43
|
+
# GC.enable
|
44
|
+
GC.start
|
45
|
+
size = memory_usage - before
|
46
|
+
|
47
|
+
formatted_size = "%10.3f" % size
|
48
|
+
puts "#{label.ljust(width)} #{result.to_s.strip} #{formatted_size}MB"
|
49
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# This benchmark is based on Tokyo Cabinet's benchmark at
|
4
|
+
# http://alpha.mixi.co.jp/blog/?p=791
|
5
|
+
#
|
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
|
+
# user system total real memory
|
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
|
+
#
|
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
|
29
|
+
#
|
30
|
+
# NOTE:
|
31
|
+
# * groonga, Localmemcache and Tokyo Cabinet are built with "-O3" option.
|
32
|
+
# * Ruby bindings of them are built with "-O2" option.
|
33
|
+
|
34
|
+
require File.join(File.dirname(__FILE__), "common.rb")
|
35
|
+
|
36
|
+
n = 500000
|
37
|
+
|
38
|
+
values = []
|
39
|
+
n.times do |i|
|
40
|
+
values << "%08d" % i
|
41
|
+
end
|
42
|
+
|
43
|
+
item("Hash") do
|
44
|
+
@hash = {}
|
45
|
+
values.each do |value|
|
46
|
+
@hash[value] = value
|
47
|
+
@hash[value]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
begin
|
52
|
+
base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
53
|
+
$LOAD_PATH.unshift(File.join(base_dir, "ext"))
|
54
|
+
$LOAD_PATH.unshift(File.join(base_dir, "lib"))
|
55
|
+
|
56
|
+
require 'groonga'
|
57
|
+
tmp_dir = "/tmp/groonga"
|
58
|
+
FileUtils.rm_rf(tmp_dir)
|
59
|
+
FileUtils.mkdir(tmp_dir)
|
60
|
+
@database = Groonga::Database.create(:path => "#{tmp_dir}/db")
|
61
|
+
|
62
|
+
item("groonga: Hash: file") do
|
63
|
+
@hash = Groonga::Hash.create(:name => "Hash",
|
64
|
+
:key_type => "ShortText")
|
65
|
+
column_name = "value"
|
66
|
+
@column = @hash.define_column(column_name, "ShortText")
|
67
|
+
values.each do |value|
|
68
|
+
@hash.set_column_value(value, column_name, value)
|
69
|
+
@hash.column_value(value, column_name)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
item("groonga: Trie: file") do
|
74
|
+
@trie = Groonga::PatriciaTrie.create(:name => "PatriciaTrie",
|
75
|
+
:key_type => "ShortText")
|
76
|
+
column_name = "value"
|
77
|
+
@column = @trie.define_column(column_name, "ShortText")
|
78
|
+
values.each do |value|
|
79
|
+
@trie.set_column_value(value, column_name, value)
|
80
|
+
@trie.column_value(value, column_name)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
rescue LoadError
|
84
|
+
end
|
85
|
+
|
86
|
+
begin
|
87
|
+
require 'localmemcache'
|
88
|
+
|
89
|
+
item("Localmemcache: file") do
|
90
|
+
LocalMemCache.drop(:namespace => "read-write-many-small-items",
|
91
|
+
:force => true)
|
92
|
+
@db = LocalMemCache.new(:namespace => "read-write-many-small-items")
|
93
|
+
values.each do |value|
|
94
|
+
@db[value] = value
|
95
|
+
@db[value]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
rescue LoadError
|
99
|
+
end
|
100
|
+
|
101
|
+
begin
|
102
|
+
require 'tokyocabinet'
|
103
|
+
|
104
|
+
item("TC: Hash: memory") do
|
105
|
+
@db = TokyoCabinet::ADB::new
|
106
|
+
@db.open("*#bnum=#{n}#mode=wct#xmsiz=0")
|
107
|
+
values.each do |value|
|
108
|
+
@db.put(value, value)
|
109
|
+
@db.get(value)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
item("TC: Tree: memory") do
|
114
|
+
@db = TokyoCabinet::ADB::new
|
115
|
+
@db.open("+#bnum=#{n}#mode=wct#xmsiz=0")
|
116
|
+
values.each do |value|
|
117
|
+
@db.put(value, value)
|
118
|
+
@db.get(value)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
hash_file = Tempfile.new(["tc-hash", ".tch"])
|
123
|
+
item("TC: Hash: file") do
|
124
|
+
@db = TokyoCabinet::ADB::new
|
125
|
+
@db.open("#{hash_file.path}#bnum=#{n}#mode=wct#xmsiz=0")
|
126
|
+
values.each do |value|
|
127
|
+
@db.put(value, value)
|
128
|
+
@db.get(value)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
tree_file = Tempfile.new(["tc-tree", ".tcb"])
|
133
|
+
item("TC: Tree: file") do
|
134
|
+
@db = TokyoCabinet::ADB::new
|
135
|
+
@db.open("#{tree_file.path}#bnum=#{n}#mode=wct#xmsiz=0")
|
136
|
+
values.each do |value|
|
137
|
+
@db.put(value, value)
|
138
|
+
@db.get(value)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
rescue LoadError
|
142
|
+
end
|
143
|
+
|
144
|
+
report(Integer(ARGV[0] || 0))
|
@@ -0,0 +1,135 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# This benchmark is based on Tokyo Cabinet's benchmark at
|
4
|
+
# http://alpha.mixi.co.jp/blog/?p=791
|
5
|
+
#
|
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
|
+
# user system total real memory
|
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
|
+
#
|
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
|
29
|
+
#
|
30
|
+
# NOTE:
|
31
|
+
# * groonga, Localmemcache and Tokyo Cabinet are built with "-O3" option.
|
32
|
+
# * Ruby bindings of them are built with "-O2" option.
|
33
|
+
|
34
|
+
require File.join(File.dirname(__FILE__), "common.rb")
|
35
|
+
|
36
|
+
n = 500000
|
37
|
+
|
38
|
+
values = []
|
39
|
+
n.times do |i|
|
40
|
+
values << "%08d" % i
|
41
|
+
end
|
42
|
+
|
43
|
+
item("Hash") do
|
44
|
+
@hash = {}
|
45
|
+
values.each do |value|
|
46
|
+
@hash[value] = value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
begin
|
51
|
+
base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
52
|
+
$LOAD_PATH.unshift(File.join(base_dir, "ext"))
|
53
|
+
$LOAD_PATH.unshift(File.join(base_dir, "lib"))
|
54
|
+
|
55
|
+
require 'groonga'
|
56
|
+
tmp_dir = "/tmp/groonga"
|
57
|
+
FileUtils.rm_rf(tmp_dir)
|
58
|
+
FileUtils.mkdir(tmp_dir)
|
59
|
+
@database = Groonga::Database.create(:path => "#{tmp_dir}/db")
|
60
|
+
|
61
|
+
item("groonga: Hash: file") do
|
62
|
+
@hash = Groonga::Hash.create(:name => "Hash",
|
63
|
+
:key_type => "ShortText")
|
64
|
+
column_name = "value"
|
65
|
+
@column = @hash.define_column(column_name, "ShortText")
|
66
|
+
values.each do |value|
|
67
|
+
@hash.set_column_value(value, column_name, value)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
item("groonga: Trie: file") do
|
72
|
+
@trie = Groonga::PatriciaTrie.create(:name => "PatriciaTrie",
|
73
|
+
:key_type => "ShortText")
|
74
|
+
column_name = "value"
|
75
|
+
@column = @trie.define_column(column_name, "ShortText")
|
76
|
+
values.each do |value|
|
77
|
+
@trie.set_column_value(value, column_name, value)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
rescue LoadError
|
81
|
+
end
|
82
|
+
|
83
|
+
begin
|
84
|
+
require 'localmemcache'
|
85
|
+
|
86
|
+
item("Localmemcache: file") do
|
87
|
+
LocalMemCache.drop(:namespace => "write-many-small-items", :force => true)
|
88
|
+
@db = LocalMemCache.new(:namespace => "write-many-small-items")
|
89
|
+
values.each do |value|
|
90
|
+
@db[value] = value
|
91
|
+
end
|
92
|
+
end
|
93
|
+
rescue LoadError
|
94
|
+
end
|
95
|
+
|
96
|
+
begin
|
97
|
+
require 'tokyocabinet'
|
98
|
+
|
99
|
+
item("TC: Hash: memory") do
|
100
|
+
@db = TokyoCabinet::ADB::new
|
101
|
+
@db.open("*#bnum=#{n}#mode=wct#xmsiz=0")
|
102
|
+
values.each do |value|
|
103
|
+
@db.put(value, value)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
item("TC: Tree: memory") do
|
108
|
+
@db = TokyoCabinet::ADB::new
|
109
|
+
@db.open("+#bnum=#{n}#mode=wct#xmsiz=0")
|
110
|
+
values.each do |value|
|
111
|
+
@db.put(value, value)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
hash_file = Tempfile.new(["tc-hash", ".tch"])
|
116
|
+
item("TC: Hash: file") do
|
117
|
+
@db = TokyoCabinet::ADB::new
|
118
|
+
@db.open("#{hash_file.path}#bnum=#{n}#mode=wct#xmsiz=0")
|
119
|
+
values.each do |value|
|
120
|
+
@db.put(value, value)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
tree_file = Tempfile.new(["tc-tree", ".tcb"])
|
125
|
+
item("TC: Tree: file") do
|
126
|
+
@db = TokyoCabinet::ADB::new
|
127
|
+
@db.open("#{tree_file.path}#bnum=#{n}#mode=wct#xmsiz=0")
|
128
|
+
values.each do |value|
|
129
|
+
@db.put(value, value)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
rescue LoadError
|
133
|
+
end
|
134
|
+
|
135
|
+
report(Integer(ARGV[0] || 0))
|
data/example/bookmark.rb
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
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
|
16
|
+
|
17
|
+
require 'time'
|
18
|
+
|
19
|
+
# Groonga::Logger.register(:level => :debug) do |level, time, title, message, location|
|
20
|
+
# p [level, time, title, message, location]
|
21
|
+
# end
|
22
|
+
|
23
|
+
$KCODE = "UTF-8"
|
24
|
+
Groonga::Context.default_options = {:encoding => :utf8}
|
25
|
+
|
26
|
+
path = ARGV[0]
|
27
|
+
if path.nil?
|
28
|
+
require 'tmpdir'
|
29
|
+
require 'fileutils'
|
30
|
+
temporary_directory = File.join(Dir.tmpdir, "ruby-groonga")
|
31
|
+
FileUtils.mkdir_p(temporary_directory)
|
32
|
+
at_exit {FileUtils.rm_rf(temporary_directory)}
|
33
|
+
path = File.join(temporary_directory, "db")
|
34
|
+
end
|
35
|
+
persistent = true
|
36
|
+
|
37
|
+
p Groonga::Database.create(:path => path)
|
38
|
+
|
39
|
+
p(items = Groonga::Hash.create(:name => "Items",
|
40
|
+
:key_type => "ShortText",
|
41
|
+
:persistent => persistent))
|
42
|
+
|
43
|
+
p items.add("http://ja.wikipedia.org/wiki/Ruby")
|
44
|
+
p items.add("http://www.ruby-lang.org/")
|
45
|
+
|
46
|
+
p items.define_column("title", "Text", :persistent => persistent)
|
47
|
+
|
48
|
+
p(terms = Groonga::Hash.create(:name => "Terms",
|
49
|
+
:key_type => "ShortText",
|
50
|
+
:persistent => persistent,
|
51
|
+
:default_tokenizer => "TokenBigram"))
|
52
|
+
p terms.define_index_column("item_title", items,
|
53
|
+
:persistent => persistent,
|
54
|
+
:with_weight => true,
|
55
|
+
:with_section => true,
|
56
|
+
:with_position => true,
|
57
|
+
:source => "Items.title")
|
58
|
+
|
59
|
+
p items.find("http://ja.wikipedia.org/wiki/Ruby")["title"] = "Ruby"
|
60
|
+
p items.find("http://www.ruby-lang.org/")["title"] = "オブジェクト指向スクリプト言語Ruby"
|
61
|
+
|
62
|
+
p(users = Groonga::Hash.create(:name => "Users",
|
63
|
+
:key_type => "ShortText",
|
64
|
+
:persistent => persistent))
|
65
|
+
p users.define_column("name", "Text",
|
66
|
+
:persistent => persistent)
|
67
|
+
|
68
|
+
p(comments = Groonga::Array.create(:name => "Comments",
|
69
|
+
:persistent => persistent))
|
70
|
+
p comments.define_column("item", items)
|
71
|
+
p comments.define_column("author", users)
|
72
|
+
p comments.define_column("content", "Text")
|
73
|
+
p comments.define_column("issued", "Time")
|
74
|
+
|
75
|
+
p terms.define_index_column("comment_content", comments,
|
76
|
+
:persistent => persistent,
|
77
|
+
:with_weight => true,
|
78
|
+
:with_section => true,
|
79
|
+
:with_position => true,
|
80
|
+
:source => "Comments.content")
|
81
|
+
|
82
|
+
p users.add("moritan", :name => "モリタン")
|
83
|
+
p users.add("taporobo", :name => "タポロボ")
|
84
|
+
|
85
|
+
|
86
|
+
p items.find("http://d.hatena.ne.jp/brazil/20050829/1125321936")
|
87
|
+
|
88
|
+
p items.add("http://d.hatena.ne.jp/brazil/20050829/1125321936",
|
89
|
+
:title => "[翻訳]JavaScript: 世界で最も誤解されたプログラミング言語")
|
90
|
+
|
91
|
+
p comments.add(:item => "http://d.hatena.ne.jp/brazil/20050829/1125321936",
|
92
|
+
:author => "moritan",
|
93
|
+
:content => "JavaScript LISP",
|
94
|
+
:issued => 1187430026)
|
95
|
+
|
96
|
+
@items = items
|
97
|
+
@comments = comments
|
98
|
+
def add_bookmark(url, title, author, content, issued)
|
99
|
+
item = @items.find(url) || @items.add(url, :title => title)
|
100
|
+
@comments.add(:item => item,
|
101
|
+
:author => author,
|
102
|
+
:content => content,
|
103
|
+
:issued => issued)
|
104
|
+
end
|
105
|
+
|
106
|
+
p add_bookmark("http://practical-scheme.net/docs/cont-j.html",
|
107
|
+
"なんでも継続", "moritan", "継続 LISP Scheme", 1187568692)
|
108
|
+
p add_bookmark("http://d.hatena.ne.jp/higepon/20070815/1187192864",
|
109
|
+
"末尾再帰", "taporobo", "末尾再帰 Scheme LISP", 1187568793)
|
110
|
+
p add_bookmark("http://practical-scheme.net/docs/cont-j.html",
|
111
|
+
"なんでも継続", "taporobo", "トランポリン LISP continuation",
|
112
|
+
1187568692.98765)
|
113
|
+
p add_bookmark("http://jp.rubyist.net/managinze",
|
114
|
+
"るびま", "moritan", "Ruby ドキュメント",
|
115
|
+
Time.now)
|
116
|
+
p add_bookmark("http://jp.rubyist.net/managinze",
|
117
|
+
"るびま", "taporobo", "Ruby 雑誌",
|
118
|
+
Time.now)
|
119
|
+
p add_bookmark("http://groonga.rubyforge.org/",
|
120
|
+
"ラングバ", "moritan", "Ruby groonga",
|
121
|
+
Time.parse("2009-07-19"))
|
122
|
+
|
123
|
+
|
124
|
+
records = comments.select do |record|
|
125
|
+
record["content"] =~ "LISP"
|
126
|
+
end
|
127
|
+
|
128
|
+
records.each do |record|
|
129
|
+
record = record.key
|
130
|
+
p [record.id,
|
131
|
+
record[".issued"],
|
132
|
+
record[".item.title"],
|
133
|
+
record[".author.name"],
|
134
|
+
record[".content"]]
|
135
|
+
end
|
136
|
+
|
137
|
+
p records
|
138
|
+
|
139
|
+
records.sort([{:key => ".issued", :order => "descending"}]).each do |record|
|
140
|
+
record = record.key
|
141
|
+
p [record.id,
|
142
|
+
record[".issued"],
|
143
|
+
record[".item.title"],
|
144
|
+
record[".author.name"],
|
145
|
+
record[".content"]]
|
146
|
+
end
|
147
|
+
|
148
|
+
records.group([".item"]).each do |record|
|
149
|
+
item = record.key
|
150
|
+
p [record.n_sub_records,
|
151
|
+
item.key,
|
152
|
+
item[".title"]]
|
153
|
+
end
|
154
|
+
|
155
|
+
p ruby_comments = @comments.select {|record| record["content"] =~ "Ruby"}
|
156
|
+
p ruby_items = @items.select("*W1:50 title:@Ruby")
|
157
|
+
|
158
|
+
p ruby_items = ruby_comments.group([".item"]).union!(ruby_items)
|
159
|
+
ruby_items.sort([{:key => "._score", :order => "descending"}]).each do |record|
|
160
|
+
p [record["._score"], record[".title"]]
|
161
|
+
end
|