rroonga 3.0.5-x86-mingw32 → 3.0.6-x86-mingw32

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.
Files changed (49) hide show
  1. data/AUTHORS +5 -0
  2. data/Gemfile +20 -0
  3. data/Rakefile +187 -0
  4. data/doc/text/news.textile +7 -0
  5. data/doc/text/tutorial.textile +0 -2
  6. data/ext/groonga/extconf.rb +7 -1
  7. data/ext/groonga/rb-grn-accessor.c +11 -11
  8. data/ext/groonga/rb-grn-array.c +25 -25
  9. data/ext/groonga/rb-grn-column.c +106 -106
  10. data/ext/groonga/rb-grn-context.c +121 -121
  11. data/ext/groonga/rb-grn-database.c +78 -78
  12. data/ext/groonga/rb-grn-double-array-trie.c +92 -92
  13. data/ext/groonga/rb-grn-encoding-support.c +1 -1
  14. data/ext/groonga/rb-grn-encoding.c +28 -28
  15. data/ext/groonga/rb-grn-exception.c +9 -9
  16. data/ext/groonga/rb-grn-expression-builder.c +6 -6
  17. data/ext/groonga/rb-grn-expression.c +87 -87
  18. data/ext/groonga/rb-grn-fix-size-column.c +12 -12
  19. data/ext/groonga/rb-grn-geo-point.c +2 -2
  20. data/ext/groonga/rb-grn-hash.c +38 -38
  21. data/ext/groonga/rb-grn-index-column.c +191 -191
  22. data/ext/groonga/rb-grn-index-cursor.c +29 -29
  23. data/ext/groonga/rb-grn-logger.c +36 -36
  24. data/ext/groonga/rb-grn-normalizer.c +10 -10
  25. data/ext/groonga/rb-grn-patricia-trie.c +196 -196
  26. data/ext/groonga/rb-grn-plugin.c +5 -5
  27. data/ext/groonga/rb-grn-posting.c +2 -2
  28. data/ext/groonga/rb-grn-procedure.c +2 -2
  29. data/ext/groonga/rb-grn-query-logger.c +1 -1
  30. data/ext/groonga/rb-grn-record.c +1 -1
  31. data/ext/groonga/rb-grn-snippet.c +14 -14
  32. data/ext/groonga/rb-grn-table-cursor-key-support.c +4 -4
  33. data/ext/groonga/rb-grn-table-cursor.c +52 -52
  34. data/ext/groonga/rb-grn-table-key-support.c +209 -209
  35. data/ext/groonga/rb-grn-type.c +18 -18
  36. data/ext/groonga/rb-grn-utils.c +332 -314
  37. data/ext/groonga/rb-grn-variable-size-column.c +34 -34
  38. data/ext/groonga/rb-grn-variable.c +2 -2
  39. data/ext/groonga/rb-grn.h +240 -232
  40. data/ext/groonga/rb-groonga.c +10 -10
  41. data/lib/1.9/groonga.so +0 -0
  42. data/lib/2.0/groonga.so +0 -0
  43. data/rroonga-build.rb +7 -0
  44. data/rroonga.gemspec +1 -1
  45. data/test/test-hash.rb +4 -4
  46. data/test/test-index-column.rb +271 -257
  47. data/test/test-table-key-support.rb +78 -0
  48. data/test/test-table.rb +78 -51
  49. metadata +8 -3
@@ -25,10 +25,10 @@ VALUE rb_cGrnIndexCursor;
25
25
 
26
26
  VALUE
27
27
  rb_grn_index_cursor_to_ruby_object (grn_ctx *context,
28
- grn_obj *cursor,
29
- VALUE rb_table,
30
- VALUE rb_lexicon,
31
- grn_bool owner)
28
+ grn_obj *cursor,
29
+ VALUE rb_table,
30
+ VALUE rb_lexicon,
31
+ grn_bool owner)
32
32
  {
33
33
  VALUE rb_cursor;
34
34
 
@@ -41,19 +41,19 @@ rb_grn_index_cursor_to_ruby_object (grn_ctx *context,
41
41
 
42
42
  void
43
43
  rb_grn_index_cursor_deconstruct (RbGrnIndexCursor *rb_grn_index_cursor,
44
- grn_obj **cursor,
45
- grn_ctx **context,
46
- grn_id *domain_id,
47
- grn_obj **domain,
48
- grn_id *range_id,
49
- grn_obj **range)
44
+ grn_obj **cursor,
45
+ grn_ctx **context,
46
+ grn_id *domain_id,
47
+ grn_obj **domain,
48
+ grn_id *range_id,
49
+ grn_obj **range)
50
50
  {
51
51
  RbGrnObject *rb_grn_object;
52
52
 
53
53
  rb_grn_object = RB_GRN_OBJECT(rb_grn_index_cursor);
54
54
  rb_grn_object_deconstruct(rb_grn_object, cursor, context,
55
- domain_id, domain,
56
- range_id, range);
55
+ domain_id, domain,
56
+ range_id, range);
57
57
  }
58
58
 
59
59
  static VALUE
@@ -64,7 +64,7 @@ next_value (grn_ctx *context, grn_obj *cursor, VALUE rb_table, VALUE rb_lexicon)
64
64
 
65
65
  posting = grn_index_cursor_next(context, cursor, &term_id);
66
66
  if (!posting) {
67
- return Qnil;
67
+ return Qnil;
68
68
  }
69
69
 
70
70
  return rb_grn_posting_new(posting, term_id, rb_table, rb_lexicon);
@@ -78,13 +78,13 @@ rb_grn_index_cursor_next (VALUE self)
78
78
  grn_ctx *context;
79
79
 
80
80
  rb_grn_index_cursor_deconstruct(SELF(self), &cursor, &context,
81
- NULL, NULL, NULL, NULL);
81
+ NULL, NULL, NULL, NULL);
82
82
  if (context && cursor) {
83
- VALUE rb_table;
84
- VALUE rb_lexicon;
85
- rb_table = rb_iv_get(self, "@table");
86
- rb_lexicon = rb_iv_get(self, "@lexicon");
87
- rb_posting = next_value(context, cursor, rb_table, rb_lexicon);
83
+ VALUE rb_table;
84
+ VALUE rb_lexicon;
85
+ rb_table = rb_iv_get(self, "@table");
86
+ rb_lexicon = rb_iv_get(self, "@lexicon");
87
+ rb_posting = next_value(context, cursor, rb_table, rb_lexicon);
88
88
  }
