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
data/lib/groonga.rb DELETED
@@ -1,83 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License version 2.1 as published by the Free Software Foundation.
8
- #
9
- # This library is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- # Lesser General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU Lesser General Public
15
- # License along with this library; if not, write to the Free Software
16
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
-
18
- require 'pathname'
19
-
20
- base_dir = Pathname.new(__FILE__).dirname.dirname
21
- local_groonga_library_dir = base_dir + "vendor" + "local" + "lib"
22
- if local_groonga_library_dir.exist?
23
- prepend_path = Proc.new do |environment_name, separator|
24
- paths = (ENV[environment_name] || '').split(/#{separator}/)
25
- unless paths.include?(local_groonga_library_dir.to_s)
26
- paths = [local_groonga_library_dir.to_s] + paths
27
- ENV[environment_name] = paths.join(separator)
28
- end
29
- end
30
-
31
- case RUBY_PLATFORM
32
- when /mingw|mswin/
33
- prepend_path.call("PATH", ";")
34
- end
35
- end
36
-
37
- require 'groonga/record'
38
- require 'groonga/expression-builder'
39
- require 'groonga.so'
40
-
41
- ##
42
- # Ruby/groonga用のネームスペース。Ruby/groongaのクラスやメソッ
43
- # ドなどはこのモジュール以下に定義される。
44
- module Groonga
45
- class << self
46
- ##
47
- # BUILD_VERSIONを"."で結合して<tt>"メジャーバージョン.マ
48
- # イナーバージョン.マイクロバージョン"</tt>という形式の
49
- # 文字列にしたもの。
50
- def build_version
51
- BUILD_VERSION.join(".")
52
- end
53
-
54
- ##
55
- # VERSIONを"."で結合して<tt>"メジャーバージョン.マイナー
56
- # バージョン.マイクロバージョン"</tt>という形式の文字列に
57
- # したもの。
58
- def version
59
- VERSION.join(".")
60
- end
61
-
62
- ##
63
- # BINDINGS_VERSIONを"."で結合して<tt>"メジャーバージョン.マ
64
- # イナーバージョン.マイクロバージョン"</tt>という形式の文
65
- # 字列にしたもの。
66
- def bindings_version
67
- BINDINGS_VERSION.join(".")
68
- end
69
-
70
- ##
71
- # call-seq:
72
- # Groonga[name] -> Groonga::Object or nil
73
- # Groonga[id] -> Groonga::Object or nil
74
- #
75
- # 便利メソッド。Groonga::Context.default[name]と同じ。
76
- def [](name)
77
- Context.default[name]
78
- end
79
- end
80
- end
81
-
82
- require 'groonga/patricia-trie'
83
- require 'groonga/schema'
@@ -1,285 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License version 2.1 as published by the Free Software Foundation.
8
- #
9
- # This library is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- # Lesser General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU Lesser General Public
15
- # License along with this library; if not, write to the Free Software
16
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
-
18
- module Groonga
19
- module ExpressionBuildable # :nodoc:
20
- attr_reader :table
21
- attr_accessor :query
22
- attr_accessor :syntax
23
- attr_accessor :allow_pragma
24
- attr_accessor :allow_column
25
- attr_accessor :allow_update
26
- attr_accessor :default_column
27
-
28
- def initialize(*args)
29
- @table = nil
30
- @name = nil
31
- @query = nil
32
- @syntax = nil
33
- @allow_pragma = nil
34
- @allow_column = nil
35
- @allow_update = nil
36
- @default_column = nil
37
- end
38
-
39
- def build
40
- expression = Expression.new(:name => @name)
41
- variable = expression.define_variable(:domain => @table)
42
-
43
- builder = nil
44
- builder = match(@query, default_parse_options) if @query
45
- if block_given?
46
- if builder
47
- builder &= yield(self)
48
- else
49
- builder = yield(self)
50
- end
51
- end
52
- if builder.nil? or builder == self
53
- expression.append_constant(1)
54
- expression.append_constant(1)
55
- expression.append_operation(Groonga::Operation::OR, 2)
56
- else
57
- builder.build(expression, variable)
58
- end
59
-
60
- expression.compile
61
- expression
62
- end
63
-
64
- def &(other)
65
- other
66
- end
67
-
68
- def |(other)
69
- other
70
- end
71
-
72
- private
73
- def default_parse_options
74
- {
75
- :syntax => @syntax,
76
- :allow_pragma => @allow_pragma,
77
- :allow_column => @allow_column,
78
- :allow_update => @allow_update,
79
- :default_column => @default_column,
80
- }
81
- end
82
-
83
- class ExpressionBuilder # :nodoc:
84
- def initialize
85
- super()
86
- end
87
-
88
- def &(other)
89
- AndExpressionBuilder.new(self, other)
90
- end
91
-
92
- def |(other)
93
- OrExpressionBuilder.new(self, other)
94
- end
95
- end
96
-
97
- class SetExpressionBuilder < ExpressionBuilder # :nodoc:
98
- def initialize(operation, *expression_builders)
99
- super()
100
- @operation = operation
101
- @expression_builders = expression_builders
102
- end
103
-
104
- def build(expression, variable)
105
- return if @expression_builders.empty?
106
- @expression_builders.each do |builder|
107
- builder.build(expression, variable)
108
- end
109
- expression.append_operation(@operation, @expression_builders.size)
110
- end
111
- end
112
-
113
- class AndExpressionBuilder < SetExpressionBuilder # :nodoc:
114
- def initialize(*expression_builders)
115
- super(Groonga::Operation::AND, *expression_builders)
116
- end
117
- end
118
-
119
- class OrExpressionBuilder < SetExpressionBuilder # :nodoc:
120
- def initialize(*expression_builders)
121
- super(Groonga::Operation::OR, *expression_builders)
122
- end
123
- end
124
-
125
- class BinaryExpressionBuilder < ExpressionBuilder # :nodoc:
126
- def initialize(operation, column, value)
127
- super()
128
- @operation = operation
129
- @default_column = column
130
- @value = value
131
- end
132
-
133
- def build(expression, variable)
134
- expression.append_object(variable)
135
- if @default_column.is_a?(String)
136
- expression.append_constant(@default_column)
137
- else
138
- expression.append_object(@default_column)
139
- end
140
- expression.append_operation(Groonga::Operation::GET_VALUE, 2)
141
- expression.append_constant(@value)
142
- expression.append_operation(@operation, 2)
143
- end
144
- end
145
-
146
- class EqualExpressionBuilder < BinaryExpressionBuilder # :nodoc:
147
- def initialize(column, value)
148
- super(Groonga::Operation::EQUAL, column, value)
149
- end
150
- end
151
-
152
- class MatchExpressionBuilder < BinaryExpressionBuilder # :nodoc:
153
- def initialize(column, value)
154
- super(Groonga::Operation::MATCH, column, value)
155
- end
156
- end
157
-
158
- class LessExpressionBuilder < BinaryExpressionBuilder # :nodoc:
159
- def initialize(column, value)
160
- super(Groonga::Operation::LESS, column, value)
161
- end
162
- end
163
-
164
- class LessEqualExpressionBuilder < BinaryExpressionBuilder # :nodoc:
165
- def initialize(column, value)
166
- super(Groonga::Operation::LESS_EQUAL, column, value)
167
- end
168
- end
169
-
170
- class GreaterExpressionBuilder < BinaryExpressionBuilder # :nodoc:
171
- def initialize(column, value)
172
- super(Groonga::Operation::GREATER, column, value)
173
- end
174
- end
175
-
176
- class GreaterEqualExpressionBuilder < BinaryExpressionBuilder # :nodoc:
177
- def initialize(column, value)
178
- super(Groonga::Operation::GREATER_EQUAL, column, value)
179
- end
180
- end
181
-
182
- class SubExpressionBuilder < ExpressionBuilder # :nodoc:
183
- def initialize(query, options)
184
- super()
185
- @query = query
186
- @options = options
187
- end
188
-
189
- def build(expression, variable)
190
- expression.parse(@query, @options)
191
- end
192
- end
193
- end
194
-
195
- class RecordExpressionBuilder # :nodoc:
196
- include ExpressionBuildable
197
-
198
- def initialize(table, name)
199
- super()
200
- @table = table
201
- @name = name
202
- end
203
-
204
- def [](name)
205
- column = @table.column(name)
206
- if column.nil?
207
- message = "unknown column <#{name.inspect}> " +
208
- "for table <#{@table.inspect}>"
209
- raise ArgumentError, message
210
- end
211
- ColumnExpressionBuilder.new(column, nil, nil,
212
- :table => @table,
213
- :column_name => name)
214
- end
215
-
216
- def match(query, options_or_default_column={})
217
- if options_or_default_column.is_a?(String)
218
- options = {:default_column => options_or_default_column}
219
- else
220
- options = options_or_default_column
221
- end
222
- options = options.dup
223
- options[:syntax] ||= :query
224
- SubExpressionBuilder.new(query, options)
225
- end
226
- end
227
-
228
- class ColumnExpressionBuilder # :nodoc:
229
- include ExpressionBuildable
230
-
231
- def initialize(column, name, query, options={})
232
- super()
233
- @table = options[:table] || column.table
234
- @default_column = column
235
- @column_name = options[:column_name] || @default_column.local_name
236
- @range = @default_column.range
237
- @name = name
238
- @query = query
239
- end
240
-
241
- def ==(other)
242
- EqualExpressionBuilder.new(@default_column, normalize(other))
243
- end
244
-
245
- def =~(other)
246
- if other.nil?
247
- full_column_name = "#{@table.name}.#{@column_name}"
248
- raise ArgumentError, "match word should not be nil: #{full_column_name}"
249
- end
250
- MatchExpressionBuilder.new(@default_column, normalize(other))
251
- end
252
-
253
- def <(other)
254
- LessExpressionBuilder.new(@default_column, normalize(other))
255
- end
256
-
257
- def <=(other)
258
- LessEqualExpressionBuilder.new(@default_column, normalize(other))
259
- end
260
-
261
- def >(other)
262
- GreaterExpressionBuilder.new(@default_column, normalize(other))
263
- end
264
-
265
- def >=(other)
266
- GreaterEqualExpressionBuilder.new(@default_column, normalize(other))
267
- end
268
-
269
- def match(query, options={})
270
- options = options.dup
271
- options[:syntax] ||= :query
272
- options[:default_column] = @column_name
273
- SubExpressionBuilder.new(query, options)
274
- end
275
-
276
- private
277
- def normalize(other)
278
- if @range.is_a?(Groonga::Table) and other.is_a?(Integer)
279
- Groonga::Record.new(@range, other)
280
- else
281
- other
282
- end
283
- end
284
- end
285
- end
@@ -1,53 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License version 2.1 as published by the Free Software Foundation.
8
- #
9
- # This library is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- # Lesser General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU Lesser General Public
15
- # License along with this library; if not, write to the Free Software
16
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
-
18
- module Groonga
19
- class PatriciaTrie
20
- # call-seq:
21
- # patricia_trie.tag_keys(text) {|record, word| ...} -> String
22
- #
23
- # _text_を走査し、レコードのキーとマッチする部分文字列ごとに
24
- # そのレコードが_record_として、その部分文字列が_word_として、
25
- # ブロックが呼び出される。ブロックから返された文字列が元の部
26
- # 分文字列と置換される。全てのヒットに対してのその置換処理が
27
- # 行われた文字列が返される。
28
- def tag_keys(text)
29
- position = 0
30
- result = ''
31
- if text.respond_to?(:encoding)
32
- encoding = text.encoding
33
- bytes = text.dup.force_encoding("ascii-8bit")
34
- else
35
- encoding = nil
36
- bytes = text
37
- end
38
- scan(text) do |record, word, start, length|
39
- previous_text = bytes[position...start]
40
- previous_text.force_encoding(encoding) if encoding
41
- result << previous_text
42
- result << yield(record, word)
43
- position = start + length
44
- end
45
- last_text = bytes[position..-1]
46
- unless last_text.empty?
47
- last_text.force_encoding(encoding) if encoding
48
- result << last_text
49
- end
50
- result
51
- end
52
- end
53
- end
@@ -1,276 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2009-2010 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
- module Groonga
19
- class Record
20
- # レコードが所属するテーブル
21
- attr_reader :table
22
- # レコードのID
23
- attr_reader :id
24
- # _table_の_id_に対応するレコードを作成する。_values_には各
25
- # カラムに設定する値を以下のような形式で指定する。
26
- #
27
- # [
28
- # ["カラム名", 値],
29
- # ["カラム名", 値],
30
- # ...,
31
- # ]
32
- def initialize(table, id, values=nil)
33
- @table = table
34
- @id = id
35
- if values
36
- values.each do |name, value|
37
- self[name] = value
38
- end
39
- end
40
- end
41
-
42
- # call-seq:
43
- # record == other -> true/false
44
- #
45
- # _record_と_other_が同じgroongaのレコードなら+true+を返し、
46
- # そうでなければ+false+を返す。
47
- def ==(other)
48
- self.class == other.class and
49
- [table, id] == [other.table, other.id]
50
- end
51
-
52
- # call-seq:
53
- # record[column_name] -> 値
54
- #
55
- # このレコードの_column_name_で指定されたカラムの値を返す。
56
- def [](column_name)
57
- @table.column_value(@id, column_name, :id => true)
58
- end
59
-
60
- # call-seq:
61
- # record[column_name] = 値
62
- #
63
- # このレコードの_column_name_で指定されたカラムの値を設定す
64
- # る。
65
- def []=(column_name, value)
66
- @table.set_column_value(@id, column_name, value, :id => true)
67
- end
68
-
69
- # call-seq:
70
- # record.append(column_name, value)
71
- #
72
- # このレコードの_column_name_で指定されたカラムの値の最後に
73
- # _value_を追加する。
74
- def append(column_name, value)
75
- column(column_name).append(@id, value)
76
- end
77
-
78
- # call-seq:
79
- # record.prepend(column_name, value)
80
- #
81
- # このレコードの_column_name_で指定されたカラムの値の最初に
82
- # _value_を追加する。
83
- def prepend(column_name, value)
84
- column(column_name).prepend(@id, value)
85
- end
86
-
87
- # call-seq:
88
- # record.have_column?(name) -> true/false
89
- #
90
- # 名前が_name_のカラムがレコードの所属するテーブルで定義され
91
- # ているなら+true+を返す。
92
- def have_column?(name)
93
- column(name).is_a?(Groonga::Column)
94
- rescue Groonga::NoSuchColumn
95
- false
96
- end
97
-
98
- # call-seq:
99
- # record.reference_column?(name) -> true/false
100
- #
101
- # 名前が_name_のカラムが参照カラムであるなら+true+を返す。
102
- def reference_column?(name)
103
- column(name).range.is_a?(Groonga::Table)
104
- end
105
-
106
- # call-seq:
107
- # record.search(name, query, options={}) -> Groonga::Hash
108
- #
109
- # 名前が_name_のGroonga::IndexColumnのsearchメソッドを呼ぶ。
110
- # _query_と_options_はそのメソッドにそのまま渡される。詳しく
111
- # はGroonga::IndexColumn#searchを参照。
112
- def search(name, query, options={})
113
- column(name).search(query, options)
114
- end
115
-
116
- # call-seq:
117
- # record.key -> 主キー
118
- #
119
- # レコードの主キーを返す。
120
- #
121
- # _record_が所属するテーブルがGroonga:::Arrayの場合は常
122
- # に+nil+を返す。
123
- def key
124
- if @table.is_a?(Groonga::Array)
125
- nil
126
- else
127
- @key ||= @table.key(@id)
128
- end
129
- end
130
-
131
- # call-seq:
132
- # record.score -> スコア値
133
- #
134
- # レコードのスコア値を返す。検索結果として生成されたテーブル
135
- # のみに定義される。
136
- def score
137
- self["._score"]
138
- end
139
-
140
- # call-seq:
141
- # record.n_sub_records -> 件数
142
- #
143
- # 主キーの値が同一であったレコードの件数を返す。検索結果とし
144
- # て生成されたテーブルのみに定義される。
145
- def n_sub_records
146
- self["._nsubrecs"]
147
- end
148
-
149
- # call-seq:
150
- # record.value -> 値
151
- #
152
- # レコードの値を返す。
153
- def value
154
- @table.value(@id, :id => true)
155
- end
156
-
157
- # call-seq:
158
- # record.value = 値
159
- #
160
- # レコードの値を設定する。既存の値は上書きされる。
161
- def value=(value)
162
- @table.set_value(@id, value, :id => true)
163
- end
164
-
165
- # call-seq:
166
- # record.increment!(name, delta=nil)
167
- #
168
- # このレコードの_name_で指定されたカラムの値を_delta_だけ増
169
- # 加する。_delta_が+nil+の場合は1増加する。
170
- def increment!(name, delta=nil)
171
- column(name).increment!(@id, delta)
172
- end
173
-
174
- # call-seq:
175
- # record.decrement!(name, delta=nil)
176
- #
177
- # このレコードの_name_で指定されたカラムの値を_delta_だけ減
178
- # 少する。_delta_が+nil+の場合は1減少する。
179
- def decrement!(name, delta=nil)
180
- column(name).decrement!(@id, delta)
181
- end
182
-
183
- # call-seq:
184
- # record.columns -> Groonga::Columnの配列
185
- #
186
- # レコードが所属するテーブルの全てのカラムを返す。
187
- def columns
188
- @table.columns
189
- end
190
-
191
- # call-seq:
192
- # attributes -> Hash
193
- #
194
- # レコードが所属しているテーブルで定義されているインデックス
195
- # 型のカラムでない全カラムを対象とし、カラムの名前をキーとし
196
- # たこのレコードのカラムの値のハッシュを返す。
197
- def attributes
198
- attributes = {"id" => id}
199
- _key = key
200
- attributes["key"] = _key if _key
201
- table_name = @table.name
202
- columns.each do |column|
203
- next if column.is_a?(Groonga::IndexColumn)
204
- value = column[@id]
205
- # TODO: support recursive reference.
206
- value = value.attributes if value.is_a?(Groonga::Record)
207
- attributes[column.local_name] = value
208
- end
209
- attributes
210
- end
211
-
212
- # call-seq:
213
- # record.delete
214
- #
215
- # レコードを削除する。
216
- def delete
217
- @table.delete(@id)
218
- end
219
-
220
- # call-seq:
221
- # record.lock(options={})
222
- # record.lock(options={}) {...}
223
- #
224
- # レコードが所属するテーブルをロックする。ロックに失敗した場
225
- # 合はGroonga::ResourceDeadlockAvoided例外が発生する。
226
- #
227
- # ブロックを指定した場合はブロックを抜けたときにunlockする。
228
- #
229
- # 利用可能なオプションは以下の通り。
230
- #
231
- # [_:timeout_]
232
- # ロックを獲得できなかった場合は_:timeout_秒間ロックの獲
233
- # 得を試みる。_:timeout_秒以内にロックを獲得できなかった
234
- # 場合は例外が発生する。
235
- def lock(options={}, &block)
236
- @table.lock(options.merge(:id => @id), &block)
237
- end
238
-
239
- # call-seq:
240
- # record.unlock(options={})
241
- #
242
- # レコードが所属するテーブルのロックを解除する。
243
- #
244
- # 利用可能なオプションは現在は無い。
245
- def unlock(options={})
246
- @table.unlock(options.merge(:id => @id))
247
- end
248
-
249
- # call-seq:
250
- # record.clear_lock(options={})
251
- #
252
- # レコードが所属するテーブルのロックを強制的に解除する。
253
- #
254
- # 利用可能なオプションは現在は無い。
255
- def clear_lock(options={})
256
- @table.clear_lock(options.merge(:id => @id))
257
- end
258
-
259
- # call-seq:
260
- # record.locked?(options={}) -> true/false
261
- #
262
- # レコードが所属するテーブルがロックされていれば+true+を返す。
263
- #
264
- # 利用可能なオプションは現在は無い。
265
- def locked?(options={})
266
- @table.locked?(options.merge(:id => @id))
267
- end
268
-
269
- private
270
- def column(name) # :nodoc:
271
- _column = @table.column(name.to_s)
272
- raise NoSuchColumn, "column(#{name.inspect}) is nil" if _column.nil?
273
- _column
274
- end
275
- end
276
- end