isomorfeus-ferret 0.17.1 → 0.17.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/ext/isomorfeus_ferret_ext/benchmark.c +9 -20
  3. data/ext/isomorfeus_ferret_ext/benchmarks_all.h +1 -2
  4. data/ext/isomorfeus_ferret_ext/bm_hash.c +1 -2
  5. data/ext/isomorfeus_ferret_ext/bm_store.c +2 -0
  6. data/ext/isomorfeus_ferret_ext/brotli_dec_decode.c +4 -2
  7. data/ext/isomorfeus_ferret_ext/brotli_enc_encode.c +3 -2
  8. data/ext/isomorfeus_ferret_ext/frb_analysis.c +4 -5
  9. data/ext/isomorfeus_ferret_ext/frb_field_info.c +3 -4
  10. data/ext/isomorfeus_ferret_ext/frb_index.c +118 -160
  11. data/ext/isomorfeus_ferret_ext/frb_lazy_doc.c +14 -16
  12. data/ext/isomorfeus_ferret_ext/frb_search.c +31 -23
  13. data/ext/isomorfeus_ferret_ext/frb_store.c +27 -13
  14. data/ext/isomorfeus_ferret_ext/frb_utils.c +3 -6
  15. data/ext/isomorfeus_ferret_ext/frt_analysis.c +39 -46
  16. data/ext/isomorfeus_ferret_ext/frt_analysis.h +9 -9
  17. data/ext/isomorfeus_ferret_ext/frt_array.c +11 -22
  18. data/ext/isomorfeus_ferret_ext/frt_bitvector.h +3 -6
  19. data/ext/isomorfeus_ferret_ext/frt_doc_field.c +87 -0
  20. data/ext/isomorfeus_ferret_ext/frt_doc_field.h +26 -0
  21. data/ext/isomorfeus_ferret_ext/frt_document.c +4 -97
  22. data/ext/isomorfeus_ferret_ext/frt_document.h +2 -27
  23. data/ext/isomorfeus_ferret_ext/frt_except.c +50 -6
  24. data/ext/isomorfeus_ferret_ext/frt_except.h +3 -2
  25. data/ext/isomorfeus_ferret_ext/frt_field_index.c +13 -32
  26. data/ext/isomorfeus_ferret_ext/frt_field_index.h +0 -6
  27. data/ext/isomorfeus_ferret_ext/frt_field_info.c +69 -0
  28. data/ext/isomorfeus_ferret_ext/frt_field_info.h +49 -0
  29. data/ext/isomorfeus_ferret_ext/frt_field_infos.c +196 -0
  30. data/ext/isomorfeus_ferret_ext/frt_field_infos.h +35 -0
  31. data/ext/isomorfeus_ferret_ext/frt_global.c +10 -4
  32. data/ext/isomorfeus_ferret_ext/frt_global.h +11 -15
  33. data/ext/isomorfeus_ferret_ext/frt_hash.c +8 -8
  34. data/ext/isomorfeus_ferret_ext/frt_hash.h +1 -2
  35. data/ext/isomorfeus_ferret_ext/frt_hashset.c +20 -40
  36. data/ext/isomorfeus_ferret_ext/frt_hashset.h +1 -2
  37. data/ext/isomorfeus_ferret_ext/frt_helper.c +7 -15
  38. data/ext/isomorfeus_ferret_ext/frt_in_stream.c +482 -0
  39. data/ext/isomorfeus_ferret_ext/frt_in_stream.h +241 -0
  40. data/ext/isomorfeus_ferret_ext/frt_ind.c +20 -49
  41. data/ext/isomorfeus_ferret_ext/frt_ind.h +0 -1
  42. data/ext/isomorfeus_ferret_ext/frt_index.c +296 -1857
  43. data/ext/isomorfeus_ferret_ext/frt_index.h +2 -145
  44. data/ext/isomorfeus_ferret_ext/frt_lang.c +5 -10
  45. data/ext/isomorfeus_ferret_ext/frt_lazy_doc.c +29 -0
  46. data/ext/isomorfeus_ferret_ext/frt_lazy_doc.h +19 -0
  47. data/ext/isomorfeus_ferret_ext/frt_lazy_doc_field.c +93 -0
  48. data/ext/isomorfeus_ferret_ext/frt_lazy_doc_field.h +33 -0
  49. data/ext/isomorfeus_ferret_ext/frt_mdbx_store.c +102 -70
  50. data/ext/isomorfeus_ferret_ext/frt_mempool.c +8 -16
  51. data/ext/isomorfeus_ferret_ext/frt_multimapper.c +23 -46
  52. data/ext/isomorfeus_ferret_ext/frt_multimapper.h +4 -8
  53. data/ext/isomorfeus_ferret_ext/frt_out_stream.c +334 -0
  54. data/ext/isomorfeus_ferret_ext/frt_out_stream.h +198 -0
  55. data/ext/isomorfeus_ferret_ext/frt_posh.c +6 -819
  56. data/ext/isomorfeus_ferret_ext/frt_posh.h +0 -57
  57. data/ext/isomorfeus_ferret_ext/frt_priorityqueue.c +11 -22
  58. data/ext/isomorfeus_ferret_ext/frt_priorityqueue.h +1 -2
  59. data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +85 -171
  60. data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +8 -16
  61. data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +1 -2
  62. data/ext/isomorfeus_ferret_ext/frt_q_parser.c +49 -98
  63. data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +52 -104
  64. data/ext/isomorfeus_ferret_ext/frt_q_range.c +6 -12
  65. data/ext/isomorfeus_ferret_ext/frt_q_span.c +113 -226
  66. data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +1 -2
  67. data/ext/isomorfeus_ferret_ext/frt_ram_store.c +134 -85
  68. data/ext/isomorfeus_ferret_ext/frt_ram_store.h +12 -0
  69. data/ext/isomorfeus_ferret_ext/frt_search.c +82 -164
  70. data/ext/isomorfeus_ferret_ext/frt_similarity.c +11 -22
  71. data/ext/isomorfeus_ferret_ext/frt_similarity.h +1 -2
  72. data/ext/isomorfeus_ferret_ext/frt_store.c +13 -536
  73. data/ext/isomorfeus_ferret_ext/frt_store.h +90 -495
  74. data/ext/isomorfeus_ferret_ext/frt_stream.h +18 -0
  75. data/ext/isomorfeus_ferret_ext/frt_term_vectors.c +8 -16
  76. data/ext/isomorfeus_ferret_ext/frt_win32.h +5 -10
  77. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +12 -11
  78. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +11 -13
  79. data/ext/isomorfeus_ferret_ext/lz4.c +422 -195
  80. data/ext/isomorfeus_ferret_ext/lz4.h +114 -46
  81. data/ext/isomorfeus_ferret_ext/lz4frame.c +421 -242
  82. data/ext/isomorfeus_ferret_ext/lz4frame.h +122 -53
  83. data/ext/isomorfeus_ferret_ext/lz4hc.c +127 -111
  84. data/ext/isomorfeus_ferret_ext/lz4hc.h +14 -14
  85. data/ext/isomorfeus_ferret_ext/lz4xxhash.h +1 -1
  86. data/ext/isomorfeus_ferret_ext/mdbx.c +3762 -2526
  87. data/ext/isomorfeus_ferret_ext/mdbx.h +115 -70
  88. data/ext/isomorfeus_ferret_ext/test.c +40 -87
  89. data/ext/isomorfeus_ferret_ext/test.h +3 -6
  90. data/ext/isomorfeus_ferret_ext/test_1710.c +11 -13
  91. data/ext/isomorfeus_ferret_ext/test_analysis.c +32 -64
  92. data/ext/isomorfeus_ferret_ext/test_array.c +6 -12
  93. data/ext/isomorfeus_ferret_ext/test_bitvector.c +12 -24
  94. data/ext/isomorfeus_ferret_ext/test_document.c +23 -33
  95. data/ext/isomorfeus_ferret_ext/test_except.c +10 -21
  96. data/ext/isomorfeus_ferret_ext/test_fields.c +62 -68
  97. data/ext/isomorfeus_ferret_ext/test_file_deleter.c +15 -24
  98. data/ext/isomorfeus_ferret_ext/test_filter.c +17 -27
  99. data/ext/isomorfeus_ferret_ext/test_global.c +14 -29
  100. data/ext/isomorfeus_ferret_ext/test_hash.c +19 -38
  101. data/ext/isomorfeus_ferret_ext/test_hashset.c +8 -16
  102. data/ext/isomorfeus_ferret_ext/test_helper.c +4 -8
  103. data/ext/isomorfeus_ferret_ext/test_highlighter.c +16 -28
  104. data/ext/isomorfeus_ferret_ext/test_index.c +277 -495
  105. data/ext/isomorfeus_ferret_ext/test_lang.c +7 -14
  106. data/ext/isomorfeus_ferret_ext/test_mdbx_store.c +2 -5
  107. data/ext/isomorfeus_ferret_ext/test_mempool.c +5 -10
  108. data/ext/isomorfeus_ferret_ext/test_multimapper.c +3 -6
  109. data/ext/isomorfeus_ferret_ext/test_priorityqueue.c +9 -18
  110. data/ext/isomorfeus_ferret_ext/test_q_const_score.c +4 -6
  111. data/ext/isomorfeus_ferret_ext/test_q_filtered.c +3 -4
  112. data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +9 -15
  113. data/ext/isomorfeus_ferret_ext/test_q_parser.c +8 -16
  114. data/ext/isomorfeus_ferret_ext/test_q_span.c +19 -35
  115. data/ext/isomorfeus_ferret_ext/test_ram_store.c +14 -13
  116. data/ext/isomorfeus_ferret_ext/test_search.c +60 -109
  117. data/ext/isomorfeus_ferret_ext/test_segments.c +8 -13
  118. data/ext/isomorfeus_ferret_ext/test_similarity.c +2 -4
  119. data/ext/isomorfeus_ferret_ext/test_sort.c +14 -24
  120. data/ext/isomorfeus_ferret_ext/test_store.c +96 -115
  121. data/ext/isomorfeus_ferret_ext/test_term.c +9 -15
  122. data/ext/isomorfeus_ferret_ext/test_term_vectors.c +9 -14
  123. data/ext/isomorfeus_ferret_ext/test_test.c +4 -8
  124. data/ext/isomorfeus_ferret_ext/test_threading.c +15 -30
  125. data/ext/isomorfeus_ferret_ext/testhelper.c +11 -21
  126. data/ext/isomorfeus_ferret_ext/testhelper.h +1 -1
  127. data/ext/isomorfeus_ferret_ext/tests_all.h +1 -2
  128. data/lib/isomorfeus/ferret/index/index.rb +1 -12
  129. data/lib/isomorfeus/ferret/version.rb +1 -1
  130. metadata +43 -4