89
89
 
90
90
  return rb_posting;
@@ -102,25 +102,25 @@ rb_grn_index_cursor_each (VALUE self)
102
102
  RETURN_ENUMERATOR(self, 0, NULL);
103
103
 
104
104
  rb_grn_index_cursor_deconstruct(SELF(self), &cursor, &context,
105
- NULL, NULL, NULL, NULL);
105
+ NULL, NULL, NULL, NULL);
106
106
 
107
107
  if (!context) {
108
- return Qnil;
108
+ return Qnil;
109
109
  }
110
110
 
111
111
  if (!cursor) {
112
- return Qnil;
112
+ return Qnil;
113
113
  }
114
114
 
115
115
  rb_table = rb_iv_get(self, "@table");
116
116
  rb_lexicon = rb_iv_get(self, "@lexicon");
117
117
  while (GRN_TRUE) {
118
- VALUE rb_posting;
119
- rb_posting = next_value(context, cursor, rb_table, rb_lexicon);
120
- if (NIL_P(rb_posting)) {
121
- break;
122
- }
123
- rb_yield(rb_posting);
118
+ VALUE rb_posting;
119
+ rb_posting = next_value(context, cursor, rb_table, rb_lexicon);
120
+ if (NIL_P(rb_posting)) {
121
+ break;
122
+ }
123
+ rb_yield(rb_posting);
124
124
  }
125
125
 
126
126
  return Qnil;
@@ -130,7 +130,7 @@ void
130
130
  rb_grn_init_index_cursor (VALUE mGrn)
131
131
  {
132
132
  rb_cGrnIndexCursor =
133
- rb_define_class_under(mGrn, "IndexCursor", rb_cGrnObject);
133
+ rb_define_class_under(mGrn, "IndexCursor", rb_cGrnObject);
134
134
  rb_define_alloc_func(rb_cGrnIndexCursor, rb_grn_object_alloc);
135
135
  rb_include_module(rb_cGrnIndexCursor, rb_mEnumerable);
136
136
 
@@ -85,38 +85,38 @@ rb_grn_log_level_to_ruby_object (grn_log_level level)
85
85
 
86
86
  switch (level) {
87
87
  case GRN_LOG_NONE:
88
- rb_level = RB_GRN_INTERN("none");
89
- break;
88
+ rb_level = RB_GRN_INTERN("none");
89
+ break;
90
90
  case GRN_LOG_EMERG:
91
- rb_level = RB_GRN_INTERN("emergency");
92
- break;
91
+ rb_level = RB_GRN_INTERN("emergency");
92
+ break;
93
93
  case GRN_LOG_ALERT:
94
- rb_level = RB_GRN_INTERN("alert");
95
- break;
94
+ rb_level = RB_GRN_INTERN("alert");
95
+ break;
96
96
  case GRN_LOG_CRIT:
97
- rb_level = RB_GRN_INTERN("critical");
98
- break;
97
+ rb_level = RB_GRN_INTERN("critical");
98
+ break;
99
99
  case GRN_LOG_ERROR:
100
- rb_level = RB_GRN_INTERN("error");
101
- break;
100
+ rb_level = RB_GRN_INTERN("error");
101
+ break;
102
102
  case GRN_LOG_WARNING:
103
- rb_level = RB_GRN_INTERN("warning");
104
- break;
103
+ rb_level = RB_GRN_INTERN("warning");
104
+ break;
105
105
  case GRN_LOG_NOTICE:
106
- rb_level = RB_GRN_INTERN("notice");
107
- break;
106
+ rb_level = RB_GRN_INTERN("notice");
107
+ break;
108
108
  case GRN_LOG_INFO:
109
- rb_level = RB_GRN_INTERN("info");
110
- break;
109
+ rb_level = RB_GRN_INTERN("info");
110
+ break;
111
111
  case GRN_LOG_DEBUG:
112
- rb_level = RB_GRN_INTERN("debug");
113
- break;
112
+ rb_level = RB_GRN_INTERN("debug");
113
+ break;
114
114
  case GRN_LOG_DUMP:
115
- rb_level = RB_GRN_INTERN("dump");
116
- break;
115
+ rb_level = RB_GRN_INTERN("dump");
116
+ break;
117
117
  default:
118
- rb_level = INT2NUM(level);
119
- break;
118
+ rb_level = INT2NUM(level);
119
+ break;
120
120
  }
121
121
 
122
122
  return rb_level;
@@ -133,10 +133,10 @@ rb_grn_logger_reset_with_error_check (VALUE klass, grn_ctx *context)
133
133
  rb_cv_set(klass, "@@current_logger", Qnil);
134
134
 
135
135
  if (context) {
136
- grn_logger_set(context, NULL);
137
- rb_grn_context_check(context, current_logger);
136
+ grn_logger_set(context, NULL);
137
+ rb_grn_context_check(context, current_logger);
138
138
  } else {
139
- grn_logger_set(NULL, NULL);
139
+ grn_logger_set(NULL, NULL);
140
140
  }
141
141
  }
142
142
 
@@ -148,8 +148,8 @@ rb_grn_logger_reset (VALUE klass)
148
148
 
149
149
  static void
150
150
  rb_grn_logger_log (grn_ctx *ctx, grn_log_level level,
151
- const char *timestamp, const char *title, const char *message,
152
- const char *location, void *user_data)
151
+ const char *timestamp, const char *title, const char *message,
152
+ const char *location, void *user_data)
153
153
  {
154
154
  VALUE handler = (VALUE)user_data;
155
155
 
@@ -162,7 +162,7 @@ rb_grn_logger_log (grn_ctx *ctx, grn_log_level level,
162
162
  rb_str_new2(timestamp),
163
163
  rb_str_new2(title),
164
164
  rb_str_new2(message),
165
- rb_str_new2(location));
165
+ rb_str_new2(location));
166
166
  }
