rroonga 1.3.0 → 1.3.1
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/Rakefile +33 -2
- data/benchmark/common.rb +2 -2
- data/benchmark/read-write-many-small-items.rb +71 -62
- data/benchmark/write-many-small-items.rb +61 -53
- data/ext/groonga/rb-grn-context.c +23 -5
- data/ext/groonga/rb-grn-index-column.c +2 -6
- data/ext/groonga/rb-grn-operator.c +31 -1
- data/ext/groonga/rb-grn-variable-size-column.c +77 -1
- data/ext/groonga/rb-grn.h +2 -11
- data/ext/groonga/rb-groonga.c +1 -2
- data/lib/groonga/command.rb +169 -0
- data/lib/groonga/context.rb +4 -124
- data/lib/groonga/dumper.rb +10 -8
- data/lib/groonga/record.rb +7 -0
- data/lib/groonga/schema.rb +98 -7
- data/rroonga-build.rb +3 -3
- data/test/{test-context-select.rb → test-command-select.rb} +3 -3
- data/test/test-record.rb +18 -1
- data/test/test-schema-dumper.rb +48 -0
- data/test/test-schema-type.rb +35 -0
- data/test/test-schema.rb +81 -11
- data/test/test-table-select.rb +49 -38
- data/test/test-variable-size-column.rb +30 -0
- metadata +80 -82
- data/ext/groonga/rb-grn-query.c +0 -260
- data/test/test-query.rb +0 -22
data/test/test-table-select.rb
CHANGED
@@ -53,27 +53,37 @@ class TableSelectTest < Test::Unit::TestCase
|
|
53
53
|
:user => "darashi")
|
54
54
|
end
|
55
55
|
|
56
|
+
setup
|
57
|
+
def setup_variables
|
58
|
+
@result = nil
|
59
|
+
end
|
60
|
+
|
61
|
+
teardown
|
62
|
+
def teardown_expression_close
|
63
|
+
@result.expression.close if @result # TODO: We want to remove it.
|
64
|
+
end
|
65
|
+
|
56
66
|
def test_sub_expression
|
57
|
-
result = @comments.select do |record|
|
67
|
+
@result = @comments.select do |record|
|
58
68
|
record.match("Hello", "content") &
|
59
69
|
(record["created_at"] < Time.parse("2009-08-01"))
|
60
70
|
end
|
61
|
-
assert_equal_select_result([@comment2], result)
|
71
|
+
assert_equal_select_result([@comment2], @result)
|
62
72
|
end
|
63
73
|
|
64
74
|
def test_query
|
65
|
-
result = @comments.select("content:@Hello")
|
66
|
-
assert_equal_select_result([@comment1, @comment2], result)
|
75
|
+
@result = @comments.select("content:@Hello")
|
76
|
+
assert_equal_select_result([@comment1, @comment2], @result)
|
67
77
|
end
|
68
78
|
|
69
79
|
def test_query_with_parser
|
70
|
-
result = @comments.select("content @ \"Hello\"", :syntax => :script)
|
71
|
-
assert_equal_select_result([@comment1, @comment2], result)
|
80
|
+
@result = @comments.select("content @ \"Hello\"", :syntax => :script)
|
81
|
+
assert_equal_select_result([@comment1, @comment2], @result)
|
72
82
|
end
|
73
83
|
|
74
84
|
def test_query_with_default_column
|
75
|
-
result = @comments.select("Hello", {:default_column => 'content'})
|
76
|
-
assert_equal_select_result([@comment1, @comment2], result)
|
85
|
+
@result = @comments.select("Hello", {:default_column => 'content'})
|
86
|
+
assert_equal_select_result([@comment1, @comment2], @result)
|
77
87
|
end
|
78
88
|
|
79
89
|
def test_expression
|
@@ -82,104 +92,105 @@ class TableSelectTest < Test::Unit::TestCase
|
|
82
92
|
expression.append_object(variable)
|
83
93
|
expression.parse("content:@Hello", :syntax => :query)
|
84
94
|
expression.compile
|
85
|
-
result = @comments.select(expression)
|
86
|
-
assert_equal(expression, result.expression)
|
87
|
-
assert_equal_select_result([@comment1, @comment2], result)
|
95
|
+
@result = @comments.select(expression)
|
96
|
+
assert_equal(expression, @result.expression)
|
97
|
+
assert_equal_select_result([@comment1, @comment2], @result)
|
88
98
|
end
|
89
99
|
|
90
100
|
def test_query_with_block
|
91
|
-
result = @comments.select("content:@Hello") do |record|
|
101
|
+
@result = @comments.select("content:@Hello") do |record|
|
92
102
|
record["created_at"] < Time.parse("2009-08-01")
|
93
103
|
end
|
94
|
-
assert_equal_select_result([@comment2], result)
|
104
|
+
assert_equal_select_result([@comment2], @result)
|
95
105
|
end
|
96
106
|
|
97
107
|
def test_query_with_block_match
|
98
|
-
result = @comments.select("content:@Hello") do |record|
|
108
|
+
@result = @comments.select("content:@Hello") do |record|
|
99
109
|
record.match("World", "content")
|
100
110
|
end
|
101
|
-
assert_equal_select_result([@comment2], result)
|
111
|
+
assert_equal_select_result([@comment2], @result)
|
102
112
|
end
|
103
113
|
|
104
114
|
def test_without_block
|
115
|
+
@result = @comments.select
|
105
116
|
assert_equal_select_result([@comment1, @comment2,
|
106
117
|
@comment3, @japanese_comment],
|
107
|
-
@
|
118
|
+
@result)
|
108
119
|
end
|
109
120
|
|
110
121
|
def test_query_japanese
|
111
|
-
result = @comments.select("content:@ボロTV")
|
112
|
-
assert_equal_select_result([@japanese_comment], result)
|
122
|
+
@result = @comments.select("content:@ボロTV")
|
123
|
+
assert_equal_select_result([@japanese_comment], @result)
|
113
124
|
end
|
114
125
|
|
115
126
|
def test_but_query
|
116
|
-
result = @comments.select do |record|
|
127
|
+
@result = @comments.select do |record|
|
117
128
|
record["content"].match "Hello -World"
|
118
129
|
end
|
119
|
-
assert_equal_select_result([@comment1], result)
|
130
|
+
assert_equal_select_result([@comment1], @result)
|
120
131
|
end
|
121
132
|
|
122
133
|
def test_query_with_three_terms
|
123
|
-
result = @comments.select do |record|
|
134
|
+
@result = @comments.select do |record|
|
124
135
|
record["content"].match "Say Hello World"
|
125
136
|
end
|
126
|
-
assert_equal_select_result([], result)
|
137
|
+
assert_equal_select_result([], @result)
|
127
138
|
end
|
128
139
|
|
129
140
|
def test_query_with_brackets
|
130
|
-
result = @comments.select do |record|
|
141
|
+
@result = @comments.select do |record|
|
131
142
|
record["content"].match "Say (Hello World)"
|
132
143
|
end
|
133
|
-
assert_equal_select_result([], result)
|
144
|
+
assert_equal_select_result([], @result)
|
134
145
|
end
|
135
146
|
|
136
147
|
def test_equal_reference_column_by_key
|
137
|
-
result = @comments.select do |record|
|
148
|
+
@result = @comments.select do |record|
|
138
149
|
record["user"] == "darashi"
|
139
150
|
end
|
140
|
-
assert_equal_select_result([@japanese_comment], result)
|
151
|
+
assert_equal_select_result([@japanese_comment], @result)
|
141
152
|
end
|
142
153
|
|
143
154
|
def test_not_equal_reference_column_by_key
|
144
|
-
result = @comments.select('user != "darashi"', :syntax => :script)
|
155
|
+
@result = @comments.select('user != "darashi"', :syntax => :script)
|
145
156
|
assert_equal_select_result([@comment1, @comment2, @comment3],
|
146
|
-
result)
|
157
|
+
@result)
|
147
158
|
end
|
148
159
|
|
149
160
|
def test_not_equal_block
|
150
161
|
only_ruby19
|
151
|
-
result = @comments.select do |record|
|
162
|
+
@result = @comments.select do |record|
|
152
163
|
record.user != "darashi"
|
153
164
|
end
|
154
165
|
assert_equal_select_result([@comment1, @comment2, @comment3],
|
155
|
-
result)
|
166
|
+
@result)
|
156
167
|
end
|
157
168
|
|
158
169
|
def test_equal_reference_column_by_nonexistent_key
|
159
|
-
result = @comments.select do |record|
|
170
|
+
@result = @comments.select do |record|
|
160
171
|
record["user"] == "nonexistent"
|
161
172
|
end
|
162
|
-
assert_equal_select_result([], result)
|
173
|
+
assert_equal_select_result([], @result)
|
163
174
|
end
|
164
175
|
|
165
176
|
def test_query_key
|
166
|
-
result = @users.select do |record|
|
177
|
+
@result = @users.select do |record|
|
167
178
|
record["_key"] =~ "mori"
|
168
179
|
end
|
169
|
-
assert_equal_select_result([@users["morita"]], result)
|
180
|
+
assert_equal_select_result([@users["morita"]], @result)
|
170
181
|
end
|
171
182
|
|
172
183
|
def test_symbol
|
173
|
-
result = @comments.select do |record|
|
184
|
+
@result = @comments.select do |record|
|
174
185
|
record[:content].match("Say Hello World")
|
175
186
|
end
|
176
|
-
assert_equal_select_result([], result)
|
187
|
+
assert_equal_select_result([], @result)
|
177
188
|
end
|
178
189
|
|
179
190
|
def test_method
|
180
|
-
result = @comments.select do |record|
|
191
|
+
@result = @comments.select do |record|
|
181
192
|
record.content.match("Say Hello World")
|
182
193
|
end
|
183
|
-
assert_equal_select_result([], result)
|
194
|
+
assert_equal_select_result([], @result)
|
184
195
|
end
|
185
196
|
end
|
@@ -62,6 +62,36 @@ class VariableSizeColumnTest < Test::Unit::TestCase
|
|
62
62
|
assert_not_predicate(@nick_names, :scalar?)
|
63
63
|
end
|
64
64
|
|
65
|
+
def test_compressed?
|
66
|
+
description = @users.define_column("description", "ShortText",
|
67
|
+
:compress => :zlib)
|
68
|
+
if context.support_zlib?
|
69
|
+
assert_predicate(description, :compressed?)
|
70
|
+
else
|
71
|
+
assert_not_predicate(description, :compressed?)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_compressed_zlib?
|
76
|
+
description = @users.define_column("description", "ShortText",
|
77
|
+
:compress => :zlib)
|
78
|
+
if context.support_zlib?
|
79
|
+
assert_send([description, :compressed?, :zlib])
|
80
|
+
else
|
81
|
+
assert_not_send([description, :compressed?, :zlib])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_compressed_lzo?
|
86
|
+
description = @users.define_column("description", "ShortText",
|
87
|
+
:compress => :lzo)
|
88
|
+
if context.support_lzo?
|
89
|
+
assert_send([description, :compressed?, :lzo])
|
90
|
+
else
|
91
|
+
assert_not_send([description, :compressed?, :lzo])
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
65
95
|
def test_inspect
|
66
96
|
assert_equal("#<Groonga::VariableSizeColumn " +
|
67
97
|
"id: <#{@name.id}>, " +
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rroonga
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 1.3.
|
9
|
+
- 1
|
10
|
+
version: 1.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kouhei Sutou
|
@@ -19,7 +19,7 @@ autorequire:
|
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
21
|
|
22
|
-
date:
|
22
|
+
date: 2012-01-30 00:00:00 Z
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
25
25
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
@@ -206,7 +206,6 @@ files:
|
|
206
206
|
- ext/groonga/rb-grn-plugin.c
|
207
207
|
- ext/groonga/rb-grn-posting.c
|
208
208
|
- ext/groonga/rb-grn-procedure.c
|
209
|
-
- ext/groonga/rb-grn-query.c
|
210
209
|
- ext/groonga/rb-grn-record.c
|
211
210
|
- ext/groonga/rb-grn-snippet.c
|
212
211
|
- ext/groonga/rb-grn-table-cursor-key-support.c
|
@@ -225,6 +224,7 @@ files:
|
|
225
224
|
- ext/groonga/rb-groonga.c
|
226
225
|
- extconf.rb
|
227
226
|
- lib/groonga.rb
|
227
|
+
- lib/groonga/command.rb
|
228
228
|
- lib/groonga/context.rb
|
229
229
|
- lib/groonga/dumper.rb
|
230
230
|
- lib/groonga/expression-builder-19.rb
|
@@ -241,54 +241,53 @@ files:
|
|
241
241
|
- rroonga-build.rb
|
242
242
|
- README.textile
|
243
243
|
- TODO
|
244
|
-
- test/test-
|
244
|
+
- test/test-schema.rb
|
245
|
+
- test/test-vector-column.rb
|
246
|
+
- test/test-schema-dumper.rb
|
247
|
+
- test/run-test.rb
|
245
248
|
- test/test-table-cursor.rb
|
246
|
-
- test/test-
|
247
|
-
- test/test-database-dumper.rb
|
248
|
-
- test/test-index-column.rb
|
249
|
-
- test/test-context-select.rb
|
250
|
-
- test/groonga-test-utils.rb
|
251
|
-
- test/test-pagination.rb
|
252
|
-
- test/test-table.rb
|
253
|
-
- test/test-variable-size-column.rb
|
254
|
-
- test/test-plugin.rb
|
249
|
+
- test/test-procedure.rb
|
255
250
|
- test/test-hash.rb
|
251
|
+
- test/test-expression.rb
|
252
|
+
- test/test-version.rb
|
253
|
+
- test/test-remote.rb
|
254
|
+
- test/test-table-offset-and-limit.rb
|
255
|
+
- test/test-expression-builder.rb
|
256
256
|
- test/test-encoding.rb
|
257
|
-
- test/test-
|
257
|
+
- test/test-snippet.rb
|
258
|
+
- test/test-index-cursor.rb
|
258
259
|
- test/test-type.rb
|
259
|
-
- test/test-
|
260
|
-
- test/test-
|
261
|
-
- test/test-
|
262
|
-
- test/test-
|
263
|
-
- test/test-expression-builder.rb
|
260
|
+
- test/test-table-dumper.rb
|
261
|
+
- test/test-table.rb
|
262
|
+
- test/test-pagination.rb
|
263
|
+
- test/groonga-test-utils.rb
|
264
264
|
- test/test-logger.rb
|
265
|
+
- test/test-context.rb
|
266
|
+
- test/test-table-select-weight.rb
|
267
|
+
- test/test-exception.rb
|
268
|
+
- test/test-table-select-normalize.rb
|
269
|
+
- test/test-command-select.rb
|
270
|
+
- test/test-gqtp.rb
|
271
|
+
- test/test-database-dumper.rb
|
272
|
+
- test/test-index-column.rb
|
273
|
+
- test/test-plugin.rb
|
274
|
+
- test/test-query-log.rb
|
275
|
+
- test/test-variable-size-column.rb
|
276
|
+
- test/test-schema-create-table.rb
|
265
277
|
- test/test-array.rb
|
266
|
-
- test/test-record.rb
|
267
|
-
- test/test-column.rb
|
268
278
|
- test/test-fix-size-column.rb
|
269
|
-
- test/
|
270
|
-
- test/test-
|
271
|
-
- test/test-
|
272
|
-
- test/test-table-dumper.rb
|
273
|
-
- test/test-schema.rb
|
279
|
+
- test/test-schema-type.rb
|
280
|
+
- test/test-table-select.rb
|
281
|
+
- test/test-schema-view.rb
|
274
282
|
- test/test-view.rb
|
283
|
+
- test/test-variable.rb
|
284
|
+
- test/test-column.rb
|
285
|
+
- test/test-patricia-trie.rb
|
275
286
|
- test/test-table-select-mecab.rb
|
276
|
-
- test/test-
|
277
|
-
- test/test-
|
278
|
-
- test/test-vector-column.rb
|
279
|
-
- test/test-version.rb
|
280
|
-
- test/test-schema-view.rb
|
281
|
-
- test/test-index-cursor.rb
|
287
|
+
- test/test-accessor.rb
|
288
|
+
- test/test-database.rb
|
282
289
|
- test/test-double-array-trie.rb
|
283
|
-
- test/test-
|
284
|
-
- test/test-schema-dumper.rb
|
285
|
-
- test/test-query.rb
|
286
|
-
- test/test-schema-type.rb
|
287
|
-
- test/test-table-select-weight.rb
|
288
|
-
- test/test-gqtp.rb
|
289
|
-
- test/test-context.rb
|
290
|
-
- test/test-snippet.rb
|
291
|
-
- test/test-table-offset-and-limit.rb
|
290
|
+
- test/test-record.rb
|
292
291
|
homepage: http://groonga.rubyforge.org/
|
293
292
|
licenses:
|
294
293
|
- LGPLv2
|
@@ -318,56 +317,55 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
318
317
|
requirements: []
|
319
318
|
|
320
319
|
rubyforge_project: groonga
|
321
|
-
rubygems_version: 1.8.
|
320
|
+
rubygems_version: 1.8.15
|
322
321
|
signing_key:
|
323
322
|
specification_version: 3
|
324
323
|
summary: Ruby bindings for groonga that provide full text search and column store features.
|
325
324
|
test_files:
|
326
|
-
- test/test-
|
325
|
+
- test/test-schema.rb
|
326
|
+
- test/test-vector-column.rb
|
327
|
+
- test/test-schema-dumper.rb
|
328
|
+
- test/run-test.rb
|
327
329
|
- test/test-table-cursor.rb
|
328
|
-
- test/test-
|
329
|
-
- test/test-database-dumper.rb
|
330
|
-
- test/test-index-column.rb
|
331
|
-
- test/test-context-select.rb
|
332
|
-
- test/groonga-test-utils.rb
|
333
|
-
- test/test-pagination.rb
|
334
|
-
- test/test-table.rb
|
335
|
-
- test/test-variable-size-column.rb
|
336
|
-
- test/test-plugin.rb
|
330
|
+
- test/test-procedure.rb
|
337
331
|
- test/test-hash.rb
|
332
|
+
- test/test-expression.rb
|
333
|
+
- test/test-version.rb
|
334
|
+
- test/test-remote.rb
|
335
|
+
- test/test-table-offset-and-limit.rb
|
336
|
+
- test/test-expression-builder.rb
|
338
337
|
- test/test-encoding.rb
|
339
|
-
- test/test-
|
338
|
+
- test/test-snippet.rb
|
339
|
+
- test/test-index-cursor.rb
|
340
340
|
- test/test-type.rb
|
341
|
-
- test/test-
|
342
|
-
- test/test-
|
343
|
-
- test/test-
|
344
|
-
- test/test-
|
345
|
-
- test/test-expression-builder.rb
|
341
|
+
- test/test-table-dumper.rb
|
342
|
+
- test/test-table.rb
|
343
|
+
- test/test-pagination.rb
|
344
|
+
- test/groonga-test-utils.rb
|
346
345
|
- test/test-logger.rb
|
346
|
+
- test/test-context.rb
|
347
|
+
- test/test-table-select-weight.rb
|
348
|
+
- test/test-exception.rb
|
349
|
+
- test/test-table-select-normalize.rb
|
350
|
+
- test/test-command-select.rb
|
351
|
+
- test/test-gqtp.rb
|
352
|
+
- test/test-database-dumper.rb
|
353
|
+
- test/test-index-column.rb
|
354
|
+
- test/test-plugin.rb
|
355
|
+
- test/test-query-log.rb
|
356
|
+
- test/test-variable-size-column.rb
|
357
|
+
- test/test-schema-create-table.rb
|
347
358
|
- test/test-array.rb
|
348
|
-
- test/test-record.rb
|
349
|
-
- test/test-column.rb
|
350
359
|
- test/test-fix-size-column.rb
|
351
|
-
- test/
|
352
|
-
- test/test-
|
353
|
-
- test/test-
|
354
|
-
- test/test-table-dumper.rb
|
355
|
-
- test/test-schema.rb
|
360
|
+
- test/test-schema-type.rb
|
361
|
+
- test/test-table-select.rb
|
362
|
+
- test/test-schema-view.rb
|
356
363
|
- test/test-view.rb
|
364
|
+
- test/test-variable.rb
|
365
|
+
- test/test-column.rb
|
366
|
+
- test/test-patricia-trie.rb
|
357
367
|
- test/test-table-select-mecab.rb
|
358
|
-
- test/test-
|
359
|
-
- test/test-
|
360
|
-
- test/test-vector-column.rb
|
361
|
-
- test/test-version.rb
|
362
|
-
- test/test-schema-view.rb
|
363
|
-
- test/test-index-cursor.rb
|
368
|
+
- test/test-accessor.rb
|
369
|
+
- test/test-database.rb
|
364
370
|
- test/test-double-array-trie.rb
|
365
|
-
- test/test-
|
366
|
-
- test/test-schema-dumper.rb
|
367
|
-
- test/test-query.rb
|
368
|
-
- test/test-schema-type.rb
|
369
|
-
- test/test-table-select-weight.rb
|
370
|
-
- test/test-gqtp.rb
|
371
|
-
- test/test-context.rb
|
372
|
-
- test/test-snippet.rb
|
373
|
-
- test/test-table-offset-and-limit.rb
|
371
|
+
- test/test-record.rb
|
data/ext/groonga/rb-grn-query.c
DELETED
@@ -1,260 +0,0 @@
|
|
1
|
-
/* -*- coding: utf-8; c-file-style: "ruby" -*- */
|
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
|
-
|
19
|
-
#include "rb-grn.h"
|
20
|
-
|
21
|
-
/*
|
22
|
-
* Document-class: Groonga::Query
|
23
|
-
*
|
24
|
-
* インデックスを用いた検索用のクエリのためのオブジェクト。
|
25
|
-
* Groonga::IndexColumn#searchに渡すことができる。(このクラ
|
26
|
-
* スは非推奨で、代わりにGroonga::Expressionを使用すること)
|
27
|
-
*
|
28
|
-
*/
|
29
|
-
|
30
|
-
#define SELF(object) (rb_rb_grn_query_from_ruby_object(object))
|
31
|
-
|
32
|
-
typedef struct _RbGrnQuery RbGrnQuery;
|
33
|
-
struct _RbGrnQuery
|
34
|
-
{
|
35
|
-
grn_ctx *context;
|
36
|
-
grn_query *query;
|
37
|
-
grn_bool owner;
|
38
|
-
};
|
39
|
-
|
40
|
-
VALUE rb_cGrnQuery;
|
41
|
-
|
42
|
-
static RbGrnQuery *
|
43
|
-
rb_rb_grn_query_from_ruby_object (VALUE object)
|
44
|
-
{
|
45
|
-
RbGrnQuery *rb_grn_query;
|
46
|
-
|
47
|
-
if (!RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cGrnQuery))) {
|
48
|
-
rb_raise(rb_eTypeError, "not a groonga query");
|
49
|
-
}
|
50
|
-
|
51
|
-
Data_Get_Struct(object, RbGrnQuery, rb_grn_query);
|
52
|
-
if (!rb_grn_query)
|
53
|
-
rb_raise(rb_eGrnError, "groonga query is NULL");
|
54
|
-
|
55
|
-
return rb_grn_query;
|
56
|
-
}
|
57
|
-
|
58
|
-
grn_query *
|
59
|
-
rb_grn_query_from_ruby_object (VALUE object)
|
60
|
-
{
|
61
|
-
if (NIL_P(object))
|
62
|
-
return NULL;
|
63
|
-
|
64
|
-
return SELF(object)->query;
|
65
|
-
}
|
66
|
-
|
67
|
-
static void
|
68
|
-
rb_rb_grn_query_free (void *object)
|
69
|
-
{
|
70
|
-
RbGrnQuery *rb_grn_query = object;
|
71
|
-
|
72
|
-
if (rb_grn_query->owner && rb_grn_query->context && rb_grn_query->query)
|
73
|
-
grn_query_close(rb_grn_query->context, rb_grn_query->query);
|
74
|
-
|
75
|
-
xfree(object);
|
76
|
-
}
|
77
|
-
|
78
|
-
VALUE
|
79
|
-
rb_grn_query_to_ruby_object (grn_ctx *context, grn_query *query)
|
80
|
-
{
|
81
|
-
RbGrnQuery *rb_grn_query;
|
82
|
-
|
83
|
-
if (!query)
|
84
|
-
return Qnil;
|
85
|
-
|
86
|
-
rb_grn_query = ALLOC(RbGrnQuery);
|
87
|
-
rb_grn_query->context = context;
|
88
|
-
rb_grn_query->query = query;
|
89
|
-
rb_grn_query->owner = GRN_FALSE;
|
90
|
-
|
91
|
-
return Data_Wrap_Struct(rb_cGrnQuery, NULL,
|
92
|
-
rb_rb_grn_query_free, rb_grn_query);
|
93
|
-
}
|
94
|
-
|
95
|
-
static VALUE
|
96
|
-
rb_grn_query_alloc (VALUE klass)
|
97
|
-
{
|
98
|
-
return Data_Wrap_Struct(klass, NULL, rb_rb_grn_query_free, NULL);
|
99
|
-
}
|
100
|
-
|
101
|
-
grn_operator
|
102
|
-
rb_grn_operator_from_ruby_object (VALUE rb_operator)
|
103
|
-
{
|
104
|
-
grn_operator operator = GRN_OP_OR;
|
105
|
-
|
106
|
-
if (NIL_P(rb_operator) ||
|
107
|
-
rb_grn_equal_option(rb_operator, "or") ||
|
108
|
-
rb_grn_equal_option(rb_operator, "||")) {
|
109
|
-
operator = GRN_OP_OR;
|
110
|
-
} else if (rb_grn_equal_option(rb_operator, "and") ||
|
111
|
-
rb_grn_equal_option(rb_operator, "+") ||
|
112
|
-
rb_grn_equal_option(rb_operator, "&&")) {
|
113
|
-
operator = GRN_OP_AND;
|
114
|
-
} else if (rb_grn_equal_option(rb_operator, "but") ||
|
115
|
-
rb_grn_equal_option(rb_operator, "not") ||
|
116
|
-
rb_grn_equal_option(rb_operator, "-")) {
|
117
|
-
operator = GRN_OP_BUT;
|
118
|
-
} else if (rb_grn_equal_option(rb_operator, "adjust") ||
|
119
|
-
rb_grn_equal_option(rb_operator, ">")) {
|
120
|
-
operator = GRN_OP_ADJUST;
|
121
|
-
} else {
|
122
|
-
rb_raise(rb_eArgError,
|
123
|
-
"operator should be one of "
|
124
|
-
"[:or, :||, :and, :+, :&&, :but, :not, :-, :adjust, :>]: <%s>",
|
125
|
-
rb_grn_inspect(rb_operator));
|
126
|
-
}
|
127
|
-
|
128
|
-
return operator;
|
129
|
-
}
|
130
|
-
|
131
|
-
/*
|
132
|
-
* call-seq:
|
133
|
-
* query.new(string, options={})
|
134
|
-
*
|
135
|
-
* _string_ をパースした上で、クエリを作成する。作成されたオ
|
136
|
-
* ブジェクトはGroonga::IndexColumn#searchに渡すことで使用す
|
137
|
-
* ることができる。
|
138
|
-
*
|
139
|
-
* _options_ に指定可能な値は以下の通り。
|
140
|
-
* @param options [::Hash] The name and value
|
141
|
-
* pairs. Omitted names are initialized as the default value.
|
142
|
-
* @option options :context (Groonga::Context.default) The context
|
143
|
-
* クエリが利用するGroonga::Context。
|
144
|
-
*
|
145
|
-
* @option options :default_operator The default_operator
|
146
|
-
* 演算子の既定値(演算子を省略した場合にどの演算を行うか)
|
147
|
-
* を指定する。
|
148
|
-
*
|
149
|
-
* [Groonga::Operator::OR]
|
150
|
-
* [Groonga::Operator::AND]
|
151
|
-
* [Groonga::Operator::BUT]
|
152
|
-
* [Groonga::Operator::ADJUST]
|
153
|
-
* (FIXME: 挙動の違いを検証する必要性あり?
|
154
|
-
* Groonga::Expressionとの関連性は?)
|
155
|
-
*
|
156
|
-
* @option options :max_expressions
|
157
|
-
* 検索クエリに指定する式の最大値を指定する。
|
158
|
-
*/
|
159
|
-
static VALUE
|
160
|
-
rb_grn_query_initialize (int argc, VALUE *argv, VALUE self)
|
161
|
-
{
|
162
|
-
RbGrnQuery *rb_grn_query;
|
163
|
-
grn_ctx *context = NULL;
|
164
|
-
grn_query *query;
|
165
|
-
char *query_string;
|
166
|
-
unsigned int query_string_length;
|
167
|
-
grn_operator default_operator;
|
168
|
-
int max_expressions = RB_GRN_QUERY_DEFAULT_MAX_EXPRESSIONS;
|
169
|
-
VALUE rb_query_string, options, rb_context, rb_default_operator;
|
170
|
-
VALUE rb_max_expressions;
|
171
|
-
|
172
|
-
rb_scan_args(argc, argv, "11", &rb_query_string, &options);
|
173
|
-
|
174
|
-
query_string = StringValuePtr(rb_query_string);
|
175
|
-
query_string_length = RSTRING_LEN(rb_query_string);
|
176
|
-
|
177
|
-
rb_grn_scan_options(options,
|
178
|
-
"context", &rb_context,
|
179
|
-
"default_operator", &rb_default_operator,
|
180
|
-
"max_expressions", &rb_max_expressions,
|
181
|
-
NULL);
|
182
|
-
|
183
|
-
context = rb_grn_context_ensure(&rb_context);
|
184
|
-
|
185
|
-
default_operator = RVAL2GRNOPERATOR(rb_default_operator);
|
186
|
-
|
187
|
-
if (!NIL_P(rb_max_expressions))
|
188
|
-
max_expressions = NUM2INT(rb_max_expressions);
|
189
|
-
|
190
|
-
query = grn_query_open(context, query_string, query_string_length,
|
191
|
-
default_operator, max_expressions);
|
192
|
-
rb_grn_context_check(context, rb_ary_new4(argc, argv));
|
193
|
-
|
194
|
-
rb_grn_query = ALLOC(RbGrnQuery);
|
195
|
-
DATA_PTR(self) = rb_grn_query;
|
196
|
-
rb_grn_query->context = context;
|
197
|
-
rb_grn_query->query = query;
|
198
|
-
rb_grn_query->owner = GRN_TRUE;
|
199
|
-
|
200
|
-
rb_iv_set(self, "@context", rb_context);
|
201
|
-
|
202
|
-
return Qnil;
|
203
|
-
}
|
204
|
-
|
205
|
-
/*
|
206
|
-
* call-seq:
|
207
|
-
* query.close
|
208
|
-
*
|
209
|
-
* _query_ が使用しているリソースを開放する。これ以降 _query_ を
|
210
|
-
* 使うことはできない。
|
211
|
-
*/
|
212
|
-
static VALUE
|
213
|
-
rb_grn_query_close (VALUE self)
|
214
|
-
{
|
215
|
-
RbGrnQuery *rb_grn_query;
|
216
|
-
|
217
|
-
rb_grn_query = SELF(self);
|
218
|
-
if (rb_grn_query->context && rb_grn_query->query) {
|
219
|
-
grn_rc rc;
|
220
|
-
|
221
|
-
rc = grn_query_close(rb_grn_query->context, rb_grn_query->query);
|
222
|
-
rb_grn_query->context = NULL;
|
223
|
-
rb_grn_query->query = NULL;
|
224
|
-
rb_grn_rc_check(rc, self);
|
225
|
-
}
|
226
|
-
return Qnil;
|
227
|
-
}
|
228
|
-
|
229
|
-
/*
|
230
|
-
* call-seq:
|
231
|
-
* query.closed? -> true/false
|
232
|
-
*
|
233
|
-
* _query_ が開放済みの場合は +true+ を返し、そうでない場合は
|
234
|
-
* +false+ を返す。
|
235
|
-
*/
|
236
|
-
static VALUE
|
237
|
-
rb_grn_query_closed_p (VALUE self)
|
238
|
-
{
|
239
|
-
RbGrnQuery *rb_grn_query;
|
240
|
-
|
241
|
-
rb_grn_query = SELF(self);
|
242
|
-
if (rb_grn_query->context && rb_grn_query->query)
|
243
|
-
return Qfalse;
|
244
|
-
else
|
245
|
-
return Qtrue;
|
246
|
-
}
|
247
|
-
|
248
|
-
void
|
249
|
-
rb_grn_init_query (VALUE mGrn)
|
250
|
-
{
|
251
|
-
rb_cGrnQuery = rb_define_class_under(mGrn, "Query", rb_cObject);
|
252
|
-
rb_define_alloc_func(rb_cGrnQuery, rb_grn_query_alloc);
|
253
|
-
|
254
|
-
rb_define_method(rb_cGrnQuery, "initialize",
|
255
|
-
rb_grn_query_initialize, -1);
|
256
|
-
rb_define_method(rb_cGrnQuery, "close",
|
257
|
-
rb_grn_query_close, 0);
|
258
|
-
rb_define_method(rb_cGrnQuery, "closed?",
|
259
|
-
rb_grn_query_closed_p, 0);
|
260
|
-
}
|