groonga 0.9.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. metadata +38 -227
  2. data/AUTHORS +0 -5
  3. data/NEWS.ja.rdoc +0 -114
  4. data/NEWS.rdoc +0 -116
  5. data/README.ja.rdoc +0 -63
  6. data/README.rdoc +0 -64
  7. data/Rakefile +0 -216
  8. data/benchmark/common.rb +0 -49
  9. data/benchmark/read-write-many-small-items.rb +0 -144
  10. data/benchmark/write-many-small-items.rb +0 -135
  11. data/example/bookmark.rb +0 -161
  12. data/example/index-html.rb +0 -89
  13. data/example/search/config.ru +0 -211
  14. data/example/search/public/css/groonga.css +0 -122
  15. data/ext/.gitignore +0 -2
  16. data/ext/rb-grn-accessor.c +0 -52
  17. data/ext/rb-grn-array-cursor.c +0 -36
  18. data/ext/rb-grn-array.c +0 -210
  19. data/ext/rb-grn-column.c +0 -570
  20. data/ext/rb-grn-context.c +0 -655
  21. data/ext/rb-grn-database.c +0 -415
  22. data/ext/rb-grn-encoding-support.c +0 -64
  23. data/ext/rb-grn-encoding.c +0 -257
  24. data/ext/rb-grn-exception.c +0 -1110
  25. data/ext/rb-grn-expression-builder.c +0 -75
  26. data/ext/rb-grn-expression.c +0 -732
  27. data/ext/rb-grn-fix-size-column.c +0 -166
  28. data/ext/rb-grn-hash-cursor.c +0 -38
  29. data/ext/rb-grn-hash.c +0 -294
  30. data/ext/rb-grn-index-column.c +0 -488
  31. data/ext/rb-grn-logger.c +0 -325
  32. data/ext/rb-grn-object.c +0 -1335
  33. data/ext/rb-grn-operation.c +0 -198
  34. data/ext/rb-grn-patricia-trie-cursor.c +0 -39
  35. data/ext/rb-grn-patricia-trie.c +0 -488
  36. data/ext/rb-grn-procedure.c +0 -52
  37. data/ext/rb-grn-query.c +0 -260
  38. data/ext/rb-grn-record.c +0 -40
  39. data/ext/rb-grn-snippet.c +0 -328
  40. data/ext/rb-grn-table-cursor-key-support.c +0 -69
  41. data/ext/rb-grn-table-cursor.c +0 -246
  42. data/ext/rb-grn-table-key-support.c +0 -731
  43. data/ext/rb-grn-table.c +0 -2038
  44. data/ext/rb-grn-type.c +0 -181
  45. data/ext/rb-grn-utils.c +0 -769
  46. data/ext/rb-grn-variable-size-column.c +0 -36
  47. data/ext/rb-grn-variable.c +0 -108
  48. data/ext/rb-grn.h +0 -684
  49. data/ext/rb-groonga.c +0 -113
  50. data/extconf.rb +0 -216
  51. data/html/bar.svg +0 -153
  52. data/html/developer.html +0 -121
  53. data/html/developer.svg +0 -469
  54. data/html/download.svg +0 -253
  55. data/html/favicon.ico +0 -0
  56. data/html/favicon.xcf +0 -0
  57. data/html/footer.html.erb +0 -28
  58. data/html/head.html.erb +0 -4
  59. data/html/header.html.erb +0 -17
  60. data/html/index.html +0 -147
  61. data/html/install.svg +0 -636
  62. data/html/logo.xcf +0 -0
  63. data/html/ranguba.css +0 -248
  64. data/html/tutorial.svg +0 -559
  65. data/lib/groonga.rb +0 -83
  66. data/lib/groonga/expression-builder.rb +0 -285
  67. data/lib/groonga/patricia-trie.rb +0 -53
  68. data/lib/groonga/record.rb +0 -276
  69. data/lib/groonga/schema.rb +0 -916
  70. data/license/GPL +0 -340
  71. data/license/LGPL +0 -504
  72. data/license/RUBY +0 -59
  73. data/misc/grnop2ruby.rb +0 -49
  74. data/pkg-config.rb +0 -333
  75. data/src/rb-grn-table-cursor.c +0 -296
  76. data/test-unit/Rakefile +0 -40
  77. data/test-unit/TODO +0 -5
  78. data/test-unit/bin/testrb +0 -5
  79. data/test-unit/html/classic.html +0 -15
  80. data/test-unit/html/index.html +0 -25
  81. data/test-unit/html/index.html.ja +0 -27
  82. data/test-unit/lib/test/unit.rb +0 -323
  83. data/test-unit/lib/test/unit/assertionfailederror.rb +0 -25
  84. data/test-unit/lib/test/unit/assertions.rb +0 -1230
  85. data/test-unit/lib/test/unit/attribute.rb +0 -125
  86. data/test-unit/lib/test/unit/autorunner.rb +0 -353
  87. data/test-unit/lib/test/unit/collector.rb +0 -36
  88. data/test-unit/lib/test/unit/collector/descendant.rb +0 -23
  89. data/test-unit/lib/test/unit/collector/dir.rb +0 -108
  90. data/test-unit/lib/test/unit/collector/load.rb +0 -136
  91. data/test-unit/lib/test/unit/collector/objectspace.rb +0 -34
  92. data/test-unit/lib/test/unit/color-scheme.rb +0 -102
  93. data/test-unit/lib/test/unit/color.rb +0 -96
  94. data/test-unit/lib/test/unit/diff.rb +0 -724
  95. data/test-unit/lib/test/unit/error.rb +0 -130
  96. data/test-unit/lib/test/unit/exceptionhandler.rb +0 -39
  97. data/test-unit/lib/test/unit/failure.rb +0 -136
  98. data/test-unit/lib/test/unit/fixture.rb +0 -176
  99. data/test-unit/lib/test/unit/notification.rb +0 -129
  100. data/test-unit/lib/test/unit/omission.rb +0 -191
  101. data/test-unit/lib/test/unit/pending.rb +0 -150
  102. data/test-unit/lib/test/unit/priority.rb +0 -181
  103. data/test-unit/lib/test/unit/runner/console.rb +0 -52
  104. data/test-unit/lib/test/unit/runner/emacs.rb +0 -8
  105. data/test-unit/lib/test/unit/runner/tap.rb +0 -8
  106. data/test-unit/lib/test/unit/testcase.rb +0 -476
  107. data/test-unit/lib/test/unit/testresult.rb +0 -89
  108. data/test-unit/lib/test/unit/testsuite.rb +0 -110
  109. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +0 -14
  110. data/test-unit/lib/test/unit/ui/console/testrunner.rb +0 -464
  111. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +0 -63
  112. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +0 -92
  113. data/test-unit/lib/test/unit/ui/testrunner.rb +0 -28
  114. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +0 -77
  115. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +0 -41
  116. data/test-unit/lib/test/unit/util/backtracefilter.rb +0 -41
  117. data/test-unit/lib/test/unit/util/method-owner-finder.rb +0 -28
  118. data/test-unit/lib/test/unit/util/observable.rb +0 -90
  119. data/test-unit/lib/test/unit/util/procwrapper.rb +0 -48
  120. data/test-unit/lib/test/unit/version.rb +0 -7
  121. data/test-unit/sample/adder.rb +0 -13
  122. data/test-unit/sample/subtracter.rb +0 -12
  123. data/test-unit/sample/test_adder.rb +0 -20
  124. data/test-unit/sample/test_subtracter.rb +0 -20
  125. data/test-unit/sample/test_user.rb +0 -23
  126. data/test-unit/test/collector/test-descendant.rb +0 -133
  127. data/test-unit/test/collector/test-load.rb +0 -329
  128. data/test-unit/test/collector/test_dir.rb +0 -406
  129. data/test-unit/test/collector/test_objectspace.rb +0 -100
  130. data/test-unit/test/run-test.rb +0 -15
  131. data/test-unit/test/test-attribute.rb +0 -86
  132. data/test-unit/test/test-color-scheme.rb +0 -67
  133. data/test-unit/test/test-color.rb +0 -47
  134. data/test-unit/test/test-diff.rb +0 -518
  135. data/test-unit/test/test-emacs-runner.rb +0 -60
  136. data/test-unit/test/test-fixture.rb +0 -287
  137. data/test-unit/test/test-notification.rb +0 -33
  138. data/test-unit/test/test-omission.rb +0 -81
  139. data/test-unit/test/test-pending.rb +0 -70
  140. data/test-unit/test/test-priority.rb +0 -119
  141. data/test-unit/test/test-testcase.rb +0 -554
  142. data/test-unit/test/test_assertions.rb +0 -1151
  143. data/test-unit/test/test_error.rb +0 -26
  144. data/test-unit/test/test_failure.rb +0 -33
  145. data/test-unit/test/test_testresult.rb +0 -113
  146. data/test-unit/test/test_testsuite.rb +0 -129
  147. data/test-unit/test/testunit-test-util.rb +0 -14
  148. data/test-unit/test/ui/test_testrunmediator.rb +0 -20
  149. data/test-unit/test/util/test-method-owner-finder.rb +0 -38
  150. data/test-unit/test/util/test_backtracefilter.rb +0 -41
  151. data/test-unit/test/util/test_observable.rb +0 -102
  152. data/test-unit/test/util/test_procwrapper.rb +0 -36
  153. data/test/.gitignore +0 -1
  154. data/test/groonga-test-utils.rb +0 -106
  155. data/test/run-test.rb +0 -58
  156. data/test/test-array.rb +0 -97
  157. data/test/test-column.rb +0 -298
  158. data/test/test-context.rb +0 -73
  159. data/test/test-database.rb +0 -113
  160. data/test/test-encoding.rb +0 -33
  161. data/test/test-exception.rb +0 -93
  162. data/test/test-expression-builder.rb +0 -156
  163. data/test/test-expression.rb +0 -133
  164. data/test/test-fix-size-column.rb +0 -65
  165. data/test/test-gqtp.rb +0 -70
  166. data/test/test-hash.rb +0 -312
  167. data/test/test-index-column.rb +0 -81
  168. data/test/test-patricia-trie.rb +0 -189
  169. data/test/test-procedure.rb +0 -37
  170. data/test/test-query.rb +0 -22
  171. data/test/test-record.rb +0 -268
  172. data/test/test-remote.rb +0 -53
  173. data/test/test-schema.rb +0 -416
  174. data/test/test-snippet.rb +0 -121
  175. data/test/test-table-cursor.rb +0 -153
  176. data/test/test-table-offset-and-limit.rb +0 -102
  177. data/test/test-table-select-normalize.rb +0 -48
  178. data/test/test-table-select.rb +0 -145
  179. data/test/test-table.rb +0 -642
  180. data/test/test-type.rb +0 -61
  181. data/test/test-variable-size-column.rb +0 -98
  182. data/test/test-variable.rb +0 -28
  183. data/test/test-vector-column.rb +0 -76
  184. data/test/test-version.rb +0 -31
  185. data/text/TUTORIAL.ja.rdoc +0 -392
  186. data/text/expression.rdoc +0 -284