167
167
 
168
168
  static void
@@ -246,20 +246,20 @@ rb_grn_logger_s_register (int argc, VALUE *argv, VALUE klass)
246
246
  "flags", &rb_flags,
247
247
  NULL);
248
248
  if (!NIL_P(rb_max_level)) {
249
- max_level = RVAL2GRNLOGLEVEL(rb_max_level);
249
+ max_level = RVAL2GRNLOGLEVEL(rb_max_level);
250
250
  }
251
251
 
252
252
  if (NIL_P(rb_time) || CBOOL2RVAL(rb_time)) {
253
- flags |= GRN_LOG_TIME;
253
+ flags |= GRN_LOG_TIME;
254
254
  }
255
255
  if (NIL_P(rb_title) || CBOOL2RVAL(rb_title)) {
256
- flags |= GRN_LOG_TITLE;
256
+ flags |= GRN_LOG_TITLE;
257
257
  }
258
258
  if (NIL_P(rb_message) || CBOOL2RVAL(rb_message)) {
259
- flags |= GRN_LOG_MESSAGE;
259
+ flags |= GRN_LOG_MESSAGE;
260
260
  }
261
261
  if (NIL_P(rb_location) || CBOOL2RVAL(rb_location)) {
262
- flags |= GRN_LOG_LOCATION;
262
+ flags |= GRN_LOG_LOCATION;
263
263
  }
264
264
  if (!NIL_P(rb_flags)) {
265
265
  flags = rb_funcall(mGrnLoggerFlags, id_parse, 2,
@@ -355,7 +355,7 @@ rb_grn_logger_s_get_path (VALUE klass)
355
355
 
356
356
  path = grn_default_logger_get_path();
357
357
  if (path) {
358
- rb_path = rb_str_new2(path);
358
+ rb_path = rb_str_new2(path);
359
359
  }
360
360
  return rb_path;
361
361
  }
@@ -401,7 +401,7 @@ rb_grn_logger_s_set_path (VALUE klass, VALUE rb_path)
401
401
  grn_default_logger_set_path(path);
402
402
 
403
403
  if (need_reopen) {
404
- rb_grn_logger_s_reopen_with_related_object(klass, rb_path);
404
+ rb_grn_logger_s_reopen_with_related_object(klass, rb_path);
405
405
  }
406
406
 
407
407
  return Qnil;
@@ -439,7 +439,7 @@ rb_grn_init_logger (VALUE mGrn)
439
439
 
440
440
  mGrnLoggerFlags = rb_define_module_under(cGrnLogger, "Flags");
441
441
  #define DEFINE_FLAG(NAME) \
442
- rb_define_const(mGrnLoggerFlags, \
442
+ rb_define_const(mGrnLoggerFlags, \
443
443
  #NAME, INT2NUM(GRN_LOG_ ## NAME))
444
444
  DEFINE_FLAG(TIME);
445
445
  DEFINE_FLAG(TITLE);
@@ -56,18 +56,18 @@ rb_grn_normalizer_s_normalize (VALUE klass, VALUE rb_string)
56
56
  context = rb_grn_context_ensure(&rb_context);
57
57
  rb_encoded_string = rb_grn_context_rb_string_encode(context, rb_string);
58
58
  grn_string = grn_string_open(context,
59
- RSTRING_PTR(rb_encoded_string),
60
- RSTRING_LEN(rb_encoded_string),
61
- normalizer,
62
- flags);
59
+ RSTRING_PTR(rb_encoded_string),
60
+ RSTRING_LEN(rb_encoded_string),
61
+ normalizer,
62
+ flags);
63
63
  rb_grn_context_check(context, rb_string);
64
64
  grn_string_get_normalized(context, grn_string,
65
- &normalized_string, &normalized_string_length,
66
- NULL);
65
+ &normalized_string, &normalized_string_length,
66
+ NULL);
67
67
  rb_normalized_string =
68
- rb_grn_context_rb_string_new(context,
69
- normalized_string,
70
- normalized_string_length);
68
+ rb_grn_context_rb_string_new(context,
69
+ normalized_string,
70
+ normalized_string_length);
71
71
  grn_obj_close(context, grn_string);
72
72
 
73
73
  return rb_normalized_string;
@@ -79,5 +79,5 @@ rb_grn_init_normalizer (VALUE mGrn)
79
79
  rb_cGrnNormalizer = rb_define_class_under(mGrn, "Normalizer", rb_cObject);
80
80
 
81
81
  rb_define_singleton_method(rb_cGrnNormalizer, "normalize",
82
- rb_grn_normalizer_s_normalize, 1);
82
+ rb_grn_normalizer_s_normalize, 1);
83
83
  }
@@ -174,65 +174,65 @@ rb_grn_patricia_trie_s_create (int argc, VALUE *argv, VALUE klass)
174
174
  rb_scan_args(argc, argv, "01", &options);
175
175
 
176
176
  rb_grn_scan_options(options,
177
- "context", &rb_context,
178
- "name", &rb_name,
177
+ "context", &rb_context,
178
+ "name", &rb_name,
179
179
  "path", &rb_path,
180
- "persistent", &rb_persistent,
181
- "key_normalize", &rb_key_normalize,
182
- "key_with_sis", &rb_key_with_sis,
183
- "key_type", &rb_key_type,
184
- "value_type", &rb_value_type,
185
- "default_tokenizer", &rb_default_tokenizer,
186
- "sub_records", &rb_sub_records,
187
- "normalizer", &rb_normalizer,
188
- NULL);
180
+ "persistent", &rb_persistent,
181
+ "key_normalize", &rb_key_normalize,
182
+ "key_with_sis", &rb_key_with_sis,
183
+ "key_type", &rb_key_type,
184
+ "value_type", &rb_value_type,
185
+ "default_tokenizer", &rb_default_tokenizer,
186
+ "sub_records", &rb_sub_records,
187
+ "normalizer", &rb_normalizer,
188
+ NULL);
189
189
 