@@ -208,8 +208,7 @@ static VALUE frb_fis_add(VALUE self, VALUE rfi) {
208
208
  * of the available properties.
209
209
  */
210
210
  static VALUE
211
- frb_fis_add_field(int argc, VALUE *argv, VALUE self)
212
- {
211
+ frb_fis_add_field(int argc, VALUE *argv, VALUE self) {
213
212
  FrtFieldInfos *fis = (FrtFieldInfos *)DATA_PTR(self);
214
213
  FrtFieldInfo *fi;
215
214
  unsigned int bits = fis->bits;
@@ -233,8 +232,7 @@ frb_fis_add_field(int argc, VALUE *argv, VALUE self)
233
232
  * Iterate through the FieldInfo objects.
234
233
  */
235
234
  static VALUE
236
- frb_fis_each(VALUE self)
237
- {
235
+ frb_fis_each(VALUE self) {
238
236
  int i;
239
237
  FrtFieldInfos *fis = (FrtFieldInfos *)DATA_PTR(self);
240
238
 
@@ -251,8 +249,7 @@ frb_fis_each(VALUE self)
251
249
  * Return a string representation of the FieldInfos object.
252
250
  */
253
251
  static VALUE
254
- frb_fis_to_s(VALUE self)
255
- {
252
+ frb_fis_to_s(VALUE self) {
256
253
  FrtFieldInfos *fis = (FrtFieldInfos *)DATA_PTR(self);
257
254
  char *fis_s = frt_fis_to_s(fis);
258
255
  VALUE rfis_s = rb_str_new2(fis_s);
@@ -291,6 +288,7 @@ static VALUE frb_fis_create_index(VALUE self, VALUE rdir) {
291
288
  StringValue(rdir);
292
289
  frb_create_dir(rdir);
293
290
  store = frt_open_mdbx_store(rs2s(rdir));
291
+ store->create_folder(store, segm_idx_name);
294
292
  frt_index_create(store, fis);
295
293
  frt_store_close(store);
296
294
  }
@@ -306,8 +304,7 @@ static VALUE frb_fis_create_index(VALUE self, VALUE rdir) {
306
304
  * index.
307
305
  */
308
306
  static VALUE
309
- frb_fis_get_fields(VALUE self)
310
- {
307
+ frb_fis_get_fields(VALUE self) {
311
308
  FrtFieldInfos *fis = (FrtFieldInfos *)DATA_PTR(self);
312
309
  VALUE rfield_names = rb_ary_new();
313
310
  int i;
@@ -325,8 +322,7 @@ frb_fis_get_fields(VALUE self)
325
322
  * in the index.
326
323
  */
327
324
  static VALUE
328
- frb_fis_get_tk_fields(VALUE self)
329
- {
325
+ frb_fis_get_tk_fields(VALUE self) {
330
326
  FrtFieldInfos *fis = (FrtFieldInfos *)DATA_PTR(self);
331
327
  VALUE rfield_names = rb_ary_new();
332
328
  int i;
@@ -777,16 +773,13 @@ static VALUE frb_tde_to_json(int argc, VALUE *argv, VALUE self) {
777
773
  if (do_positions) {
778
774
  if (argc == 0) {
779
775
  format = "{\"document\":%d,\"frequency\":%d,\"positions\":[";
780
- }
781
- else {
776
+ } else {
782
777
  format = "[%d,%d,[";
783
778
  }
784
- }
785
- else {
779
+ } else {
786
780
  if (argc == 0) {
787
781
  format = "{\"document\":%d,\"frequency\":%d},";
788
- }
789
- else {
782
+ } else {
790
783
  format = "[%d,%d],";
791
784
  }
792
785
  }
@@ -1039,6 +1032,7 @@ static VALUE frb_iw_init(int argc, VALUE *argv, VALUE self) {
1039
1032
  StringValue(rval);
1040
1033
  frb_create_dir(rval);
1041
1034
  store = frt_open_mdbx_store(rs2s(rval));
1035
+ store->create_folder(store, segm_idx_name);
1042
1036
  }
1043
1037
 
1044
1038
  if ((rval = rb_hash_aref(roptions, sym_analyzer)) != Qnil) {
@@ -1060,8 +1054,9 @@ static VALUE frb_iw_init(int argc, VALUE *argv, VALUE self) {
1060
1054
  }
1061
1055
  if (NULL == store) {
1062
1056
  store = frt_open_ram_store(NULL);
1057
+ store->create_folder(store, segm_idx_name);
1063
1058
  }
1064
- if (!create && create_if_missing && !store->exists(store, "segments")) {
1059
+ if (!create && create_if_missing && !store->exists(store, segm_idx_name, "segments")) {
1065
1060
  create = true;
1066
1061
  }
1067
1062
  if (create) {
@@ -1130,8 +1125,7 @@ frb_iw_get_doc_count(VALUE self) {
1130
1125
  }
1131
1126
 
1132
1127
  static int
1133
- frb_hash_to_doc_i(VALUE key, VALUE value, VALUE arg)
1134
- {
1128
+ frb_hash_to_doc_i(VALUE key, VALUE value, VALUE arg) {
1135
1129
  if (key == Qundef) {
1136
1130
  return ST_CONTINUE;
1137
1131
  } else {
@@ -1151,20 +1145,18 @@ frb_hash_to_doc_i(VALUE key, VALUE value, VALUE arg)
1151
1145
  case T_ARRAY:
1152
1146
  {
1153
1147
  int i;
1154
- df->destroy_data = true;
1155
1148
  for (i = 0; i < RARRAY_LEN(value); i++) {
1156
1149
  val = rb_obj_as_string(RARRAY_PTR(value)[i]);
1157
- frt_df_add_data_len(df, rstrdup(val), RSTRING_LEN(val), rb_enc_get(val));
1150
+ frt_df_add_data_len(df, RSTRING_PTR(val), RSTRING_LEN(val), rb_enc_get(val));
1158
1151
  }
1159
1152
  }
1160
1153
  break;
1161
1154
  case T_STRING:
1162
- frt_df_add_data_len(df, rs2s(value), RSTRING_LEN(value), rb_enc_get(value));
1155
+ frt_df_add_data_len(df, RSTRING_PTR(value), RSTRING_LEN(value), rb_enc_get(value));
1163
1156
  break;
1164
1157
  default:
1165
1158
  val = rb_obj_as_string(value);
1166
- df->destroy_data = true;
1167
- frt_df_add_data_len(df, rstrdup(val), RSTRING_LEN(val), rb_enc_get(val));
1159
+ frt_df_add_data_len(df, RSTRING_PTR(val), RSTRING_LEN(val), rb_enc_get(val));
1168
1160
  break;
1169
1161
  }
1170
1162
  FRT_TRY
@@ -1181,8 +1173,7 @@ frb_hash_to_doc_i(VALUE key, VALUE value, VALUE arg)
1181
1173
  }
1182
1174
 
1183
1175
  static FrtDocument *
1184
- frb_get_doc(VALUE rdoc)
1185
- {
1176
+ frb_get_doc(VALUE rdoc) {
1186
1177
  VALUE val;
1187
1178
  FrtDocument *doc = frt_doc_new();
1188
1179
  FrtDocField *df;
@@ -1199,27 +1190,25 @@ frb_get_doc(VALUE rdoc)
1199
1190
  {
1200
1191
  int i;
1201
1192
  df = frt_df_new(fsym_content);
1202
- df->destroy_data = true;
1203
1193
  for (i = 0; i < RARRAY_LEN(rdoc); i++) {
1204
1194
  val = rb_obj_as_string(RARRAY_PTR(rdoc)[i]);
1205
- frt_df_add_data_len(df, rstrdup(val), RSTRING_LEN(val), rb_enc_get(val));
1195
+ frt_df_add_data_len(df, RSTRING_PTR(val), RSTRING_LEN(val), rb_enc_get(val));
1206
1196
  }
1207
1197
  frt_doc_add_field(doc, df);
1208
1198
  }
1209
1199
  break;
1210
1200
  case T_SYMBOL:
1211
1201
  /* TODO: clean up this ugly cast */
1212
- df = frt_df_add_data(frt_df_new(fsym_content), (char *)rb_id2name(SYM2ID(rdoc)), rb_enc_get(rdoc));
1202
+ df = frt_df_add_data(frt_df_new(fsym_content), rb_id2name(SYM2ID(rdoc)), rb_enc_get(rdoc));
1213
1203
  frt_doc_add_field(doc, df);
1214
1204
  break;
1215
1205
  case T_STRING:
1216
- df = frt_df_add_data_len(frt_df_new(fsym_content), rs2s(rdoc), RSTRING_LEN(rdoc), rb_enc_get(rdoc));
1206
+ df = frt_df_add_data_len(frt_df_new(fsym_content), RSTRING_PTR(rdoc), RSTRING_LEN(rdoc), rb_enc_get(rdoc));
1217
1207
  frt_doc_add_field(doc, df);
1218
1208
  break;
1219
1209
  default:
1220
1210
  val = rb_obj_as_string(rdoc);
1221
- df = frt_df_add_data_len(frt_df_new(fsym_content), rstrdup(val), RSTRING_LEN(val), rb_enc_get(val));
1222
- df->destroy_data = true;
1211
+ df = frt_df_add_data_len(frt_df_new(fsym_content), RSTRING_PTR(val), RSTRING_LEN(val), rb_enc_get(val));
1223
1212
  frt_doc_add_field(doc, df);
1224
1213
  break;
1225
1214
  }
@@ -1258,40 +1247,6 @@ frb_iw_add_doc(VALUE self, VALUE rdoc) {
1258
1247
  return self;
1259
1248
  }
1260
1249
 
1261
- /*
1262
- * call-seq:
1263
- * iw.optimize -> iw
1264
- *
1265
- * Optimize the index for searching. This commits any unwritten data to the
1266
- * index and optimizes the index into a single segment to improve search
1267
- * performance. This is an expensive operation and should not be called too
1268
- * often. The best time to call this is at the end of a long batch indexing
1269
- * process. Note that calling the optimize method do not in any way effect
1270
- * indexing speed (except for the time taken to complete the optimization
1271
- * process).
1272
- */
1273
- static VALUE
1274
- frb_iw_optimize(VALUE self) {
1275
- int ex_code = 0;
1276
- const char *msg = NULL;
1277
-
1278
- FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1279
-
1280
- FRT_TRY
1281
- frt_iw_optimize(iw);
1282
- FRT_XCATCHALL
1283
- ex_code = xcontext.excode;
1284
- msg = xcontext.msg;
1285
- FRT_HANDLED();
1286
- FRT_XENDTRY
1287
-
1288
- if (ex_code && msg) {
1289
- frb_raise(ex_code, msg);
1290
- }
1291
-
1292
- return self;
1293
- }
1294
-
1295
1250
  /*
1296
1251
  * call-seq:
1297
1252
  * iw.commit -> iw
@@ -1473,8 +1428,7 @@ static VALUE frb_iw_field_infos(VALUE self) {
1473
1428
  * to use the same analyzer in a QueryParser.
1474
1429
  */
1475
1430
  static VALUE
1476
- frb_iw_get_analyzer(VALUE self)
1477
- {
1431
+ frb_iw_get_analyzer(VALUE self) {
1478
1432
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1479
1433
  return frb_get_analyzer(iw->analyzer);
1480
1434
  }
@@ -1488,8 +1442,7 @@ frb_iw_get_analyzer(VALUE self)
1488
1442
  * same analyzer will be used for all documents during search.
1489
1443
  */
1490
1444
  static VALUE
1491
- frb_iw_set_analyzer(VALUE self, VALUE ranalyzer)
1492
- {
1445
+ frb_iw_set_analyzer(VALUE self, VALUE ranalyzer) {
1493
1446
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1494
1447
 
1495
1448
  frt_a_deref(iw->analyzer);
@@ -1504,8 +1457,7 @@ frb_iw_set_analyzer(VALUE self, VALUE ranalyzer)
1504
1457
  * Returns the current version of the index writer.
1505
1458
  */
1506
1459
  static VALUE
1507
- frb_iw_version(VALUE self)
1508
- {
1460
+ frb_iw_version(VALUE self) {
1509
1461
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1510
1462
  return ULL2NUM(iw->sis->version);
1511
1463
  }
@@ -1517,8 +1469,7 @@ frb_iw_version(VALUE self)
1517
1469
  * Return the current value of chunk_size
1518
1470
  */
1519
1471
  static VALUE
1520
- frb_iw_get_chunk_size(VALUE self)
1521
- {
1472
+ frb_iw_get_chunk_size(VALUE self) {
1522
1473
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1523
1474
  return INT2FIX(iw->config.chunk_size);
1524
1475
  }
@@ -1530,8 +1481,7 @@ frb_iw_get_chunk_size(VALUE self)
1530
1481
  * Set the chunk_size parameter
1531
1482
  */
1532
1483
  static VALUE
1533
- frb_iw_set_chunk_size(VALUE self, VALUE rval)
1534
- {
1484
+ frb_iw_set_chunk_size(VALUE self, VALUE rval) {
1535
1485
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1536
1486
  iw->config.chunk_size = FIX2INT(rval);
1537
1487
  return rval;
@@ -1544,8 +1494,7 @@ frb_iw_set_chunk_size(VALUE self, VALUE rval)
1544
1494
  * Return the current value of max_buffer_memory
1545
1495
  */
1546
1496
  static VALUE
1547
- frb_iw_get_max_buffer_memory(VALUE self)
1548
- {
1497
+ frb_iw_get_max_buffer_memory(VALUE self) {
1549
1498
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1550
1499
  return INT2FIX(iw->config.max_buffer_memory);
1551
1500
  }
@@ -1557,8 +1506,7 @@ frb_iw_get_max_buffer_memory(VALUE self)
1557
1506
  * Set the max_buffer_memory parameter
1558
1507
  */
1559
1508
  static VALUE
1560
- frb_iw_set_max_buffer_memory(VALUE self, VALUE rval)
1561
- {
1509
+ frb_iw_set_max_buffer_memory(VALUE self, VALUE rval) {
1562
1510
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1563
1511
  iw->config.max_buffer_memory = FIX2INT(rval);
1564
1512
  return rval;
@@ -1571,8 +1519,7 @@ frb_iw_set_max_buffer_memory(VALUE self, VALUE rval)
1571
1519
  * Return the current value of term_index_interval
1572
1520
  */
1573
1521
  static VALUE
1574
- frb_iw_get_index_interval(VALUE self)
1575
- {
1522
+ frb_iw_get_index_interval(VALUE self) {
1576
1523
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1577
1524
  return INT2FIX(iw->config.index_interval);
1578
1525
  }
@@ -1584,8 +1531,7 @@ frb_iw_get_index_interval(VALUE self)
1584
1531
  * Set the term_index_interval parameter
1585
1532
  */
1586
1533
  static VALUE
1587
- frb_iw_set_index_interval(VALUE self, VALUE rval)
1588
- {
1534
+ frb_iw_set_index_interval(VALUE self, VALUE rval) {
1589
1535
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1590
1536
  iw->config.index_interval = FIX2INT(rval);
1591
1537
  return rval;
@@ -1598,8 +1544,7 @@ frb_iw_set_index_interval(VALUE self, VALUE rval)
1598
1544
  * Return the current value of doc_skip_interval
1599
1545
  */
1600
1546
  static VALUE
1601
- frb_iw_get_skip_interval(VALUE self)
1602
- {
1547
+ frb_iw_get_skip_interval(VALUE self) {
1603
1548
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1604
1549
  return INT2FIX(iw->config.skip_interval);
1605
1550
  }
@@ -1611,8 +1556,7 @@ frb_iw_get_skip_interval(VALUE self)
1611
1556
  * Set the doc_skip_interval parameter
1612
1557
  */
1613
1558
  static VALUE
1614
- frb_iw_set_skip_interval(VALUE self, VALUE rval)
1615
- {
1559
+ frb_iw_set_skip_interval(VALUE self, VALUE rval) {
1616
1560
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1617
1561
  iw->config.skip_interval = FIX2INT(rval);
1618
1562
  return rval;
@@ -1625,8 +1569,7 @@ frb_iw_set_skip_interval(VALUE self, VALUE rval)
1625
1569
  * Return the current value of merge_factor
1626
1570
  */
1627
1571
  static VALUE
1628
- frb_iw_get_merge_factor(VALUE self)
1629
- {
1572
+ frb_iw_get_merge_factor(VALUE self) {
1630
1573
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1631
1574
  return INT2FIX(iw->config.merge_factor);
1632
1575
  }
@@ -1638,8 +1581,7 @@ frb_iw_get_merge_factor(VALUE self)
1638
1581
  * Set the merge_factor parameter
1639
1582
  */
1640
1583
  static VALUE
1641
- frb_iw_set_merge_factor(VALUE self, VALUE rval)
1642
- {
1584
+ frb_iw_set_merge_factor(VALUE self, VALUE rval) {
1643
1585
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1644
1586
  iw->config.merge_factor = FIX2INT(rval);
1645
1587
  return rval;
@@ -1652,8 +1594,7 @@ frb_iw_set_merge_factor(VALUE self, VALUE rval)
1652
1594
  * Return the current value of max_buffered_docs
1653
1595
  */
1654
1596
  static VALUE
1655
- frb_iw_get_max_buffered_docs(VALUE self)
1656
- {
1597
+ frb_iw_get_max_buffered_docs(VALUE self) {
1657
1598
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1658
1599
  return INT2FIX(iw->config.max_buffered_docs);
1659
1600
  }
@@ -1665,8 +1606,7 @@ frb_iw_get_max_buffered_docs(VALUE self)
1665
1606
  * Set the max_buffered_docs parameter
1666
1607
  */
1667
1608
  static VALUE
1668
- frb_iw_set_max_buffered_docs(VALUE self, VALUE rval)
1669
- {
1609
+ frb_iw_set_max_buffered_docs(VALUE self, VALUE rval) {
1670
1610
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1671
1611
  iw->config.max_buffered_docs = FIX2INT(rval);
1672
1612
  return rval;
@@ -1679,8 +1619,7 @@ frb_iw_set_max_buffered_docs(VALUE self, VALUE rval)
1679
1619
  * Return the current value of max_merge_docs
1680
1620
  */
1681
1621
  static VALUE
1682
- frb_iw_get_max_merge_docs(VALUE self)
1683
- {
1622
+ frb_iw_get_max_merge_docs(VALUE self) {
1684
1623
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1685
1624
  return INT2FIX(iw->config.max_merge_docs);
1686
1625
  }
@@ -1692,8 +1631,7 @@ frb_iw_get_max_merge_docs(VALUE self)
1692
1631
  * Set the max_merge_docs parameter
1693
1632
  */
1694
1633
  static VALUE
1695
- frb_iw_set_max_merge_docs(VALUE self, VALUE rval)
1696
- {
1634
+ frb_iw_set_max_merge_docs(VALUE self, VALUE rval) {
1697
1635
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1698
1636
  iw->config.max_merge_docs = FIX2INT(rval);
1699
1637
  return rval;
@@ -1706,8 +1644,7 @@ frb_iw_set_max_merge_docs(VALUE self, VALUE rval)
1706
1644
  * Return the current value of max_field_length
1707
1645
  */
1708
1646
  static VALUE
1709
- frb_iw_get_max_field_length(VALUE self)
1710
- {
1647
+ frb_iw_get_max_field_length(VALUE self) {
1711
1648
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1712
1649
  return INT2FIX(iw->config.max_field_length);
1713
1650
  }
@@ -1719,8 +1656,7 @@ frb_iw_get_max_field_length(VALUE self)
1719
1656
  * Set the max_field_length parameter
1720
1657
  */
1721
1658
  static VALUE
1722
- frb_iw_set_max_field_length(VALUE self, VALUE rval)
1723
- {
1659
+ frb_iw_set_max_field_length(VALUE self, VALUE rval) {
1724
1660
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1725
1661
  iw->config.max_field_length = FIX2INT(rval);
1726
1662
  return rval;
@@ -1800,6 +1736,7 @@ static VALUE frb_ir_init(VALUE self, VALUE rdir) {
1800
1736
  case T_STRING:
1801
1737
  frb_create_dir(rdir);
1802
1738
  store = frt_open_mdbx_store(rs2s(rdir));
1739
+ store->create_folder(store, segm_idx_name);
1803
1740
  break;
1804
1741
  default:
1805
1742
  FRT_RAISE(FRT_ARG_ERROR, "%s isn't a valid directory "
@@ -1821,6 +1758,7 @@ static VALUE frb_ir_init(VALUE self, VALUE rdir) {
1821
1758
  case T_STRING:
1822
1759
  frb_create_dir(rdir);
1823
1760
  store = frt_open_mdbx_store(rs2s(rdir));
1761
+ store->create_folder(store, segm_idx_name);
1824
1762
  break;
1825
1763
  default:
1826
1764
  FRT_RAISE(FRT_ARG_ERROR, "%s isn't a valid directory argument. "
@@ -1894,8 +1832,7 @@ frb_ir_set_norm(VALUE self, VALUE rdoc_id, VALUE rfield, VALUE rval) {
1894
1832
  * could have null bytes.
1895
1833
  */
1896
1834
  static VALUE
1897
- frb_ir_norms(VALUE self, VALUE rfield)
1898
- {
1835
+ frb_ir_norms(VALUE self, VALUE rfield) {
1899
1836
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
1900
1837
  frt_uchar *norms;
1901
1838
  norms = frt_ir_get_norms(ir, frb_field(rfield));
@@ -1913,8 +1850,7 @@ frb_ir_norms(VALUE self, VALUE rfield)
1913
1850
  * Expert: Get the norm values into a string +buffer+ starting at +offset+.
1914
1851
  */
1915
1852
  static VALUE
1916
- frb_ir_get_norms_into(VALUE self, VALUE rfield, VALUE rnorms, VALUE roffset)
1917
- {
1853
+ frb_ir_get_norms_into(VALUE self, VALUE rfield, VALUE rnorms, VALUE roffset) {
1918
1854
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
1919
1855
  int offset;
1920
1856
  offset = FIX2INT(roffset);
@@ -1969,8 +1905,7 @@ frb_ir_commit(VALUE self) {
1969
1905
  * errors.
1970
1906
  */
1971
1907
  static VALUE
1972
- frb_ir_close(VALUE self)
1973
- {
1908
+ frb_ir_close(VALUE self) {
1974
1909
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
1975
1910
  ((struct RData *)(self))->data = NULL;
1976
1911
  ((struct RData *)(self))->dmark = NULL;
@@ -1987,8 +1922,7 @@ frb_ir_close(VALUE self)
1987
1922
  * IndexReader or committed by any other IndexReader.
1988
1923
  */
1989
1924
  static VALUE
1990
- frb_ir_has_deletions(VALUE self)
1991
- {
1925
+ frb_ir_has_deletions(VALUE self) {
1992
1926
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
1993
1927
  return ir->has_deletions(ir) ? Qtrue : Qfalse;
1994
1928
  }
@@ -2029,8 +1963,7 @@ frb_ir_delete(VALUE self, VALUE rdoc_id) {
2029
1963
  * Returns true if the document at +doc_id+ has been deleted.
2030
1964
  */
2031
1965
  static VALUE
2032
- frb_ir_is_deleted(VALUE self, VALUE rdoc_id)
2033
- {
1966
+ frb_ir_is_deleted(VALUE self, VALUE rdoc_id) {
2034
1967
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2035
1968
  return ir->is_deleted(ir, FIX2INT(rdoc_id)) ? Qtrue : Qfalse;
2036
1969
  }
@@ -2045,8 +1978,7 @@ frb_ir_is_deleted(VALUE self, VALUE rdoc_id)
2045
1978
  * in the index.
2046
1979
  */
2047
1980
  static VALUE
2048
- frb_ir_max_doc(VALUE self)
2049
- {
1981
+ frb_ir_max_doc(VALUE self) {
2050
1982
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2051
1983
  return INT2FIX(ir->max_doc(ir));
2052
1984
  }
@@ -2060,8 +1992,7 @@ frb_ir_max_doc(VALUE self)
2060
1992
  * deleted from the index.
2061
1993
  */
2062
1994
  static VALUE
2063
- frb_ir_num_docs(VALUE self)
2064
- {
1995
+ frb_ir_num_docs(VALUE self) {
2065
1996
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2066
1997
  return INT2FIX(ir->num_docs(ir));
2067
1998
  }
@@ -2076,24 +2007,36 @@ frb_ir_num_docs(VALUE self)
2076
2007
  * effect on these documents.
2077
2008
  */
2078
2009
  static VALUE
2079
- frb_ir_undelete_all(VALUE self)
2080
- {
2010
+ frb_ir_undelete_all(VALUE self) {
2081
2011
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2082
2012
  frt_ir_undelete_all(ir);
2083
2013
  return self;
2084
2014
  }
2085
2015
 
2086
2016
  static VALUE
2087
- frb_get_doc_range(FrtIndexReader *ir, int pos, int len, int max)
2088
- {
2017
+ frb_get_doc_range(FrtIndexReader *ir, int pos, int len, int max) {
2018
+ int ex_code = 0;
2019
+ const char *msg = NULL;
2089
2020
  VALUE ary;
2090
2021
  int i;
2091
2022
  max = FRT_MIN(max, pos+len);
2092
2023
  len = max - pos;
2093
2024
  ary = rb_ary_new2(len);
2094
- for (i = 0; i < len; i++) {
2095
- rb_ary_store(ary, i, frb_get_lazy_doc(ir->get_lazy_doc(ir, i + pos)));
2025
+
2026
+ FRT_TRY
2027
+ for (i = 0; i < len; i++) {
2028
+ rb_ary_store(ary, i, frb_get_lazy_doc(ir->get_lazy_doc(ir, i + pos)));
2029
+ }
2030
+ FRT_XCATCHALL
2031
+ ex_code = xcontext.excode;
2032
+ msg = xcontext.msg;
2033
+ FRT_HANDLED();
2034
+ FRT_XENDTRY
2035
+
2036
+ if (ex_code && msg) {
2037
+ frb_raise(ex_code, msg);
2096
2038
  }
2039
+
2097
2040
  return ary;
2098
2041
  }
2099
2042
 
@@ -2121,7 +2064,24 @@ frb_ir_get_doc(int argc, VALUE *argv, VALUE self) {
2121
2064
  rb_raise(rb_eArgError, "index %ld is out of range [%d..%ld] for "
2122
2065
  "IndexReader#[]", pos, 0, max);
2123
2066
  }
2124
- return frb_get_lazy_doc(ir->get_lazy_doc(ir, pos));
2067
+
2068
+ int ex_code = 0;
2069
+ const char *msg = NULL;
2070
+ VALUE ld = Qnil;
2071
+
2072
+ FRT_TRY
2073
+ ld = frb_get_lazy_doc(ir->get_lazy_doc(ir, pos));
2074
+ FRT_XCATCHALL
2075
+ ex_code = xcontext.excode;
2076
+ msg = xcontext.msg;
2077
+ FRT_HANDLED();
2078
+ FRT_XENDTRY
2079
+
2080
+ if (ex_code && msg) {
2081
+ frb_raise(ex_code, msg);
2082
+ }
2083
+
2084
+ return ld;
2125
2085
  }
2126
2086
 
2127
2087
  /* check if idx is Range */
@@ -2152,8 +2112,7 @@ frb_ir_get_doc(int argc, VALUE *argv, VALUE self) {
2152
2112
  * index to search the latest documents added to the index.
2153
2113
  */
2154
2114
  static VALUE
2155
- frb_ir_is_latest(VALUE self)
2156
- {
2115
+ frb_ir_is_latest(VALUE self) {
2157
2116
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2158
2117
  return frt_ir_is_latest(ir) ? Qtrue : Qfalse;
2159
2118
  }
@@ -2166,8 +2125,7 @@ frb_ir_is_latest(VALUE self)
2166
2125
  * the index. Return nil if no such term_vector exists. See TermVector.
2167
2126
  */
2168
2127
  static VALUE
2169
- frb_ir_term_vector(VALUE self, VALUE rdoc_id, VALUE rfield)
2170
- {
2128
+ frb_ir_term_vector(VALUE self, VALUE rdoc_id, VALUE rfield) {
2171
2129
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2172
2130
  FrtTermVector *tv;
2173
2131
  VALUE rtv;
@@ -2176,15 +2134,13 @@ frb_ir_term_vector(VALUE self, VALUE rdoc_id, VALUE rfield)
2176
2134
  rtv = frb_get_tv(tv);
2177
2135
  frt_tv_destroy(tv);
2178
2136
  return rtv;
2179
- }
2180
- else {
2137
+ } else {
2181
2138
  return Qnil;
2182
2139
  }
2183
2140
  }
2184
2141
 
2185
2142
  static void
2186
- frb_add_each_tv(void *key, void *value, void *rtvs)
2187
- {
2143
+ frb_add_each_tv(void *key, void *value, void *rtvs) {
2188
2144
  rb_hash_aset((VALUE)rtvs, ID2SYM((ID)key), frb_get_tv(value));
2189
2145
  }
2190
2146
 
@@ -2197,8 +2153,7 @@ frb_add_each_tv(void *key, void *value, void *rtvs)
2197
2153
  * and they are referenced by field names (as symbols).
2198
2154
  */
2199
2155
  static VALUE
2200
- frb_ir_term_vectors(VALUE self, VALUE rdoc_id)
2201
- {
2156
+ frb_ir_term_vectors(VALUE self, VALUE rdoc_id) {
2202
2157
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2203
2158
  FrtHash *tvs = ir->term_vectors(ir, FIX2INT(rdoc_id));
2204
2159
  VALUE rtvs = rb_hash_new();
@@ -2216,8 +2171,7 @@ frb_ir_term_vectors(VALUE self, VALUE rdoc_id)
2216
2171
  * See TermDocEnum for more info.
2217
2172
  */
2218
2173
  static VALUE
2219
- frb_ir_term_docs(VALUE self)
2220
- {
2174
+ frb_ir_term_docs(VALUE self) {
2221
2175
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2222
2176
  return frb_get_tde(self, ir->term_docs(ir));
2223
2177
  }
@@ -2230,8 +2184,7 @@ frb_ir_term_docs(VALUE self)
2230
2184
  * term +term+ in the field +field+. See TermDocEnum for more info.
2231
2185
  */
2232
2186
  static VALUE
2233
- frb_ir_term_docs_for(VALUE self, VALUE rfield, VALUE rterm)
2234
- {
2187
+ frb_ir_term_docs_for(VALUE self, VALUE rfield, VALUE rterm) {
2235
2188
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2236
2189
  return frb_get_tde(self, ir_term_docs_for(ir,
2237
2190
  frb_field(rfield),
@@ -2247,8 +2200,7 @@ frb_ir_term_docs_for(VALUE self, VALUE rfield, VALUE rterm)
2247
2200
  * more info.
2248
2201
  */
2249
2202
  static VALUE
2250
- frb_ir_term_positions(VALUE self)
2251
- {
2203
+ frb_ir_term_positions(VALUE self) {
2252
2204
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2253
2205
  return frb_get_tde(self, ir->term_positions(ir));
2254
2206
  }
@@ -2262,8 +2214,7 @@ frb_ir_term_positions(VALUE self)
2262
2214
  * TermDocEnum for more info.
2263
2215
  */
2264
2216
  static VALUE
2265
- frb_ir_t_pos_for(VALUE self, VALUE rfield, VALUE rterm)
2266
- {
2217
+ frb_ir_t_pos_for(VALUE self, VALUE rfield, VALUE rterm) {
2267
2218
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2268
2219
  return frb_get_tde(self, frt_ir_term_positions_for(ir,
2269
2220
  frb_field(rfield),
@@ -2278,8 +2229,7 @@ frb_ir_t_pos_for(VALUE self, VALUE rfield, VALUE rterm)
2278
2229
  * field +field+.
2279
2230
  */
2280
2231
  static VALUE
2281
- frb_ir_doc_freq(VALUE self, VALUE rfield, VALUE rterm)
2282
- {
2232
+ frb_ir_doc_freq(VALUE self, VALUE rfield, VALUE rterm) {
2283
2233
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2284
2234
  return INT2FIX(frt_ir_doc_freq(ir,
2285
2235
  frb_field(rfield),
@@ -2294,8 +2244,7 @@ frb_ir_doc_freq(VALUE self, VALUE rfield, VALUE rterm)
2294
2244
  * terms in the field +field+ in the index.
2295
2245
  */
2296
2246
  static VALUE
2297
- frb_ir_terms(VALUE self, VALUE rfield)
2298
- {
2247
+ frb_ir_terms(VALUE self, VALUE rfield) {
2299
2248
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2300
2249
  return frb_get_te(self, frt_ir_terms(ir, frb_field(rfield)));
2301
2250
  }
@@ -2308,8 +2257,7 @@ frb_ir_terms(VALUE self, VALUE rfield)
2308
2257
  * at term +term+.
2309
2258
  */
2310
2259
  static VALUE
2311
- frb_ir_terms_from(VALUE self, VALUE rfield, VALUE rterm)
2312
- {
2260
+ frb_ir_terms_from(VALUE self, VALUE rfield, VALUE rterm) {
2313
2261
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2314
2262
  return frb_get_te(self, frt_ir_terms_from(ir,
2315
2263
  frb_field(rfield),
@@ -2323,8 +2271,7 @@ frb_ir_terms_from(VALUE self, VALUE rfield, VALUE rterm)
2323
2271
  * Same return a count of the number of terms in the field
2324
2272
  */
2325
2273
  static VALUE
2326
- frb_ir_term_count(VALUE self, VALUE rfield)
2327
- {
2274
+ frb_ir_term_count(VALUE self, VALUE rfield) {
2328
2275
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2329
2276
  FrtTermEnum *te = frt_ir_terms(ir, frb_field(rfield));
2330
2277
  int count = 0;
@@ -2345,8 +2292,7 @@ frb_ir_term_count(VALUE self, VALUE rfield)
2345
2292
  * gathered from the FieldInfos object.
2346
2293
  */
2347
2294
  static VALUE
2348
- frb_ir_fields(VALUE self)
2349
- {
2295
+ frb_ir_fields(VALUE self) {
2350
2296
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2351
2297
  FrtFieldInfos *fis = ir->fis;
2352
2298
  VALUE rfield_names = rb_ary_new();
@@ -2379,8 +2325,7 @@ static VALUE frb_ir_field_infos(VALUE self) {
2379
2325
  * of field names can also be gathered from the FieldInfos object.
2380
2326
  */
2381
2327
  static VALUE
2382
- frb_ir_tk_fields(VALUE self)
2383
- {
2328
+ frb_ir_tk_fields(VALUE self) {
2384
2329
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2385
2330
  FrtFieldInfos *fis = ir->fis;
2386
2331
  VALUE rfield_names = rb_ary_new();
@@ -2411,14 +2356,28 @@ static VALUE frb_ir_to_enum(VALUE self) {
2411
2356
  static VALUE frb_ir_each(VALUE self) {
2412
2357
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2413
2358
  if (rb_block_given_p()) {
2359
+ int ex_code = 0;
2360
+ const char *msg = NULL;
2414
2361
  long i;
2415
2362
  long max_doc = ir->max_doc(ir);
2416
2363
  VALUE rld;
2417
- for (i = 0; i < max_doc; i++) {
2418
- if (ir->is_deleted(ir, i)) continue;
2419
- rld = frb_get_lazy_doc(ir->get_lazy_doc(ir, i));
2420
- rb_yield(rld);
2364
+
2365
+ FRT_TRY
2366
+ for (i = 0; i < max_doc; i++) {
2367
+ if (ir->is_deleted(ir, i)) continue;
2368
+ rld = frb_get_lazy_doc(ir->get_lazy_doc(ir, i));
2369
+ rb_yield(rld);
2370
+ }
2371
+ FRT_XCATCHALL
2372
+ ex_code = xcontext.excode;
2373
+ msg = xcontext.msg;
2374
+ FRT_HANDLED();
2375
+ FRT_XENDTRY
2376
+
2377
+ if (ex_code && msg) {
2378
+ frb_raise(ex_code, msg);
2421
2379
  }
2380
+
2422
2381
  return self;
2423
2382
  } else {
2424
2383
  return frb_ir_to_enum(self);
@@ -2811,7 +2770,6 @@ void Init_IndexWriter(void) {
2811
2770
  rb_define_method(cIndexWriter, "close", frb_iw_close, 0);
2812
2771
  rb_define_method(cIndexWriter, "add_document", frb_iw_add_doc, 1);
2813
2772
  rb_define_method(cIndexWriter, "<<", frb_iw_add_doc, 1);
2814
- rb_define_method(cIndexWriter, "optimize", frb_iw_optimize, 0);
2815
2773
  rb_define_method(cIndexWriter, "commit", frb_iw_commit, 0);
2816
2774
  rb_define_method(cIndexWriter, "add_readers", frb_iw_add_readers, 1);
2817
2775
  rb_define_method(cIndexWriter, "delete", frb_iw_delete, 2);