@@ -1,135 +0,0 @@
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 DELETED
@@ -1,161 +0,0 @@
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
@@ -1,89 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- if ARGV.size < 2 or ARGV.find {|option| option == "-h" or option == "--help"}
4
- puts "Usage: #{$0} DATABASE_FILE [FILE_OR_DIRECTORY ...]"
5
- exit
6
- end
7
-
8
- require 'pathname'
9
-
10
- base_directory = Pathname(__FILE__).dirname + ".."
11
- $LOAD_PATH.unshift((base_directory + "ext").to_s)
12
- $LOAD_PATH.unshift((base_directory + "lib").to_s)
13
-
14
- require 'rubygems'
15
- require 'groonga'
16
- require 'nokogiri'
17
-
18
- database_file, *targets = ARGV
19
-
20
- database_file = Pathname(database_file)
21
- database_directory = database_file.dirname
22
- database_directory.mkpath unless database_directory.exist?
23
-
24
- if database_file.exist?
25
- Groonga::Database.open(database_file.to_s)
26
- else
27
- Groonga::Database.create(:path => database_file.to_s)
28
- Groonga::Schema.define do |schema|
29
- schema.create_table("documents") do |table|
30
- table.string("title")
31
- table.text("content")
32
- table.string("path")
33
- table.time("last-modified")
34
- end
35
-
36
- schema.create_table("terms",
37
- :type => :patricia_trie,
38
- :key_normalize => true,
39
- :default_tokenizer => "TokenBigram") do |table|
40
- table.index("documents.title")
41
- table.index("documents.content")
42
- end
43
- end
44
- end
45
-
46
- documents = Groonga::Context.default["documents"]
47
-
48
- targets.each do |target|
49
- target = Pathname(target)
50
- target.find do |path|
51
- throw :prune if path.basename.to_s == ".svn"
52
- if path.file? and path.extname == ".html"
53
- path.open do |html|
54
- values = {:path => path.relative_path_from(target).to_s}
55
- _documents = documents.select do |record|
56
- record["path"] == values[:path]
57
- end
58
- if _documents.size.zero?
59
- document = documents.add
60
- else
61
- document = _documents.to_a[0].key
62
- end
63
-
64
- html_document = Nokogiri::HTML(html)
65
- html_document.css("title").each do |title|
66
- values[:title] = title.text
67
- end
68
- contents = []
69
- html_document.css("body").each do |body|
70
- contents << body.text
71
- end
72
- html_document.css("img").each do |image|
73
- image_content = []
74
- title = image['title']
75
- alt = image['alt']
76
- image_content << title if title and !title.empty?
77
- image_content << alt if alt and !alt.empty?
78
- contents.concat(image_content) unless image_content.empty?
79
- end
80
- values[:content] = contents.join("\n")
81
- values["last-modified"] = path.mtime
82
-
83
- values.each do |key, value|
84
- document[key] = value
85
- end
86
- end
87
- end
88
- end
89
- end
@@ -1,211 +0,0 @@
1
- # -*- mode: ruby; coding: utf-8 -*-
2
-
3
- base_dir = File.join(File.dirname(__FILE__), "..", "..")
4
- $LOAD_PATH.unshift(File.join(base_dir, "ext"))
5
- $LOAD_PATH.unshift(File.join(base_dir, "lib"))
6
-
7
- require 'rubygems'
8
- require 'rack'
9
- require 'groonga'
10
-
11
- use Rack::CommonLogger
12
- use Rack::Static, :urls => ["/css", "/images"], :root => "public"
13
-
14
- Groonga::Database.new("data/database")
15
-
16
- class Searcher
17
- include Rack::Utils
18
-
19
- def initialize
20
- @documents = Groonga::Context.default["documents"]
21
- end
22
-
23
- def call(env)
24
- request = Rack::Request.new(env)
25
- response = Rack::Response.new
26
- response["Content-Type"] = "text/html; charset=UTF-8"
27
- if /\/\z/ !~ request.path_info
28
- request.path_info += "/"
29
- response.redirect(request.url)
30
- return response.to_a
31
- end
32
-
33
- response.write(<<-EOH)
34
- <?xml version="1.0" encoding="utf-8"?>
35
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
36
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
37
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
38
- <head>
39
- <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
40
- <meta name="robot" content="noindex,nofollow" />
41
- <title>groongaで全文検索</title>
42
- <link rel="stylesheet" href="css/groonga.css" type="text/css" media="all" />
43
- </head>
44
- <body>
45
- <div class="header">
46
- <h1>groongaで全文検索</h1>
47
- </div>
48
-
49
- <div class="content">
50
- EOH
51
-
52
- render_search_box(request, response)
53
- render_search_result(request, response)
54
-
55
- response.write(<<-EOF)
56
- </div>
57
-
58
- <div class="footer">
59
- <p class="powered-by-groonga">
60
- <a href="http://groonga.org/">groonga</a>
61
- #{Groonga::VERSION.join('.')}を使っています。
62
- </p>
63
- <p class="powered-by-ruby-groonga">
64
- <a href="http://groonga.rubyforge.org/">Ruby/groonga</a>
65
- #{Groonga::BINDINGS_VERSION.join('.')}を使っています。
66
- </p>
67
- </div>
68
-
69
- </body>
70
- </html>
71
- EOF
72
- response.to_a
73
- end
74
-
75
- private
76
- def query(request)
77
- request['query'] || ''
78
- end
79
-
80
- def page(request)
81
- (request['page'] || 0).to_i
82
- end
83
-
84
- def render_search_box(request, response)
85
- response.write(<<-EOF)
86
- <form method="get" action="./">
87
- <p>
88
- <a href="."><img src="images/mini-groonga.png" alt="groonga" /></a>
89
- <input name="query" type="text" value="#{escape_html(query(request))}" />
90
- <input type="submit" value="検索" />
91
- </p>
92
- </form>
93
- EOF
94
- end
95
-
96
- def render_search_result(request, response)
97
- _query = query(request)
98
- _page = page(request)
99
- limit = 20
100
- if _query.empty?
101
- records = []
102
- response.write(<<-EOS)
103
- <div class='search-summary'>
104
- <p>Rubyでgroonga使って全文検索</p>
105
- </div>
106
- EOS
107
- else
108
- options = {}
109
- before = Time.now
110
- records = @documents.select do |record|
111
- record["content"].match(_query)
112
- end
113
- total_records = records.size
114
- records = records.sort([[".:score", "descending"],
115
- [".last-modified", "descending"]],
116
- :offset => _page * limit,
117
- :limit => limit)
118
- elapsed = Time.now - before
119
-
120
- response.write(<<-EOS)
121
- <div class='search-summary'>
122
- <p>
123
- <span class="keyword">#{escape_html(query(request))}</span>の検索結果:
124
- <span class="total-entries">#{total_records}</span>件中
125
- <span class="display-range">
126
- #{total_records.zero? ? 0 : (_page * limit) + 1}
127
- -
128
- #{(_page * limit) + records.size}
129
- </span>
130
- 件(#{elapsed}秒)
131
- </p>
132
- </div>
133
- EOS
134
- end
135
-
136
- response.write(" <div class='records'>\n")
137
- records.each do |record|
138
- render_record(request, response, record)
139
- end
140
- response.write(" </div>\n")
141
-
142
- render_pagination(request, response, _page, limit, total_records)
143
- end
144
-
145
- def render_record(request, response, record)
146
- response.write(" <div class='record'>\n")
147
- href = escape_html(record['.path'])
148
- title = escape_html(record['.title'])
149
- last_modified = escape_html(record['.last-modified'].iso8601)
150
- score = record.score
151
- response.write(" <h2><a href='#{href}'>#{title}</a>(#{score})</h2>\n")
152
- render_snippet(request, response, record)
153
- response.write(<<-EOM)
154
- <p class="metadata">
155
- <span class="url">#{unescape(href)}</span>
156
- -
157
- <span class="last-modified">#{last_modified}</span>
158
- </p>
159
- EOM
160
- response.write(" </div>\n")
161
- end
162
-
163
- def render_snippet(request, response, record)
164
- expression = record.table.expression
165
- snippet = expression.snippet([["<span class=\"keyword\">", "</span>"]],
166
- :width => 100,
167
- :html_escape => true,
168
- :normalize => true)
169
- separator = "\n<span class='separator'>...</span>\n"
170
- response.write(<<-EOS)
171
- <p class="snippet">
172
- #{snippet.execute(record[".content"]).join(separator)}
173
- </p>
174
- EOS
175
- end
176
-
177
- def render_pagination(request, response, page, limit, total_records)
178
- _query = query(request)
179
- return if _query.empty?
180
-
181
- return if total_records < limit
182
-
183
- last_page = (total_records / limit.to_f).ceil
184
- response.write("<div class='pagination'>\n")
185
- if page > 0
186
- render_pagination_link(request, response, _query, page - 1, "<<")
187
- end
188
- last_page.times do |i|
189
- if i == page
190
- response.write(pagination_span(escape_html(i)))
191
- else
192
- render_pagination_link(request, response, _query, i, i)
193
- end
194
- end
195
- if page < (last_page - 1)
196
- render_pagination_link(request, response, _query, page + 1, ">>")
197
- end
198
- response.write("</div>\n")
199
- end
200
-
201
- def render_pagination_link(request, response, query, page, label)
202
- href = "./?query=#{escape_html(query)};page=#{escape_html(page)}"
203
- response.write(pagination_span("<a href='#{href}'>#{label}</a>"))
204
- end
205
-
206
- def pagination_span(content)
207
- "<span class='pagination-link'>#{content}</span>\n"
208
- end
209
- end
210
-
211
- run Searcher.new