190
190
  context = rb_grn_context_ensure(&rb_context);
191
191
 
192
192
  if (!NIL_P(rb_name)) {
193
193
  name = StringValuePtr(rb_name);
194
- name_size = RSTRING_LEN(rb_name);
195
- flags |= GRN_OBJ_PERSISTENT;
194
+ name_size = RSTRING_LEN(rb_name);
195
+ flags |= GRN_OBJ_PERSISTENT;
196
196
  }
197
197
 
198
198
  if (!NIL_P(rb_path)) {
199
199
  path = StringValueCStr(rb_path);
200
- flags |= GRN_OBJ_PERSISTENT;
200
+ flags |= GRN_OBJ_PERSISTENT;
201
201
  }
202
202
 
203
203
  if (RVAL2CBOOL(rb_persistent))
204
- flags |= GRN_OBJ_PERSISTENT;
204
+ flags |= GRN_OBJ_PERSISTENT;
205
205
 
206
206
  if (RVAL2CBOOL(rb_key_normalize))
207
- flags |= GRN_OBJ_KEY_NORMALIZE;
207
+ flags |= GRN_OBJ_KEY_NORMALIZE;
208
208
 
209
209
  if (RVAL2CBOOL(rb_key_with_sis))
210
- flags |= GRN_OBJ_KEY_WITH_SIS;
210
+ flags |= GRN_OBJ_KEY_WITH_SIS;
211
211
 
212
212
  if (NIL_P(rb_key_type)) {
213
- key_type = grn_ctx_at(context, GRN_DB_SHORT_TEXT);
213
+ key_type = grn_ctx_at(context, GRN_DB_SHORT_TEXT);
214
214
  } else {
215
- key_type = RVAL2GRNOBJECT(rb_key_type, &context);
215
+ key_type = RVAL2GRNOBJECT(rb_key_type, &context);
216
216
  }
217
217
 
218
218
  if (!NIL_P(rb_value_type))
219
- value_type = RVAL2GRNOBJECT(rb_value_type, &context);
219
+ value_type = RVAL2GRNOBJECT(rb_value_type, &context);
220
220
 
221
221
  if (RVAL2CBOOL(rb_sub_records))
222
- flags |= GRN_OBJ_WITH_SUBREC;
222
+ flags |= GRN_OBJ_WITH_SUBREC;
223
223
 
224
224
  table = grn_table_create(context, name, name_size, path,
225
- flags, key_type, value_type);
225
+ flags, key_type, value_type);
226
226
  if (!table)
227
- rb_grn_context_check(context, rb_ary_new4(argc, argv));
227
+ rb_grn_context_check(context, rb_ary_new4(argc, argv));
228
228
  rb_table = GRNOBJECT2RVAL(klass, context, table, GRN_TRUE);
229
229
 
230
230
  if (!NIL_P(rb_default_tokenizer))
231
- rb_funcall(rb_table, rb_intern("default_tokenizer="), 1,
232
- rb_default_tokenizer);
231
+ rb_funcall(rb_table, rb_intern("default_tokenizer="), 1,
232
+ rb_default_tokenizer);
233
233
  if (!NIL_P(rb_normalizer))
234
- rb_funcall(rb_table, rb_intern("normalizer="), 1,
235
- rb_normalizer);
234
+ rb_funcall(rb_table, rb_intern("normalizer="), 1,
235
+ rb_normalizer);
236
236
 
237
237
  if (rb_block_given_p())
238
238
  return rb_ensure(rb_yield, rb_table, rb_grn_object_close, rb_table);
@@ -296,35 +296,35 @@ rb_grn_patricia_trie_search (int argc, VALUE *argv, VALUE self)
296
296
  VALUE rb_key, options, rb_result, rb_operator, rb_type;
297
297
 
298
298
  rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
299
- &key, &domain_id, &domain,
300
- NULL, NULL, NULL,
301
- NULL);
299
+ &key, &domain_id, &domain,
300
+ NULL, NULL, NULL,
301
+ NULL);
302
302
 
303
303
  rb_scan_args(argc, argv, "11", &rb_key, &options);
304
304
 
305
305
  RVAL2GRNKEY(rb_key, context, key, domain_id, domain, self);
306
306
 
307
307
  rb_grn_scan_options(options,
308
- "result", &rb_result,
309
- "operator", &rb_operator,
310
- "type", &rb_type,
311
- NULL);
308
+ "result", &rb_result,
309
+ "operator", &rb_operator,
310
+ "type", &rb_type,
311
+ NULL);
312
312
 
313
313
  if (NIL_P(rb_result)) {
314
- result = grn_table_create(context, NULL, 0, NULL,
315
- GRN_OBJ_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC,
316
- table, 0);
317
- rb_grn_context_check(context, self);
318
- rb_result = GRNOBJECT2RVAL(Qnil, context, result, GRN_TRUE);
314
+ result = grn_table_create(context, NULL, 0, NULL,
315
+ GRN_OBJ_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC,
316
+ table, 0);
317
+ rb_grn_context_check(context, self);
318
+ rb_result = GRNOBJECT2RVAL(Qnil, context, result, GRN_TRUE);
319
319
  } else {
320
- result = RVAL2GRNOBJECT(rb_result, &context);
320
+ result = RVAL2GRNOBJECT(rb_result, &context);
321
321
  }
322
322
 
323
323
  operator = RVAL2GRNOPERATOR(rb_operator);
324
324
 
325
325
  rc = grn_obj_search(context, table, key,
326
- result, operator,
327
- search_options_is_set ? &search_options : NULL);
326
+ result, operator,
327
+ search_options_is_set ? &search_options : NULL);
328
328
  rb_grn_rc_check(rc, self);
329
329
 
330
330
  return rb_result;
@@ -384,47 +384,47 @@ rb_grn_patricia_trie_scan (VALUE self, VALUE rb_string)
384
384
  string_length = RSTRING_LEN(rb_string);
385
385
 
386
386
  rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
