groonga 0.0.7 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/NEWS.ja.rdoc +56 -0
- data/NEWS.rdoc +58 -0
- data/Rakefile +2 -3
- data/benchmark/read-write-many-small-items.rb +16 -32
- data/benchmark/write-many-small-items.rb +14 -28
- data/example/bookmark.rb +19 -17
- data/example/index-html.rb +11 -1
- data/example/search/config.ru +14 -9
- data/ext/rb-grn-array.c +6 -6
- data/ext/rb-grn-column.c +348 -18
- data/ext/rb-grn-context.c +8 -4
- data/ext/rb-grn-database.c +6 -7
- data/ext/rb-grn-exception.c +101 -5
- data/ext/rb-grn-expression.c +206 -23
- data/ext/rb-grn-fix-size-column.c +6 -39
- data/ext/rb-grn-hash.c +24 -24
- data/ext/rb-grn-index-column.c +74 -19
- data/ext/rb-grn-logger.c +48 -0
- data/ext/rb-grn-object.c +281 -67
- data/ext/rb-grn-operation.c +1 -1
- data/ext/rb-grn-patricia-trie-cursor.c +10 -1
- data/ext/rb-grn-patricia-trie.c +268 -7
- data/ext/rb-grn-query.c +52 -1
- data/ext/rb-grn-record.c +8 -2
- data/ext/rb-grn-snippet.c +63 -1
- data/ext/rb-grn-table-cursor-key-support.c +15 -1
- data/ext/rb-grn-table-cursor.c +57 -0
- data/ext/rb-grn-table-key-support.c +382 -46
- data/ext/rb-grn-table.c +729 -192
- data/ext/rb-grn-type.c +63 -12
- data/ext/rb-grn-utils.c +156 -158
- data/ext/rb-grn-variable.c +18 -0
- data/ext/rb-grn.h +85 -21
- data/ext/rb-groonga.c +13 -3
- data/extconf.rb +19 -4
- data/html/developer.html +1 -1
- data/html/header.html.erb +1 -1
- data/html/index.html +4 -4
- data/lib/groonga.rb +10 -0
- data/lib/groonga/expression-builder.rb +81 -42
- data/lib/groonga/patricia-trie.rb +13 -0
- data/lib/groonga/record.rb +158 -13
- data/lib/groonga/schema.rb +339 -33
- data/pkg-config.rb +6 -1
- data/test-unit/lib/test/unit.rb +23 -42
- data/test-unit/lib/test/unit/assertionfailederror.rb +11 -0
- data/test-unit/lib/test/unit/assertions.rb +87 -9
- data/test-unit/lib/test/unit/autorunner.rb +20 -11
- data/test-unit/lib/test/unit/collector.rb +1 -8
- data/test-unit/lib/test/unit/collector/load.rb +2 -3
- data/test-unit/lib/test/unit/color-scheme.rb +13 -1
- data/test-unit/lib/test/unit/diff.rb +223 -37
- data/test-unit/lib/test/unit/error.rb +4 -0
- data/test-unit/lib/test/unit/failure.rb +31 -5
- data/test-unit/lib/test/unit/notification.rb +8 -4
- data/test-unit/lib/test/unit/omission.rb +51 -3
- data/test-unit/lib/test/unit/pending.rb +4 -0
- data/test-unit/lib/test/unit/testcase.rb +55 -4
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +190 -4
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +14 -0
- data/test-unit/lib/test/unit/ui/testrunner.rb +8 -0
- data/test-unit/lib/test/unit/version.rb +1 -1
- data/test-unit/sample/{tc_adder.rb → test_adder.rb} +3 -1
- data/test-unit/sample/{tc_subtracter.rb → test_subtracter.rb} +3 -1
- data/test-unit/sample/test_user.rb +1 -0
- data/test-unit/test/collector/test-descendant.rb +2 -4
- data/test-unit/test/collector/test_objectspace.rb +7 -5
- data/test-unit/test/run-test.rb +2 -0
- data/test-unit/test/test-color-scheme.rb +7 -0
- data/test-unit/test/test-diff.rb +48 -7
- data/test-unit/test/test-omission.rb +1 -1
- data/test-unit/test/test-testcase.rb +47 -0
- data/test-unit/test/test_assertions.rb +79 -10
- data/test/groonga-test-utils.rb +6 -1
- data/test/test-array.rb +29 -14
- data/test/test-column.rb +107 -55
- data/test/test-context.rb +5 -0
- data/test/test-database.rb +2 -37
- data/test/test-exception.rb +9 -1
- data/test/test-expression-builder.rb +23 -5
- data/test/test-expression.rb +44 -8
- data/test/test-fix-size-column.rb +16 -5
- data/test/test-gqtp.rb +70 -0
- data/test/test-hash.rb +142 -43
- data/test/test-index-column.rb +9 -9
- data/test/test-patricia-trie.rb +79 -20
- data/test/test-procedure.rb +4 -2
- data/test/test-record.rb +32 -20
- data/test/test-remote.rb +3 -2
- data/test/test-schema.rb +226 -92
- data/test/test-table-cursor.rb +103 -1
- data/test/test-table-offset-and-limit.rb +102 -0
- data/test/test-table-select-normalize.rb +4 -4
- data/test/test-table-select.rb +52 -8
- data/test/test-table.rb +235 -116
- data/test/test-type.rb +2 -2
- data/test/test-variable-size-column.rb +21 -5
- data/test/test-vector-column.rb +76 -0
- data/{TUTORIAL.ja.rdoc → text/TUTORIAL.ja.rdoc} +52 -52
- data/text/expression.rdoc +284 -0
- metadata +11 -7
- data/test-unit/sample/ts_examples.rb +0 -7
data/lib/groonga.rb
CHANGED
|
@@ -66,6 +66,16 @@ module Groonga
|
|
|
66
66
|
def bindings_version
|
|
67
67
|
BINDINGS_VERSION.join(".")
|
|
68
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
|
|
69
79
|
end
|
|
70
80
|
end
|
|
71
81
|
|
|
@@ -16,14 +16,23 @@
|
|
|
16
16
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17
17
|
|
|
18
18
|
module Groonga
|
|
19
|
-
module ExpressionBuildable
|
|
19
|
+
module ExpressionBuildable # :nodoc:
|
|
20
20
|
attr_reader :table
|
|
21
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
|
|
22
27
|
|
|
23
28
|
def initialize(*args)
|
|
24
29
|
@table = nil
|
|
25
30
|
@name = nil
|
|
26
31
|
@query = nil
|
|
32
|
+
@syntax = nil
|
|
33
|
+
@allow_pragma = nil
|
|
34
|
+
@allow_column = nil
|
|
35
|
+
@allow_update = nil
|
|
27
36
|
@default_column = nil
|
|
28
37
|
end
|
|
29
38
|
|
|
@@ -32,7 +41,7 @@ module Groonga
|
|
|
32
41
|
variable = expression.define_variable(:domain => @table)
|
|
33
42
|
|
|
34
43
|
builder = nil
|
|
35
|
-
builder = match(@query) if @query
|
|
44
|
+
builder = match(@query, default_parse_options) if @query
|
|
36
45
|
if block_given?
|
|
37
46
|
if builder
|
|
38
47
|
builder &= yield(self)
|
|
@@ -52,7 +61,26 @@ module Groonga
|
|
|
52
61
|
expression
|
|
53
62
|
end
|
|
54
63
|
|
|
55
|
-
|
|
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:
|
|
56
84
|
def initialize
|
|
57
85
|
super()
|
|
58
86
|
end
|
|
@@ -66,7 +94,7 @@ module Groonga
|
|
|
66
94
|
end
|
|
67
95
|
end
|
|
68
96
|
|
|
69
|
-
class SetExpressionBuilder < ExpressionBuilder
|
|
97
|
+
class SetExpressionBuilder < ExpressionBuilder # :nodoc:
|
|
70
98
|
def initialize(operation, *expression_builders)
|
|
71
99
|
super()
|
|
72
100
|
@operation = operation
|
|
@@ -82,72 +110,76 @@ module Groonga
|
|
|
82
110
|
end
|
|
83
111
|
end
|
|
84
112
|
|
|
85
|
-
class AndExpressionBuilder < SetExpressionBuilder
|
|
113
|
+
class AndExpressionBuilder < SetExpressionBuilder # :nodoc:
|
|
86
114
|
def initialize(*expression_builders)
|
|
87
115
|
super(Groonga::Operation::AND, *expression_builders)
|
|
88
116
|
end
|
|
89
117
|
end
|
|
90
118
|
|
|
91
|
-
class OrExpressionBuilder < SetExpressionBuilder
|
|
119
|
+
class OrExpressionBuilder < SetExpressionBuilder # :nodoc:
|
|
92
120
|
def initialize(*expression_builders)
|
|
93
121
|
super(Groonga::Operation::OR, *expression_builders)
|
|
94
122
|
end
|
|
95
123
|
end
|
|
96
124
|
|
|
97
|
-
class BinaryExpressionBuilder < ExpressionBuilder
|
|
98
|
-
def initialize(operation,
|
|
125
|
+
class BinaryExpressionBuilder < ExpressionBuilder # :nodoc:
|
|
126
|
+
def initialize(operation, column, value)
|
|
99
127
|
super()
|
|
100
128
|
@operation = operation
|
|
101
|
-
@
|
|
129
|
+
@default_column = column
|
|
102
130
|
@value = value
|
|
103
131
|
end
|
|
104
132
|
|
|
105
133
|
def build(expression, variable)
|
|
106
134
|
expression.append_object(variable)
|
|
107
|
-
|
|
135
|
+
if @default_column.is_a?(String)
|
|
136
|
+
expression.append_constant(@default_column)
|
|
137
|
+
else
|
|
138
|
+
expression.append_object(@default_column)
|
|
139
|
+
end
|
|
108
140
|
expression.append_operation(Groonga::Operation::GET_VALUE, 2)
|
|
109
141
|
expression.append_constant(@value)
|
|
110
142
|
expression.append_operation(@operation, 2)
|
|
111
143
|
end
|
|
112
144
|
end
|
|
113
145
|
|
|
114
|
-
class EqualExpressionBuilder < BinaryExpressionBuilder
|
|
115
|
-
def initialize(
|
|
116
|
-
super(Groonga::Operation::EQUAL,
|
|
146
|
+
class EqualExpressionBuilder < BinaryExpressionBuilder # :nodoc:
|
|
147
|
+
def initialize(column, value)
|
|
148
|
+
super(Groonga::Operation::EQUAL, column, value)
|
|
117
149
|
end
|
|
118
150
|
end
|
|
119
151
|
|
|
120
|
-
class MatchExpressionBuilder < BinaryExpressionBuilder
|
|
121
|
-
def initialize(
|
|
122
|
-
super(Groonga::Operation::MATCH,
|
|
152
|
+
class MatchExpressionBuilder < BinaryExpressionBuilder # :nodoc:
|
|
153
|
+
def initialize(column, value)
|
|
154
|
+
super(Groonga::Operation::MATCH, column, value)
|
|
123
155
|
end
|
|
124
156
|
end
|
|
125
157
|
|
|
126
|
-
class LessExpressionBuilder < BinaryExpressionBuilder
|
|
127
|
-
def initialize(
|
|
128
|
-
super(Groonga::Operation::LESS,
|
|
158
|
+
class LessExpressionBuilder < BinaryExpressionBuilder # :nodoc:
|
|
159
|
+
def initialize(column, value)
|
|
160
|
+
super(Groonga::Operation::LESS, column, value)
|
|
129
161
|
end
|
|
130
162
|
end
|
|
131
163
|
|
|
132
|
-
class LessEqualExpressionBuilder < BinaryExpressionBuilder
|
|
133
|
-
def initialize(
|
|
134
|
-
super(Groonga::Operation::LESS_EQUAL,
|
|
164
|
+
class LessEqualExpressionBuilder < BinaryExpressionBuilder # :nodoc:
|
|
165
|
+
def initialize(column, value)
|
|
166
|
+
super(Groonga::Operation::LESS_EQUAL, column, value)
|
|
135
167
|
end
|
|
136
168
|
end
|
|
137
169
|
|
|
138
|
-
class GreaterExpressionBuilder < BinaryExpressionBuilder
|
|
139
|
-
def initialize(
|
|
140
|
-
super(Groonga::Operation::GREATER,
|
|
170
|
+
class GreaterExpressionBuilder < BinaryExpressionBuilder # :nodoc:
|
|
171
|
+
def initialize(column, value)
|
|
172
|
+
super(Groonga::Operation::GREATER, column, value)
|
|
141
173
|
end
|
|
142
174
|
end
|
|
143
175
|
|
|
144
|
-
class GreaterEqualExpressionBuilder < BinaryExpressionBuilder
|
|
145
|
-
def initialize(
|
|
146
|
-
super(Groonga::Operation::GREATER_EQUAL,
|
|
176
|
+
class GreaterEqualExpressionBuilder < BinaryExpressionBuilder # :nodoc:
|
|
177
|
+
def initialize(column, value)
|
|
178
|
+
super(Groonga::Operation::GREATER_EQUAL, column, value)
|
|
147
179
|
end
|
|
148
180
|
end
|
|
149
181
|
|
|
150
|
-
class SubExpressionBuilder < ExpressionBuilder
|
|
182
|
+
class SubExpressionBuilder < ExpressionBuilder # :nodoc:
|
|
151
183
|
def initialize(query, options)
|
|
152
184
|
super()
|
|
153
185
|
@query = query
|
|
@@ -160,7 +192,7 @@ module Groonga
|
|
|
160
192
|
end
|
|
161
193
|
end
|
|
162
194
|
|
|
163
|
-
class RecordExpressionBuilder
|
|
195
|
+
class RecordExpressionBuilder # :nodoc:
|
|
164
196
|
include ExpressionBuildable
|
|
165
197
|
|
|
166
198
|
def initialize(table, name)
|
|
@@ -176,7 +208,9 @@ module Groonga
|
|
|
176
208
|
"for table <#{@table.inspect}>"
|
|
177
209
|
raise ArgumentError, message
|
|
178
210
|
end
|
|
179
|
-
ColumnExpressionBuilder.new(column, nil, nil
|
|
211
|
+
ColumnExpressionBuilder.new(column, nil, nil,
|
|
212
|
+
:table => @table,
|
|
213
|
+
:column_name => name)
|
|
180
214
|
end
|
|
181
215
|
|
|
182
216
|
def match(query, options_or_default_column={})
|
|
@@ -185,20 +219,21 @@ module Groonga
|
|
|
185
219
|
else
|
|
186
220
|
options = options_or_default_column
|
|
187
221
|
end
|
|
188
|
-
|
|
189
|
-
|
|
222
|
+
options = options.dup
|
|
223
|
+
options[:syntax] ||= :query
|
|
224
|
+
SubExpressionBuilder.new(query, options)
|
|
190
225
|
end
|
|
191
226
|
end
|
|
192
227
|
|
|
193
|
-
class ColumnExpressionBuilder
|
|
228
|
+
class ColumnExpressionBuilder # :nodoc:
|
|
194
229
|
include ExpressionBuildable
|
|
195
230
|
|
|
196
|
-
def initialize(column, name, query)
|
|
231
|
+
def initialize(column, name, query, options={})
|
|
197
232
|
super()
|
|
198
|
-
@table = column.table
|
|
199
|
-
@
|
|
200
|
-
@
|
|
201
|
-
@
|
|
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
|
|
202
237
|
@name = name
|
|
203
238
|
@query = query
|
|
204
239
|
end
|
|
@@ -208,6 +243,10 @@ module Groonga
|
|
|
208
243
|
end
|
|
209
244
|
|
|
210
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
|
|
211
250
|
MatchExpressionBuilder.new(@default_column, normalize(other))
|
|
212
251
|
end
|
|
213
252
|
|
|
@@ -228,9 +267,9 @@ module Groonga
|
|
|
228
267
|
end
|
|
229
268
|
|
|
230
269
|
def match(query, options={})
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
options =
|
|
270
|
+
options = options.dup
|
|
271
|
+
options[:syntax] ||= :query
|
|
272
|
+
options[:default_column] = @column_name
|
|
234
273
|
SubExpressionBuilder.new(query, options)
|
|
235
274
|
end
|
|
236
275
|
|
|
@@ -17,6 +17,14 @@
|
|
|
17
17
|
|
|
18
18
|
module Groonga
|
|
19
19
|
class PatriciaTrie
|
|
20
|
+
# call-seq:
|
|
21
|
+
# patricia_trie.tag_keys(text) {|record, word| ...} -> String
|
|
22
|
+
#
|
|
23
|
+
# _text_を走査し、レコードのキーとマッチする部分文字列ごとに
|
|
24
|
+
# そのレコードが_record_として、その部分文字列が_word_として、
|
|
25
|
+
# ブロックが呼び出される。ブロックから返された文字列が元の部
|
|
26
|
+
# 分文字列と置換される。全てのヒットに対してのその置換処理が
|
|
27
|
+
# 行われた文字列が返される。
|
|
20
28
|
def tag_keys(text)
|
|
21
29
|
position = 0
|
|
22
30
|
result = ''
|
|
@@ -34,6 +42,11 @@ module Groonga
|
|
|
34
42
|
result << yield(record, word)
|
|
35
43
|
position = start + length
|
|
36
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
|
|
37
50
|
result
|
|
38
51
|
end
|
|
39
52
|
end
|
data/lib/groonga/record.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
#
|
|
3
|
-
# Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
|
|
3
|
+
# Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
|
|
4
4
|
#
|
|
5
5
|
# This library is free software; you can redistribute it and/or
|
|
6
6
|
# modify it under the terms of the GNU Lesser General Public
|
|
@@ -17,7 +17,18 @@
|
|
|
17
17
|
|
|
18
18
|
module Groonga
|
|
19
19
|
class Record
|
|
20
|
-
|
|
20
|
+
# レコードが所属するテーブル
|
|
21
|
+
attr_reader :table
|
|
22
|
+
# レコードのID
|
|
23
|
+
attr_reader :id
|
|
24
|
+
# _table_の_id_に対応するレコードを作成する。_values_には各
|
|
25
|
+
# カラムに設定する値を以下のような形式で指定する。
|
|
26
|
+
#
|
|
27
|
+
# [
|
|
28
|
+
# ["カラム名", 値],
|
|
29
|
+
# ["カラム名", 値],
|
|
30
|
+
# ...,
|
|
31
|
+
# ]
|
|
21
32
|
def initialize(table, id, values=nil)
|
|
22
33
|
@table = table
|
|
23
34
|
@id = id
|
|
@@ -28,103 +39,237 @@ module Groonga
|
|
|
28
39
|
end
|
|
29
40
|
end
|
|
30
41
|
|
|
42
|
+
# call-seq:
|
|
43
|
+
# record == other -> true/false
|
|
44
|
+
#
|
|
45
|
+
# _record_と_other_が同じgroongaのレコードなら+true+を返し、
|
|
46
|
+
# そうでなければ+false+を返す。
|
|
31
47
|
def ==(other)
|
|
32
48
|
self.class == other.class and
|
|
33
49
|
[table, id] == [other.table, other.id]
|
|
34
50
|
end
|
|
35
51
|
|
|
52
|
+
# call-seq:
|
|
53
|
+
# record[column_name] -> 値
|
|
54
|
+
#
|
|
55
|
+
# このレコードの_column_name_で指定されたカラムの値を返す。
|
|
36
56
|
def [](column_name)
|
|
37
|
-
|
|
57
|
+
@table.column_value(@id, column_name, :id => true)
|
|
38
58
|
end
|
|
39
59
|
|
|
60
|
+
# call-seq:
|
|
61
|
+
# record[column_name] = 値
|
|
62
|
+
#
|
|
63
|
+
# このレコードの_column_name_で指定されたカラムの値を設定す
|
|
64
|
+
# る。
|
|
40
65
|
def []=(column_name, value)
|
|
41
|
-
|
|
66
|
+
@table.set_column_value(@id, column_name, value, :id => true)
|
|
42
67
|
end
|
|
43
68
|
|
|
69
|
+
# call-seq:
|
|
70
|
+
# record.append(column_name, value)
|
|
71
|
+
#
|
|
72
|
+
# このレコードの_column_name_で指定されたカラムの値の最後に
|
|
73
|
+
# _value_を追加する。
|
|
44
74
|
def append(column_name, value)
|
|
45
75
|
column(column_name).append(@id, value)
|
|
46
76
|
end
|
|
47
77
|
|
|
78
|
+
# call-seq:
|
|
79
|
+
# record.prepend(column_name, value)
|
|
80
|
+
#
|
|
81
|
+
# このレコードの_column_name_で指定されたカラムの値の最初に
|
|
82
|
+
# _value_を追加する。
|
|
48
83
|
def prepend(column_name, value)
|
|
49
84
|
column(column_name).prepend(@id, value)
|
|
50
85
|
end
|
|
51
86
|
|
|
87
|
+
# call-seq:
|
|
88
|
+
# record.have_column?(name) -> true/false
|
|
89
|
+
#
|
|
90
|
+
# 名前が_name_のカラムがレコードの所属するテーブルで定義され
|
|
91
|
+
# ているなら+true+を返す。
|
|
52
92
|
def have_column?(name)
|
|
53
93
|
column(name).is_a?(Groonga::Column)
|
|
54
|
-
rescue Groonga::
|
|
94
|
+
rescue Groonga::NoSuchColumn
|
|
55
95
|
false
|
|
56
96
|
end
|
|
57
97
|
|
|
98
|
+
# call-seq:
|
|
99
|
+
# record.reference_column?(name) -> true/false
|
|
100
|
+
#
|
|
101
|
+
# 名前が_name_のカラムが参照カラムであるなら+true+を返す。
|
|
58
102
|
def reference_column?(name)
|
|
59
103
|
column(name).range.is_a?(Groonga::Table)
|
|
60
104
|
end
|
|
61
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を参照。
|
|
62
112
|
def search(name, query, options={})
|
|
63
113
|
column(name).search(query, options)
|
|
64
114
|
end
|
|
65
115
|
|
|
116
|
+
# call-seq:
|
|
117
|
+
# record.key -> 主キー
|
|
118
|
+
#
|
|
119
|
+
# レコードの主キーを返す。
|
|
120
|
+
#
|
|
121
|
+
# _record_が所属するテーブルがGroonga:::Arrayの場合は常
|
|
122
|
+
# に+nil+を返す。
|
|
66
123
|
def key
|
|
67
|
-
@table.
|
|
124
|
+
if @table.is_a?(Groonga::Array)
|
|
125
|
+
nil
|
|
126
|
+
else
|
|
127
|
+
@key ||= @table.key(@id)
|
|
128
|
+
end
|
|
68
129
|
end
|
|
69
130
|
|
|
131
|
+
# call-seq:
|
|
132
|
+
# record.score -> スコア値
|
|
133
|
+
#
|
|
134
|
+
# レコードのスコア値を返す。検索結果として生成されたテーブル
|
|
135
|
+
# のみに定義される。
|
|
70
136
|
def score
|
|
71
|
-
self["
|
|
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"]
|
|
72
147
|
end
|
|
73
148
|
|
|
149
|
+
# call-seq:
|
|
150
|
+
# record.value -> 値
|
|
151
|
+
#
|
|
152
|
+
# レコードの値を返す。
|
|
74
153
|
def value
|
|
75
|
-
@table
|
|
154
|
+
@table.value(@id, :id => true)
|
|
76
155
|
end
|
|
77
156
|
|
|
157
|
+
# call-seq:
|
|
158
|
+
# record.value = 値
|
|
159
|
+
#
|
|
160
|
+
# レコードの値を設定する。既存の値は上書きされる。
|
|
78
161
|
def value=(value)
|
|
79
|
-
@table
|
|
162
|
+
@table.set_value(@id, value, :id => true)
|
|
80
163
|
end
|
|
81
164
|
|
|
165
|
+
# call-seq:
|
|
166
|
+
# record.increment!(name, delta=nil)
|
|
167
|
+
#
|
|
168
|
+
# このレコードの_name_で指定されたカラムの値を_delta_だけ増
|
|
169
|
+
# 加する。_delta_が+nil+の場合は1増加する。
|
|
82
170
|
def increment!(name, delta=nil)
|
|
83
171
|
column(name).increment!(@id, delta)
|
|
84
172
|
end
|
|
85
173
|
|
|
174
|
+
# call-seq:
|
|
175
|
+
# record.decrement!(name, delta=nil)
|
|
176
|
+
#
|
|
177
|
+
# このレコードの_name_で指定されたカラムの値を_delta_だけ減
|
|
178
|
+
# 少する。_delta_が+nil+の場合は1減少する。
|
|
86
179
|
def decrement!(name, delta=nil)
|
|
87
180
|
column(name).decrement!(@id, delta)
|
|
88
181
|
end
|
|
89
182
|
|
|
183
|
+
# call-seq:
|
|
184
|
+
# record.columns -> Groonga::Columnの配列
|
|
185
|
+
#
|
|
186
|
+
# レコードが所属するテーブルの全てのカラムを返す。
|
|
90
187
|
def columns
|
|
91
188
|
@table.columns
|
|
92
189
|
end
|
|
93
190
|
|
|
191
|
+
# call-seq:
|
|
192
|
+
# attributes -> Hash
|
|
193
|
+
#
|
|
194
|
+
# レコードが所属しているテーブルで定義されているインデックス
|
|
195
|
+
# 型のカラムでない全カラムを対象とし、カラムの名前をキーとし
|
|
196
|
+
# たこのレコードのカラムの値のハッシュを返す。
|
|
94
197
|
def attributes
|
|
95
|
-
attributes = {}
|
|
198
|
+
attributes = {"id" => id}
|
|
199
|
+
_key = key
|
|
200
|
+
attributes["key"] = _key if _key
|
|
96
201
|
table_name = @table.name
|
|
97
202
|
columns.each do |column|
|
|
98
203
|
next if column.is_a?(Groonga::IndexColumn)
|
|
99
|
-
|
|
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
|
|
100
208
|
end
|
|
101
209
|
attributes
|
|
102
210
|
end
|
|
103
211
|
|
|
212
|
+
# call-seq:
|
|
213
|
+
# record.delete
|
|
214
|
+
#
|
|
215
|
+
# レコードを削除する。
|
|
104
216
|
def delete
|
|
105
217
|
@table.delete(@id)
|
|
106
218
|
end
|
|
107
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
|
+
# 場合は例外が発生する。
|
|
108
235
|
def lock(options={}, &block)
|
|
109
236
|
@table.lock(options.merge(:id => @id), &block)
|
|
110
237
|
end
|
|
111
238
|
|
|
239
|
+
# call-seq:
|
|
240
|
+
# record.unlock(options={})
|
|
241
|
+
#
|
|
242
|
+
# レコードが所属するテーブルのロックを解除する。
|
|
243
|
+
#
|
|
244
|
+
# 利用可能なオプションは現在は無い。
|
|
112
245
|
def unlock(options={})
|
|
113
246
|
@table.unlock(options.merge(:id => @id))
|
|
114
247
|
end
|
|
115
248
|
|
|
249
|
+
# call-seq:
|
|
250
|
+
# record.clear_lock(options={})
|
|
251
|
+
#
|
|
252
|
+
# レコードが所属するテーブルのロックを強制的に解除する。
|
|
253
|
+
#
|
|
254
|
+
# 利用可能なオプションは現在は無い。
|
|
116
255
|
def clear_lock(options={})
|
|
117
256
|
@table.clear_lock(options.merge(:id => @id))
|
|
118
257
|
end
|
|
119
258
|
|
|
259
|
+
# call-seq:
|
|
260
|
+
# record.locked?(options={}) -> true/false
|
|
261
|
+
#
|
|
262
|
+
# レコードが所属するテーブルがロックされていれば+true+を返す。
|
|
263
|
+
#
|
|
264
|
+
# 利用可能なオプションは現在は無い。
|
|
120
265
|
def locked?(options={})
|
|
121
266
|
@table.locked?(options.merge(:id => @id))
|
|
122
267
|
end
|
|
123
268
|
|
|
124
269
|
private
|
|
125
|
-
def column(name)
|
|
270
|
+
def column(name) # :nodoc:
|
|
126
271
|
_column = @table.column(name.to_s)
|
|
127
|
-
raise
|
|
272
|
+
raise NoSuchColumn, "column(#{name.inspect}) is nil" if _column.nil?
|
|
128
273
|
_column
|
|
129
274
|
end
|
|
130
275
|
end
|