387
- NULL, NULL, NULL,
388
- NULL, NULL, NULL,
389
- NULL);
387
+ NULL, NULL, NULL,
388
+ NULL, NULL, NULL,
389
+ NULL);
390
390
 
391
391
  block_given = rb_block_given_p();
392
392
  if (!block_given)
393
- rb_result = rb_ary_new();
393
+ rb_result = rb_ary_new();
394
394
 
395
395
  while (string_length > 0) {
396
- const char *rest;
397
- int i, n_hits;
398
- unsigned int previous_offset = 0;
399
-
400
- n_hits = grn_pat_scan(context, (grn_pat *)table,
401
- string, string_length,
402
- hits, sizeof(hits) / sizeof(*hits),
403
- &rest);
404
- for (i = 0; i < n_hits; i++) {
405
- VALUE record, term, matched_info;
406
-
407
- if (hits[i].offset < previous_offset)
408
- continue;
409
-
410
- record = rb_grn_record_new(self, hits[i].id, Qnil);
411
- term = rb_grn_context_rb_string_new(context,
412
- string + hits[i].offset,
413
- hits[i].length);
414
- matched_info = rb_ary_new3(4,
415
- record,
416
- term,
417
- UINT2NUM(hits[i].offset),
418
- UINT2NUM(hits[i].length));
419
- if (block_given) {
420
- rb_yield(matched_info);
421
- } else {
422
- rb_ary_push(rb_result, matched_info);
423
- }
424
- previous_offset = hits[i].offset;
425
- }
426
- string_length -= rest - string;
427
- string = rest;
396
+ const char *rest;
397
+ int i, n_hits;
398
+ unsigned int previous_offset = 0;
399
+
400
+ n_hits = grn_pat_scan(context, (grn_pat *)table,
401
+ string, string_length,
402
+ hits, sizeof(hits) / sizeof(*hits),
403
+ &rest);
404
+ for (i = 0; i < n_hits; i++) {
405
+ VALUE record, term, matched_info;
406
+
407
+ if (hits[i].offset < previous_offset)
408
+ continue;
409
+
410
+ record = rb_grn_record_new(self, hits[i].id, Qnil);
411
+ term = rb_grn_context_rb_string_new(context,
412
+ string + hits[i].offset,
413
+ hits[i].length);
414
+ matched_info = rb_ary_new3(4,
415
+ record,
416
+ term,
417
+ UINT2NUM(hits[i].offset),
418
+ UINT2NUM(hits[i].length));
419
+ if (block_given) {
420
+ rb_yield(matched_info);
421
+ } else {
422
+ rb_ary_push(rb_result, matched_info);
423
+ }
424
+ previous_offset = hits[i].offset;
425
+ }
426
+ string_length -= rest - string;
427
+ string = rest;
428
428
  }
429
429
 
430
430
  return rb_result;
@@ -447,21 +447,21 @@ rb_grn_patricia_trie_prefix_search (VALUE self, VALUE rb_prefix)
447
447
  VALUE rb_result;
448
448
 
449
449
  rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
450
- &key, &domain_id, &domain,
451
- NULL, NULL, NULL,
452
- NULL);
450
+ &key, &domain_id, &domain,
451
+ NULL, NULL, NULL,
452
+ NULL);
453
453
 
454
454
  result = grn_table_create(context, NULL, 0, NULL,
455
- GRN_OBJ_TABLE_HASH_KEY,
456
- table, 0);
455
+ GRN_OBJ_TABLE_HASH_KEY,
456
+ table, 0);
457
457
  rb_grn_context_check(context, self);
458
458
  rb_result = GRNOBJECT2RVAL(Qnil, context, result, GRN_TRUE);
459
459
 
460
460
  GRN_BULK_REWIND(key);
461
461
  RVAL2GRNKEY(rb_prefix, context, key, domain_id, domain, self);
462
462
  grn_pat_prefix_search(context, (grn_pat *)table,
463
- GRN_BULK_HEAD(key), GRN_BULK_VSIZE(key),
464
- (grn_hash *)result);
463
+ GRN_BULK_HEAD(key), GRN_BULK_VSIZE(key),
464
+ (grn_hash *)result);
465
465
  rb_grn_context_check(context, self);
466
466
 
467
467
  return rb_result;
@@ -479,15 +479,15 @@ rb_grn_patricia_trie_register_key_with_sis_p (VALUE self)
479
479
  grn_obj *table;
480
480
 
481
481
  rb_grn_table_key_support_deconstruct(SELF(self), &table, NULL,
482
- NULL, NULL, NULL,
483
- NULL, NULL, NULL,
484
- NULL);
482
+ NULL, NULL, NULL,
483
+ NULL, NULL, NULL,
484
+ NULL);
485
485
  return CBOOL2RVAL(table->header.flags & GRN_OBJ_KEY_WITH_SIS);
486
486
  }
487
487
 
488
488
  static grn_table_cursor *
489
489
  rb_grn_patricia_trie_open_grn_prefix_cursor (int argc, VALUE *argv, VALUE self,
490
- grn_ctx **context)
490
+ grn_ctx **context)
491
491
  {
492
492
  grn_obj *table;
493
493
  grn_table_cursor *cursor;
@@ -500,81 +500,81 @@ rb_grn_patricia_trie_open_grn_prefix_cursor (int argc, VALUE *argv, VALUE self,
500
500
  VALUE rb_greater_than, rb_less_than, rb_offset, rb_limit;
501
501
 
502
502
  rb_grn_table_deconstruct((RbGrnTable *)SELF(self), &table, context,
503
- NULL, NULL,
504
- NULL, NULL, NULL,
505
- NULL);
503
+ NULL, NULL,
504
+ NULL, NULL, NULL,
505
+ NULL);
506
506
 
507
507
  rb_scan_args(argc, argv, "11", &rb_prefix, &options);
508
508
 
509
509
  rb_grn_scan_options(options,
510
- "key_bytes", &rb_key_bytes,
510
+ "key_bytes", &rb_key_bytes,
511
511
  "key_bites", &rb_key_bits,
512
512
  "offset", &rb_offset,
513
513
  "limit", &rb_limit,
514
- "order", &rb_order,
515
- "order_by", &rb_order_by,
516
- "greater_than", &rb_greater_than,
517
- "less_than", &rb_less_than,
518
- NULL);
514
+ "order", &rb_order,
515
+ "order_by", &rb_order_by,
516
+ "greater_than", &rb_greater_than,
517
+ "less_than", &rb_less_than,
518
+ NULL);
519
519
 
520
520
  prefix = StringValuePtr(rb_prefix);
521
521
  if (!NIL_P(rb_key_bytes) && !NIL_P(rb_key_bits)) {
522
- rb_raise(rb_eArgError,
523
- "should not specify both :key_bytes and :key_bits once: %s",
524
- rb_grn_inspect(rb_ary_new4(argc, argv)));
522
+ rb_raise(rb_eArgError,
523
+ "should not specify both :key_bytes and :key_bits once: %s",
524
+ rb_grn_inspect(rb_ary_new4(argc, argv)));
525
525
  } else if (!NIL_P(rb_key_bytes)) {
526
- prefix_size = NUM2UINT(rb_key_bytes);
526
+ prefix_size = NUM2UINT(rb_key_bytes);
527
527
  } else if (!NIL_P(rb_key_bits)) {
528
- prefix_size = NUM2UINT(rb_key_bits);
529
- flags |= GRN_CURSOR_SIZE_BY_BIT;
528
+ prefix_size = NUM2UINT(rb_key_bits);
529
+ flags |= GRN_CURSOR_SIZE_BY_BIT;
530
530
  } else {
531
- prefix_size = RSTRING_LEN(rb_prefix);
531
+ prefix_size = RSTRING_LEN(rb_prefix);
532
532
  }
533
533
  if (!NIL_P(rb_offset))
534
- offset = NUM2INT(rb_offset);
534
+ offset = NUM2INT(rb_offset);
535
535
  if (!NIL_P(rb_limit))
536
- limit = NUM2INT(rb_limit);
536
+ limit = NUM2INT(rb_limit);
537
537
 
538
538
  if (NIL_P(rb_order)) {
539
539
  } else if (rb_grn_equal_option(rb_order, "asc") ||
540
- rb_grn_equal_option(rb_order, "ascending")) {
541
- flags |= GRN_CURSOR_ASCENDING;
540
+ rb_grn_equal_option(rb_order, "ascending")) {
541
+ flags |= GRN_CURSOR_ASCENDING;
542
542
  } else if (rb_grn_equal_option(rb_order, "desc") ||
543
- rb_grn_equal_option(rb_order, "descending")) {
544
- flags |= GRN_CURSOR_DESCENDING;
543
+ rb_grn_equal_option(rb_order, "descending")) {
544
+ flags |= GRN_CURSOR_DESCENDING;
545
545
  } else {
546
- rb_raise(rb_eArgError,
547
- "order should be one of "
548
- "[:asc, :ascending, :desc, :descending]: %s",
549
- rb_grn_inspect(rb_order));
546
+ rb_raise(rb_eArgError,
547
+ "order should be one of "
548
+ "[:asc, :ascending, :desc, :descending]: %s",
549
+ rb_grn_inspect(rb_order));
550
550
  }
551
551
  if (NIL_P(rb_order_by)) {
552
552
  } else if (rb_grn_equal_option(rb_order_by, "id")) {
553
- flags |= GRN_CURSOR_BY_ID;
553
+ flags |= GRN_CURSOR_BY_ID;
554
554
  } else if (rb_grn_equal_option(rb_order_by, "key")) {
555
- if (table->header.type != GRN_TABLE_PAT_KEY) {
556
- rb_raise(rb_eArgError,
557
- "order_by => :key is available "
558
- "only for Groonga::PatriciaTrie: %s",
559
- rb_grn_inspect(self));
560
- }
561
- flags |= GRN_CURSOR_BY_KEY;
555
+ if (table->header.type != GRN_TABLE_PAT_KEY) {
556
+ rb_raise(rb_eArgError,
557
+ "order_by => :key is available "
558
+ "only for Groonga::PatriciaTrie: %s",
559
+ rb_grn_inspect(self));
560
+ }
561
+ flags |= GRN_CURSOR_BY_KEY;
562
562
  } else {
563
- rb_raise(rb_eArgError,
564
- "order_by should be one of [:id%s]: %s",
565
- table->header.type == GRN_TABLE_PAT_KEY ? ", :key" : "",
566
- rb_grn_inspect(rb_order_by));
563
+ rb_raise(rb_eArgError,
564
+ "order_by should be one of [:id%s]: %s",
565
+ table->header.type == GRN_TABLE_PAT_KEY ? ", :key" : "",
566
+ rb_grn_inspect(rb_order_by));
567
567
  }
568
568
 
569
569
  if (RVAL2CBOOL(rb_greater_than))
570
- flags |= GRN_CURSOR_GT;
570
+ flags |= GRN_CURSOR_GT;
571
571
  if (RVAL2CBOOL(rb_less_than))
572
- flags |= GRN_CURSOR_LT;
572
+ flags |= GRN_CURSOR_LT;
573
573
 
574
574
  cursor = grn_table_cursor_open(*context, table,
575
- prefix, prefix_size,
576
- NULL, 0,
577
- offset, limit, flags);
575
+ prefix, prefix_size,
576
+ NULL, 0,
577
+ offset, limit, flags);
578
578
  rb_grn_context_check(*context, self);
579
579
 
580
580
  return cursor;
@@ -629,18 +629,18 @@ rb_grn_patricia_trie_open_prefix_cursor (int argc, VALUE *argv, VALUE self)
629
629
  VALUE rb_cursor;
630
630
 
631
631
  cursor = rb_grn_patricia_trie_open_grn_prefix_cursor(argc, argv,
632
- self, &context);
632
+ self, &context);
633
633
  rb_cursor = GRNTABLECURSOR2RVAL(Qnil, context, cursor);
634
634
  rb_iv_set(rb_cursor, "@table", self); /* FIXME: cursor should mark table */
635
635
  if (rb_block_given_p())
636
- return rb_ensure(rb_yield, rb_cursor, rb_grn_object_close, rb_cursor);
636
+ return rb_ensure(rb_yield, rb_cursor, rb_grn_object_close, rb_cursor);
637
637
  else
638
- return rb_cursor;
638
+ return rb_cursor;
639
639
  }
640
640
 
641
641
  static grn_table_cursor *
642
642
  rb_grn_patricia_trie_open_grn_rk_cursor (int argc, VALUE *argv, VALUE self,
643
- grn_ctx **context)
643
+ grn_ctx **context)
644
644
  {
645
645
  grn_obj *table;
646
646
  grn_table_cursor *cursor;
@@ -652,48 +652,48 @@ rb_grn_patricia_trie_open_grn_rk_cursor (int argc, VALUE *argv, VALUE self,
652
652
  VALUE rb_greater_than, rb_less_than, rb_offset, rb_limit;
653
653
 
654
654
  rb_grn_table_deconstruct((RbGrnTable *)SELF(self), &table, context,
655
- NULL, NULL,
656
- NULL, NULL, NULL,
657
- NULL);
655
+ NULL, NULL,
656
+ NULL, NULL, NULL,
657
+ NULL);
658
658
 
659
659
  rb_scan_args(argc, argv, "11", &rb_prefix, &options);
660
660
 
661
661
  rb_grn_scan_options(options,
662
- "key_bytes", &rb_key_bytes,
662
+ "key_bytes", &rb_key_bytes,
663
663
  "key_bites", &rb_key_bits,
664
664
  "offset", &rb_offset,
665
665
  "limit", &rb_limit,
666
- "greater_than", &rb_greater_than,
667
- "less_than", &rb_less_than,
668
- NULL);
666
+ "greater_than", &rb_greater_than,
667
+ "less_than", &rb_less_than,
668
+ NULL);
669
669
 
670
670
  prefix = StringValuePtr(rb_prefix);
671
671
  if (!NIL_P(rb_key_bytes) && !NIL_P(rb_key_bits)) {
672
- rb_raise(rb_eArgError,
673
- "should not specify both :key_bytes and :key_bits once: %s",
674
- rb_grn_inspect(rb_ary_new4(argc, argv)));
672
+ rb_raise(rb_eArgError,
673
+ "should not specify both :key_bytes and :key_bits once: %s",
674
+ rb_grn_inspect(rb_ary_new4(argc, argv)));
675
675
  } else if (!NIL_P(rb_key_bytes)) {
676
- prefix_size = NUM2UINT(rb_key_bytes);
676
+ prefix_size = NUM2UINT(rb_key_bytes);
677
677
  } else if (!NIL_P(rb_key_bits)) {
678
- prefix_size = NUM2UINT(rb_key_bits);
679
- flags |= GRN_CURSOR_SIZE_BY_BIT;
678
+ prefix_size = NUM2UINT(rb_key_bits);
679
+ flags |= GRN_CURSOR_SIZE_BY_BIT;
680
680
  } else {
681
- prefix_size = RSTRING_LEN(rb_prefix);
681
+ prefix_size = RSTRING_LEN(rb_prefix);
682
682
  }
683
683
  if (!NIL_P(rb_offset))
684
- offset = NUM2INT(rb_offset);
684
+ offset = NUM2INT(rb_offset);
685
685
  if (!NIL_P(rb_limit))
686
- limit = NUM2INT(rb_limit);
686
+ limit = NUM2INT(rb_limit);
687
687
 
688
688
  if (RVAL2CBOOL(rb_greater_than))
689
- flags |= GRN_CURSOR_GT;
689
+ flags |= GRN_CURSOR_GT;
690
690
  if (RVAL2CBOOL(rb_less_than))
691
- flags |= GRN_CURSOR_LT;
691
+ flags |= GRN_CURSOR_LT;
692
692
 
693
693
  cursor = grn_table_cursor_open(*context, table,
694
- prefix, prefix_size,
695
- NULL, 0,
696
- offset, limit, flags);
694
+ prefix, prefix_size,
695
+ NULL, 0,
696
+ offset, limit, flags);
697
697
  rb_grn_context_check(*context, self);
698
698
 
699
699
  return cursor;
@@ -741,19 +741,19 @@ rb_grn_patricia_trie_open_rk_cursor (int argc, VALUE *argv, VALUE self)
741
741
  VALUE rb_cursor;
742
742
 
743
743
  cursor = rb_grn_patricia_trie_open_grn_rk_cursor(argc, argv,
744
- self, &context);
744
+ self, &context);
745
745
  rb_cursor = GRNTABLECURSOR2RVAL(Qnil, context, cursor);
746
746
  rb_iv_set(rb_cursor, "@table", self); /* FIXME: cursor should mark table */
747
747
  if (rb_block_given_p())
748
- return rb_ensure(rb_yield, rb_cursor, rb_grn_object_close, rb_cursor);
748
+ return rb_ensure(rb_yield, rb_cursor, rb_grn_object_close, rb_cursor);
749
749
  else
750
- return rb_cursor;
750
+ return rb_cursor;
751
751
  }
752
752
 
753
753
 
754
754
  static grn_table_cursor *
755
755
  rb_grn_patricia_trie_open_grn_near_cursor (int argc, VALUE *argv, VALUE self,
756
- grn_ctx **context, int flags)
756
+ grn_ctx **context, int flags)
757
757
  {
758
758
  grn_obj *table;
759
759
  grn_obj *key_p = NULL, casted_key;
@@ -766,46 +766,46 @@ rb_grn_patricia_trie_open_grn_near_cursor (int argc, VALUE *argv, VALUE self,
766
766
  flags |= GRN_CURSOR_PREFIX;
767
767
 
768
768
  rb_grn_table_deconstruct((RbGrnTable *)SELF(self), &table, context,
769
- NULL, NULL,
770
- NULL, NULL, NULL,
771
- NULL);
769
+ NULL, NULL,
770
+ NULL, NULL, NULL,
771
+ NULL);
772
772
 
773
773
  rb_scan_args(argc, argv, "11", &rb_key, &options);
774
774
 
775
775
  rb_grn_scan_options(options,
776
- "size", &rb_min_size,
776
+ "size", &rb_min_size,
777
777
  "offset", &rb_offset,
778
778
  "limit", &rb_limit,
779
- "greater_than", &rb_greater_than,
780
- "less_than", &rb_less_than,
781
- NULL);
779
+ "greater_than", &rb_greater_than,
780
+ "less_than", &rb_less_than,
781
+ NULL);
782
782
 
783
783
  key_p = RVAL2GRNBULK_WITH_TYPE(rb_key, *context, key_p,
784
- table->header.domain,
785
- grn_ctx_at(*context, table->header.domain));
784
+ table->header.domain,
785
+ grn_ctx_at(*context, table->header.domain));
786
786
  GRN_OBJ_INIT(&casted_key, GRN_BULK, 0, table->header.domain);
787
787
  if (key_p->header.domain != table->header.domain) {
788
- grn_obj_cast(*context, key_p, &casted_key, GRN_FALSE);
789
- grn_obj_unlink(*context, key_p);
790
- key_p = &casted_key;
788
+ grn_obj_cast(*context, key_p, &casted_key, GRN_FALSE);
789
+ grn_obj_unlink(*context, key_p);
790
+ key_p = &casted_key;
791
791
  }
792
792
 
793
793
  if (!NIL_P(rb_min_size))
794
- min_size = NUM2UINT(rb_min_size);
794
+ min_size = NUM2UINT(rb_min_size);
795
795
  if (!NIL_P(rb_offset))
796
- offset = NUM2INT(rb_offset);
796
+ offset = NUM2INT(rb_offset);
797
797
  if (!NIL_P(rb_limit))
798
- limit = NUM2INT(rb_limit);
798
+ limit = NUM2INT(rb_limit);
799
799
 
800
800
  if (RVAL2CBOOL(rb_greater_than))
801
- flags |= GRN_CURSOR_GT;
801
+ flags |= GRN_CURSOR_GT;
802
802
  if (RVAL2CBOOL(rb_less_than))
803
- flags |= GRN_CURSOR_LT;
803
+ flags |= GRN_CURSOR_LT;
804
804
 
805
805
  cursor = grn_table_cursor_open(*context, table,
806
- NULL, min_size,
807
- GRN_BULK_HEAD(key_p), GRN_BULK_VSIZE(key_p),
808
- offset, limit, flags);
806
+ NULL, min_size,
807
+ GRN_BULK_HEAD(key_p), GRN_BULK_VSIZE(key_p),
808
+ offset, limit, flags);
809
809
  GRN_OBJ_FIN(*context, &casted_key);
810
810
  rb_grn_context_check(*context, self);
811
811
 
@@ -850,42 +850,42 @@ rb_grn_patricia_trie_open_near_cursor (int argc, VALUE *argv, VALUE self)
850
850
  VALUE rb_cursor;
851
851
 
852
852
  cursor = rb_grn_patricia_trie_open_grn_near_cursor(argc, argv,
853
- self, &context, GRN_CURSOR_RK);
853
+ self, &context, GRN_CURSOR_RK);
854
854
  rb_cursor = GRNTABLECURSOR2RVAL(Qnil, context, cursor);
855
855
  rb_iv_set(rb_cursor, "@table", self); /* FIXME: cursor should mark table */
856
856
  if (rb_block_given_p())
857
- return rb_ensure(rb_yield, rb_cursor, rb_grn_object_close, rb_cursor);
857
+ return rb_ensure(rb_yield, rb_cursor, rb_grn_object_close, rb_cursor);
858
858
  else
859
- return rb_cursor;
859
+ return rb_cursor;
860
860
  }
861
861
 
862
862
  void
863
863
  rb_grn_init_patricia_trie (VALUE mGrn)
864
864
  {
865
865
  rb_cGrnPatriciaTrie =
866
- rb_define_class_under(mGrn, "PatriciaTrie", rb_cGrnTable);
866
+ rb_define_class_under(mGrn, "PatriciaTrie", rb_cGrnTable);
867
867
 
868
868
  rb_include_module(rb_cGrnPatriciaTrie, rb_mGrnTableKeySupport);
869
869
  rb_define_singleton_method(rb_cGrnPatriciaTrie, "create",
870
- rb_grn_patricia_trie_s_create, -1);
870
+ rb_grn_patricia_trie_s_create, -1);
871
871
 
872
872
  rb_define_method(rb_cGrnPatriciaTrie, "search",
873
- rb_grn_patricia_trie_search, -1);
873
+ rb_grn_patricia_trie_search, -1);
874
874
  rb_define_method(rb_cGrnPatriciaTrie, "scan",
875
- rb_grn_patricia_trie_scan, 1);
875
+ rb_grn_patricia_trie_scan, 1);
876
876
  rb_define_method(rb_cGrnPatriciaTrie, "prefix_search",
877
- rb_grn_patricia_trie_prefix_search, 1);
877
+ rb_grn_patricia_trie_prefix_search, 1);
878
878
 
879
879
  rb_define_method(rb_cGrnPatriciaTrie, "register_key_with_sis?",
880
- rb_grn_patricia_trie_register_key_with_sis_p, 0);
880
+ rb_grn_patricia_trie_register_key_with_sis_p, 0);
881
881
 
882
882
  rb_define_method(rb_cGrnPatriciaTrie, "open_prefix_cursor",
883
- rb_grn_patricia_trie_open_prefix_cursor,
884
- -1);
883
+ rb_grn_patricia_trie_open_prefix_cursor,
884
+ -1);
885
885
  rb_define_method(rb_cGrnPatriciaTrie, "open_rk_cursor",
886
- rb_grn_patricia_trie_open_rk_cursor,
887
- -1);
886
+ rb_grn_patricia_trie_open_rk_cursor,
887
+ -1);
888
888
  rb_define_method(rb_cGrnPatriciaTrie, "open_near_cursor",
889
- rb_grn_patricia_trie_open_near_cursor,
890
- -1);
889
+ rb_grn_patricia_trie_open_near_cursor,
890
+ -1);
891
891
  }