isomorfeus-ferret 0.17.2 → 0.17.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) 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/brotli_dec_decode.c +4 -2
  6. data/ext/isomorfeus_ferret_ext/brotli_enc_encode.c +3 -2
  7. data/ext/isomorfeus_ferret_ext/frb_analysis.c +4 -5
  8. data/ext/isomorfeus_ferret_ext/frb_field_info.c +3 -4
  9. data/ext/isomorfeus_ferret_ext/frb_index.c +161 -187
  10. data/ext/isomorfeus_ferret_ext/frb_lazy_doc.c +14 -16
  11. data/ext/isomorfeus_ferret_ext/frb_search.c +77 -69
  12. data/ext/isomorfeus_ferret_ext/frb_store.c +27 -13
  13. data/ext/isomorfeus_ferret_ext/frb_utils.c +3 -6
  14. data/ext/isomorfeus_ferret_ext/frt_analysis.c +39 -46
  15. data/ext/isomorfeus_ferret_ext/frt_analysis.h +9 -9
  16. data/ext/isomorfeus_ferret_ext/frt_array.c +11 -22
  17. data/ext/isomorfeus_ferret_ext/frt_bitvector.h +3 -6
  18. data/ext/isomorfeus_ferret_ext/frt_doc_field.c +87 -0
  19. data/ext/isomorfeus_ferret_ext/frt_doc_field.h +26 -0
  20. data/ext/isomorfeus_ferret_ext/frt_document.c +4 -97
  21. data/ext/isomorfeus_ferret_ext/frt_document.h +5 -33
  22. data/ext/isomorfeus_ferret_ext/frt_except.c +8 -6
  23. data/ext/isomorfeus_ferret_ext/frt_except.h +1 -2
  24. data/ext/isomorfeus_ferret_ext/frt_field_index.c +14 -33
  25. data/ext/isomorfeus_ferret_ext/frt_field_index.h +0 -6
  26. data/ext/isomorfeus_ferret_ext/frt_field_info.c +69 -0
  27. data/ext/isomorfeus_ferret_ext/frt_field_info.h +49 -0
  28. data/ext/isomorfeus_ferret_ext/frt_field_infos.c +196 -0
  29. data/ext/isomorfeus_ferret_ext/frt_field_infos.h +35 -0
  30. data/ext/isomorfeus_ferret_ext/frt_filter.c +2 -2
  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 +35 -45
  39. data/ext/isomorfeus_ferret_ext/frt_in_stream.h +3 -2
  40. data/ext/isomorfeus_ferret_ext/frt_ind.c +21 -39
  41. data/ext/isomorfeus_ferret_ext/frt_ind.h +1 -1
  42. data/ext/isomorfeus_ferret_ext/frt_index.c +334 -848
  43. data/ext/isomorfeus_ferret_ext/frt_index.h +4 -105
  44. data/ext/isomorfeus_ferret_ext/frt_lang.c +5 -10
  45. data/ext/isomorfeus_ferret_ext/frt_lazy_doc.c +3 -3
  46. data/ext/isomorfeus_ferret_ext/frt_lazy_doc.h +1 -1
  47. data/ext/isomorfeus_ferret_ext/frt_lazy_doc_field.c +18 -25
  48. data/ext/isomorfeus_ferret_ext/frt_lazy_doc_field.h +5 -5
  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 +31 -43
  54. data/ext/isomorfeus_ferret_ext/frt_out_stream.h +2 -2
  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 +131 -217
  60. data/ext/isomorfeus_ferret_ext/frt_q_const_score.c +2 -2
  61. data/ext/isomorfeus_ferret_ext/frt_q_filtered_query.c +4 -4
  62. data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +18 -26
  63. data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +27 -28
  64. data/ext/isomorfeus_ferret_ext/frt_q_parser.c +49 -98
  65. data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +64 -116
  66. data/ext/isomorfeus_ferret_ext/frt_q_range.c +8 -14
  67. data/ext/isomorfeus_ferret_ext/frt_q_span.c +251 -365
  68. data/ext/isomorfeus_ferret_ext/frt_q_term.c +9 -9
  69. data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +1 -2
  70. data/ext/isomorfeus_ferret_ext/frt_ram_store.c +134 -85
  71. data/ext/isomorfeus_ferret_ext/frt_search.c +109 -191
  72. data/ext/isomorfeus_ferret_ext/frt_search.h +6 -6
  73. data/ext/isomorfeus_ferret_ext/frt_similarity.c +12 -23
  74. data/ext/isomorfeus_ferret_ext/frt_similarity.h +1 -2
  75. data/ext/isomorfeus_ferret_ext/frt_sort.c +20 -20
  76. data/ext/isomorfeus_ferret_ext/frt_store.c +13 -25
  77. data/ext/isomorfeus_ferret_ext/frt_store.h +86 -52
  78. data/ext/isomorfeus_ferret_ext/frt_term_vectors.c +8 -16
  79. data/ext/isomorfeus_ferret_ext/frt_win32.h +5 -10
  80. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +12 -11
  81. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +11 -13
  82. data/ext/isomorfeus_ferret_ext/lz4.c +422 -195
  83. data/ext/isomorfeus_ferret_ext/lz4.h +114 -46
  84. data/ext/isomorfeus_ferret_ext/lz4frame.c +421 -242
  85. data/ext/isomorfeus_ferret_ext/lz4frame.h +122 -53
  86. data/ext/isomorfeus_ferret_ext/lz4hc.c +127 -111
  87. data/ext/isomorfeus_ferret_ext/lz4hc.h +14 -14
  88. data/ext/isomorfeus_ferret_ext/lz4xxhash.h +1 -1
  89. data/ext/isomorfeus_ferret_ext/mdbx.c +3762 -2526
  90. data/ext/isomorfeus_ferret_ext/mdbx.h +115 -70
  91. data/ext/isomorfeus_ferret_ext/test.c +41 -88
  92. data/ext/isomorfeus_ferret_ext/test.h +3 -6
  93. data/ext/isomorfeus_ferret_ext/test_1710.c +11 -13
  94. data/ext/isomorfeus_ferret_ext/test_analysis.c +32 -64
  95. data/ext/isomorfeus_ferret_ext/test_array.c +6 -12
  96. data/ext/isomorfeus_ferret_ext/test_bitvector.c +12 -24
  97. data/ext/isomorfeus_ferret_ext/test_document.c +23 -33
  98. data/ext/isomorfeus_ferret_ext/test_except.c +10 -21
  99. data/ext/isomorfeus_ferret_ext/test_fields.c +62 -68
  100. data/ext/isomorfeus_ferret_ext/test_file_deleter.c +16 -25
  101. data/ext/isomorfeus_ferret_ext/test_filter.c +22 -33
  102. data/ext/isomorfeus_ferret_ext/test_global.c +14 -29
  103. data/ext/isomorfeus_ferret_ext/test_hash.c +19 -38
  104. data/ext/isomorfeus_ferret_ext/test_hashset.c +8 -16
  105. data/ext/isomorfeus_ferret_ext/test_helper.c +4 -8
  106. data/ext/isomorfeus_ferret_ext/test_highlighter.c +16 -28
  107. data/ext/isomorfeus_ferret_ext/test_index.c +307 -519
  108. data/ext/isomorfeus_ferret_ext/test_lang.c +7 -14
  109. data/ext/isomorfeus_ferret_ext/test_mdbx_store.c +2 -5
  110. data/ext/isomorfeus_ferret_ext/test_mempool.c +5 -10
  111. data/ext/isomorfeus_ferret_ext/test_multimapper.c +3 -6
  112. data/ext/isomorfeus_ferret_ext/test_priorityqueue.c +9 -18
  113. data/ext/isomorfeus_ferret_ext/test_q_const_score.c +4 -6
  114. data/ext/isomorfeus_ferret_ext/test_q_filtered.c +3 -4
  115. data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +9 -15
  116. data/ext/isomorfeus_ferret_ext/test_q_parser.c +8 -16
  117. data/ext/isomorfeus_ferret_ext/test_q_span.c +19 -35
  118. data/ext/isomorfeus_ferret_ext/test_ram_store.c +14 -13
  119. data/ext/isomorfeus_ferret_ext/test_search.c +66 -115
  120. data/ext/isomorfeus_ferret_ext/test_segments.c +8 -13
  121. data/ext/isomorfeus_ferret_ext/test_similarity.c +2 -4
  122. data/ext/isomorfeus_ferret_ext/test_sort.c +17 -27
  123. data/ext/isomorfeus_ferret_ext/test_store.c +96 -115
  124. data/ext/isomorfeus_ferret_ext/test_term.c +9 -15
  125. data/ext/isomorfeus_ferret_ext/test_term_vectors.c +9 -14
  126. data/ext/isomorfeus_ferret_ext/test_test.c +4 -8
  127. data/ext/isomorfeus_ferret_ext/test_threading.c +15 -21
  128. data/ext/isomorfeus_ferret_ext/testhelper.c +11 -21
  129. data/ext/isomorfeus_ferret_ext/testhelper.h +1 -1
  130. data/ext/isomorfeus_ferret_ext/tests_all.h +1 -2
  131. data/lib/isomorfeus/ferret/index/index.rb +8 -8
  132. data/lib/isomorfeus/ferret/version.rb +1 -1
  133. metadata +32 -6
@@ -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;
@@ -657,21 +653,14 @@ static VALUE frb_tde_seek_te(VALUE self, VALUE rterm_enum) {
657
653
  return self;
658
654
  }
659
655
 
660
- /*
661
- * call-seq:
662
- * term_doc_enum.doc -> doc_id
663
- *
664
- * Returns the current document number pointed to by the +term_doc_enum+.
656
+ /* Returns the current document number pointed to by the +term_doc_enum+.
665
657
  */
666
- static VALUE frb_tde_doc(VALUE self) {
658
+ static VALUE frb_tde_doc_num(VALUE self) {
667
659
  FrtTermDocEnum *tde = (FrtTermDocEnum *)DATA_PTR(self);
668
660
  return INT2FIX(tde->doc_num(tde));
669
661
  }
670
662
 
671
663
  /*
672
- * call-seq:
673
- * term_doc_enum.doc -> doc_id
674
- *
675
664
  * Returns the frequency of the current document pointed to by the
676
665
  * +term_doc_enum+.
677
666
  */
@@ -680,11 +669,7 @@ static VALUE frb_tde_freq(VALUE self) {
680
669
  return INT2FIX(tde->freq(tde));
681
670
  }
682
671
 
683
- /*
684
- * call-seq:
685
- * term_doc_enum.doc -> doc_id
686
- *
687
- * Move forward to the next document in the enumeration. Returns +true+ if
672
+ /* Move forward to the next document in the enumeration. Returns +true+ if
688
673
  * there is another document or +false+ otherwise.
689
674
  */
690
675
  static VALUE frb_tde_next(VALUE self) {
@@ -692,11 +677,7 @@ static VALUE frb_tde_next(VALUE self) {
692
677
  return tde->next(tde) ? Qtrue : Qfalse;
693
678
  }
694
679
 
695
- /*
696
- * call-seq:
697
- * term_doc_enum.doc -> doc_id
698
- *
699
- * Move forward to the next document in the enumeration. Returns +true+ if
680
+ /* Move forward to the next document in the enumeration. Returns +true+ if
700
681
  * there is another document or +false+ otherwise.
701
682
  */
702
683
  static VALUE frb_tde_next_position(VALUE self) {
@@ -713,7 +694,7 @@ static VALUE frb_tde_next_position(VALUE self) {
713
694
 
714
695
  /*
715
696
  * call-seq:
716
- * term_doc_enum.each {|doc_id, freq| do_something() } -> doc_count
697
+ * term_doc_enum.each {|doc_num, freq| do_something() } -> doc_count
717
698
  *
718
699
  * Iterate through the documents and document frequencies in the
719
700
  * +term_doc_enum+.
@@ -777,16 +758,13 @@ static VALUE frb_tde_to_json(int argc, VALUE *argv, VALUE self) {
777
758
  if (do_positions) {
778
759
  if (argc == 0) {
779
760
  format = "{\"document\":%d,\"frequency\":%d,\"positions\":[";
780
- }
781
- else {
761
+ } else {
782
762
  format = "[%d,%d,[";
783
763
  }
784
- }
785
- else {
764
+ } else {
786
765
  if (argc == 0) {
787
766
  format = "{\"document\":%d,\"frequency\":%d},";
788
- }
789
- else {
767
+ } else {
790
768
  format = "[%d,%d],";
791
769
  }
792
770
  }
@@ -828,8 +806,8 @@ static VALUE frb_tde_to_json(int argc, VALUE *argv, VALUE self) {
828
806
  * used within the each method. For example, to print the terms documents and
829
807
  * positions;
830
808
  *
831
- * tde.each do |doc_id, freq|
832
- * puts "term appeared #{freq} times in document #{doc_id}:"
809
+ * tde.each do |doc_num, freq|
810
+ * puts "term appeared #{freq} times in document #{doc_num}:"
833
811
  * positions = []
834
812
  * tde.each_position {|pos| positions << pos}
835
813
  * puts " #{positions.join(', ')}"
@@ -1039,6 +1017,7 @@ static VALUE frb_iw_init(int argc, VALUE *argv, VALUE self) {
1039
1017
  StringValue(rval);
1040
1018
  frb_create_dir(rval);
1041
1019
  store = frt_open_mdbx_store(rs2s(rval));
1020
+ store->create_folder(store, segm_idx_name);
1042
1021
  }
1043
1022
 
1044
1023
  if ((rval = rb_hash_aref(roptions, sym_analyzer)) != Qnil) {
@@ -1060,8 +1039,9 @@ static VALUE frb_iw_init(int argc, VALUE *argv, VALUE self) {
1060
1039
  }
1061
1040
  if (NULL == store) {
1062
1041
  store = frt_open_ram_store(NULL);
1042
+ store->create_folder(store, segm_idx_name);
1063
1043
  }
1064
- if (!create && create_if_missing && !store->exists(store, "segments")) {
1044
+ if (!create && create_if_missing && !store->exists(store, segm_idx_name, "segments")) {
1065
1045
  create = true;
1066
1046
  }
1067
1047
  if (create) {
@@ -1130,8 +1110,7 @@ frb_iw_get_doc_count(VALUE self) {
1130
1110
  }
1131
1111
 
1132
1112
  static int
1133
- frb_hash_to_doc_i(VALUE key, VALUE value, VALUE arg)
1134
- {
1113
+ frb_hash_to_doc_i(VALUE key, VALUE value, VALUE arg) {
1135
1114
  if (key == Qundef) {
1136
1115
  return ST_CONTINUE;
1137
1116
  } else {
@@ -1151,20 +1130,18 @@ frb_hash_to_doc_i(VALUE key, VALUE value, VALUE arg)
1151
1130
  case T_ARRAY:
1152
1131
  {
1153
1132
  int i;
1154
- df->destroy_data = true;
1155
1133
  for (i = 0; i < RARRAY_LEN(value); i++) {
1156
1134
  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));
1135
+ frt_df_add_data_len(df, RSTRING_PTR(val), RSTRING_LEN(val), rb_enc_get(val));
1158
1136
  }
1159
1137
  }
1160
1138
  break;
1161
1139
  case T_STRING:
1162
- frt_df_add_data_len(df, rs2s(value), RSTRING_LEN(value), rb_enc_get(value));
1140
+ frt_df_add_data_len(df, RSTRING_PTR(value), RSTRING_LEN(value), rb_enc_get(value));
1163
1141
  break;
1164
1142
  default:
1165
1143
  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));
1144
+ frt_df_add_data_len(df, RSTRING_PTR(val), RSTRING_LEN(val), rb_enc_get(val));
1168
1145
  break;
1169
1146
  }
1170
1147
  FRT_TRY
@@ -1181,8 +1158,7 @@ frb_hash_to_doc_i(VALUE key, VALUE value, VALUE arg)
1181
1158
  }
1182
1159
 
1183
1160
  static FrtDocument *
1184
- frb_get_doc(VALUE rdoc)
1185
- {
1161
+ frb_get_doc(VALUE rdoc) {
1186
1162
  VALUE val;
1187
1163
  FrtDocument *doc = frt_doc_new();
1188
1164
  FrtDocField *df;
@@ -1199,27 +1175,25 @@ frb_get_doc(VALUE rdoc)
1199
1175
  {
1200
1176
  int i;
1201
1177
  df = frt_df_new(fsym_content);
1202
- df->destroy_data = true;
1203
1178
  for (i = 0; i < RARRAY_LEN(rdoc); i++) {
1204
1179
  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));
1180
+ frt_df_add_data_len(df, RSTRING_PTR(val), RSTRING_LEN(val), rb_enc_get(val));
1206
1181
  }
1207
1182
  frt_doc_add_field(doc, df);
1208
1183
  }
1209
1184
  break;
1210
1185
  case T_SYMBOL:
1211
1186
  /* 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));
1187
+ df = frt_df_add_data(frt_df_new(fsym_content), rb_id2name(SYM2ID(rdoc)), rb_enc_get(rdoc));
1213
1188
  frt_doc_add_field(doc, df);
1214
1189
  break;
1215
1190
  case T_STRING:
1216
- df = frt_df_add_data_len(frt_df_new(fsym_content), rs2s(rdoc), RSTRING_LEN(rdoc), rb_enc_get(rdoc));
1191
+ df = frt_df_add_data_len(frt_df_new(fsym_content), RSTRING_PTR(rdoc), RSTRING_LEN(rdoc), rb_enc_get(rdoc));
1217
1192
  frt_doc_add_field(doc, df);
1218
1193
  break;
1219
1194
  default:
1220
1195
  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;
1196
+ df = frt_df_add_data_len(frt_df_new(fsym_content), RSTRING_PTR(val), RSTRING_LEN(val), rb_enc_get(val));
1223
1197
  frt_doc_add_field(doc, df);
1224
1198
  break;
1225
1199
  }
@@ -1439,8 +1413,7 @@ static VALUE frb_iw_field_infos(VALUE self) {
1439
1413
  * to use the same analyzer in a QueryParser.
1440
1414
  */
1441
1415
  static VALUE
1442
- frb_iw_get_analyzer(VALUE self)
1443
- {
1416
+ frb_iw_get_analyzer(VALUE self) {
1444
1417
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1445
1418
  return frb_get_analyzer(iw->analyzer);
1446
1419
  }
@@ -1454,8 +1427,7 @@ frb_iw_get_analyzer(VALUE self)
1454
1427
  * same analyzer will be used for all documents during search.
1455
1428
  */
1456
1429
  static VALUE
1457
- frb_iw_set_analyzer(VALUE self, VALUE ranalyzer)
1458
- {
1430
+ frb_iw_set_analyzer(VALUE self, VALUE ranalyzer) {
1459
1431
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1460
1432
 
1461
1433
  frt_a_deref(iw->analyzer);
@@ -1470,8 +1442,7 @@ frb_iw_set_analyzer(VALUE self, VALUE ranalyzer)
1470
1442
  * Returns the current version of the index writer.
1471
1443
  */
1472
1444
  static VALUE
1473
- frb_iw_version(VALUE self)
1474
- {
1445
+ frb_iw_version(VALUE self) {
1475
1446
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1476
1447
  return ULL2NUM(iw->sis->version);
1477
1448
  }
@@ -1483,8 +1454,7 @@ frb_iw_version(VALUE self)
1483
1454
  * Return the current value of chunk_size
1484
1455
  */
1485
1456
  static VALUE
1486
- frb_iw_get_chunk_size(VALUE self)
1487
- {
1457
+ frb_iw_get_chunk_size(VALUE self) {
1488
1458
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1489
1459
  return INT2FIX(iw->config.chunk_size);
1490
1460
  }
@@ -1496,8 +1466,7 @@ frb_iw_get_chunk_size(VALUE self)
1496
1466
  * Set the chunk_size parameter
1497
1467
  */
1498
1468
  static VALUE
1499
- frb_iw_set_chunk_size(VALUE self, VALUE rval)
1500
- {
1469
+ frb_iw_set_chunk_size(VALUE self, VALUE rval) {
1501
1470
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1502
1471
  iw->config.chunk_size = FIX2INT(rval);
1503
1472
  return rval;
@@ -1510,8 +1479,7 @@ frb_iw_set_chunk_size(VALUE self, VALUE rval)
1510
1479
  * Return the current value of max_buffer_memory
1511
1480
  */
1512
1481
  static VALUE
1513
- frb_iw_get_max_buffer_memory(VALUE self)
1514
- {
1482
+ frb_iw_get_max_buffer_memory(VALUE self) {
1515
1483
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1516
1484
  return INT2FIX(iw->config.max_buffer_memory);
1517
1485
  }
@@ -1523,8 +1491,7 @@ frb_iw_get_max_buffer_memory(VALUE self)
1523
1491
  * Set the max_buffer_memory parameter
1524
1492
  */
1525
1493
  static VALUE
1526
- frb_iw_set_max_buffer_memory(VALUE self, VALUE rval)
1527
- {
1494
+ frb_iw_set_max_buffer_memory(VALUE self, VALUE rval) {
1528
1495
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1529
1496
  iw->config.max_buffer_memory = FIX2INT(rval);
1530
1497
  return rval;
@@ -1537,8 +1504,7 @@ frb_iw_set_max_buffer_memory(VALUE self, VALUE rval)
1537
1504
  * Return the current value of term_index_interval
1538
1505
  */
1539
1506
  static VALUE
1540
- frb_iw_get_index_interval(VALUE self)
1541
- {
1507
+ frb_iw_get_index_interval(VALUE self) {
1542
1508
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1543
1509
  return INT2FIX(iw->config.index_interval);
1544
1510
  }
@@ -1550,8 +1516,7 @@ frb_iw_get_index_interval(VALUE self)
1550
1516
  * Set the term_index_interval parameter
1551
1517
  */
1552
1518
  static VALUE
1553
- frb_iw_set_index_interval(VALUE self, VALUE rval)
1554
- {
1519
+ frb_iw_set_index_interval(VALUE self, VALUE rval) {
1555
1520
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1556
1521
  iw->config.index_interval = FIX2INT(rval);
1557
1522
  return rval;
@@ -1564,8 +1529,7 @@ frb_iw_set_index_interval(VALUE self, VALUE rval)
1564
1529
  * Return the current value of doc_skip_interval
1565
1530
  */
1566
1531
  static VALUE
1567
- frb_iw_get_skip_interval(VALUE self)
1568
- {
1532
+ frb_iw_get_skip_interval(VALUE self) {
1569
1533
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1570
1534
  return INT2FIX(iw->config.skip_interval);
1571
1535
  }
@@ -1577,8 +1541,7 @@ frb_iw_get_skip_interval(VALUE self)
1577
1541
  * Set the doc_skip_interval parameter
1578
1542
  */
1579
1543
  static VALUE
1580
- frb_iw_set_skip_interval(VALUE self, VALUE rval)
1581
- {
1544
+ frb_iw_set_skip_interval(VALUE self, VALUE rval) {
1582
1545
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1583
1546
  iw->config.skip_interval = FIX2INT(rval);
1584
1547
  return rval;
@@ -1591,8 +1554,7 @@ frb_iw_set_skip_interval(VALUE self, VALUE rval)
1591
1554
  * Return the current value of merge_factor
1592
1555
  */
1593
1556
  static VALUE
1594
- frb_iw_get_merge_factor(VALUE self)
1595
- {
1557
+ frb_iw_get_merge_factor(VALUE self) {
1596
1558
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1597
1559
  return INT2FIX(iw->config.merge_factor);
1598
1560
  }
@@ -1604,8 +1566,7 @@ frb_iw_get_merge_factor(VALUE self)
1604
1566
  * Set the merge_factor parameter
1605
1567
  */
1606
1568
  static VALUE
1607
- frb_iw_set_merge_factor(VALUE self, VALUE rval)
1608
- {
1569
+ frb_iw_set_merge_factor(VALUE self, VALUE rval) {
1609
1570
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1610
1571
  iw->config.merge_factor = FIX2INT(rval);
1611
1572
  return rval;
@@ -1618,8 +1579,7 @@ frb_iw_set_merge_factor(VALUE self, VALUE rval)
1618
1579
  * Return the current value of max_buffered_docs
1619
1580
  */
1620
1581
  static VALUE
1621
- frb_iw_get_max_buffered_docs(VALUE self)
1622
- {
1582
+ frb_iw_get_max_buffered_docs(VALUE self) {
1623
1583
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1624
1584
  return INT2FIX(iw->config.max_buffered_docs);
1625
1585
  }
@@ -1631,8 +1591,7 @@ frb_iw_get_max_buffered_docs(VALUE self)
1631
1591
  * Set the max_buffered_docs parameter
1632
1592
  */
1633
1593
  static VALUE
1634
- frb_iw_set_max_buffered_docs(VALUE self, VALUE rval)
1635
- {
1594
+ frb_iw_set_max_buffered_docs(VALUE self, VALUE rval) {
1636
1595
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1637
1596
  iw->config.max_buffered_docs = FIX2INT(rval);
1638
1597
  return rval;
@@ -1645,8 +1604,7 @@ frb_iw_set_max_buffered_docs(VALUE self, VALUE rval)
1645
1604
  * Return the current value of max_merge_docs
1646
1605
  */
1647
1606
  static VALUE
1648
- frb_iw_get_max_merge_docs(VALUE self)
1649
- {
1607
+ frb_iw_get_max_merge_docs(VALUE self) {
1650
1608
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1651
1609
  return INT2FIX(iw->config.max_merge_docs);
1652
1610
  }
@@ -1658,8 +1616,7 @@ frb_iw_get_max_merge_docs(VALUE self)
1658
1616
  * Set the max_merge_docs parameter
1659
1617
  */
1660
1618
  static VALUE
1661
- frb_iw_set_max_merge_docs(VALUE self, VALUE rval)
1662
- {
1619
+ frb_iw_set_max_merge_docs(VALUE self, VALUE rval) {
1663
1620
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1664
1621
  iw->config.max_merge_docs = FIX2INT(rval);
1665
1622
  return rval;
@@ -1672,8 +1629,7 @@ frb_iw_set_max_merge_docs(VALUE self, VALUE rval)
1672
1629
  * Return the current value of max_field_length
1673
1630
  */
1674
1631
  static VALUE
1675
- frb_iw_get_max_field_length(VALUE self)
1676
- {
1632
+ frb_iw_get_max_field_length(VALUE self) {
1677
1633
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1678
1634
  return INT2FIX(iw->config.max_field_length);
1679
1635
  }
@@ -1685,8 +1641,7 @@ frb_iw_get_max_field_length(VALUE self)
1685
1641
  * Set the max_field_length parameter
1686
1642
  */
1687
1643
  static VALUE
1688
- frb_iw_set_max_field_length(VALUE self, VALUE rval)
1689
- {
1644
+ frb_iw_set_max_field_length(VALUE self, VALUE rval) {
1690
1645
  FrtIndexWriter *iw = (FrtIndexWriter *)DATA_PTR(self);
1691
1646
  iw->config.max_field_length = FIX2INT(rval);
1692
1647
  return rval;
@@ -1766,6 +1721,7 @@ static VALUE frb_ir_init(VALUE self, VALUE rdir) {
1766
1721
  case T_STRING:
1767
1722
  frb_create_dir(rdir);
1768
1723
  store = frt_open_mdbx_store(rs2s(rdir));
1724
+ store->create_folder(store, segm_idx_name);
1769
1725
  break;
1770
1726
  default:
1771
1727
  FRT_RAISE(FRT_ARG_ERROR, "%s isn't a valid directory "
@@ -1787,6 +1743,7 @@ static VALUE frb_ir_init(VALUE self, VALUE rdir) {
1787
1743
  case T_STRING:
1788
1744
  frb_create_dir(rdir);
1789
1745
  store = frt_open_mdbx_store(rs2s(rdir));
1746
+ store->create_folder(store, segm_idx_name);
1790
1747
  break;
1791
1748
  default:
1792
1749
  FRT_RAISE(FRT_ARG_ERROR, "%s isn't a valid directory argument. "
@@ -1824,20 +1781,20 @@ static VALUE frb_ir_init(VALUE self, VALUE rdir) {
1824
1781
 
1825
1782
  /*
1826
1783
  * call-seq:
1827
- * index_reader.set_norm(doc_id, field, val)
1784
+ * index_reader.set_norm(doc_num, field, val)
1828
1785
  *
1829
- * Expert: change the boost value for a +field+ in document at +doc_id+.
1786
+ * Expert: change the boost value for a +field+ in document at +doc_num+.
1830
1787
  * +val+ should be an integer in the range 0..255 which corresponds to an
1831
1788
  * encoded float value.
1832
1789
  */
1833
1790
  static VALUE
1834
- frb_ir_set_norm(VALUE self, VALUE rdoc_id, VALUE rfield, VALUE rval) {
1791
+ frb_ir_set_norm(VALUE self, VALUE rdoc_num, VALUE rfield, VALUE rval) {
1835
1792
  int ex_code = 0;
1836
1793
  const char *msg = NULL;
1837
1794
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
1838
1795
 
1839
1796
  FRT_TRY
1840
- frt_ir_set_norm(ir, FIX2INT(rdoc_id), frb_field(rfield), (frt_uchar)NUM2CHR(rval));
1797
+ frt_ir_set_norm(ir, FIX2INT(rdoc_num), frb_field(rfield), (frt_uchar)NUM2CHR(rval));
1841
1798
  FRT_XCATCHALL
1842
1799
  ex_code = xcontext.excode;
1843
1800
  msg = xcontext.msg;
@@ -1860,13 +1817,12 @@ frb_ir_set_norm(VALUE self, VALUE rdoc_id, VALUE rfield, VALUE rval) {
1860
1817
  * could have null bytes.
1861
1818
  */
1862
1819
  static VALUE
1863
- frb_ir_norms(VALUE self, VALUE rfield)
1864
- {
1820
+ frb_ir_norms(VALUE self, VALUE rfield) {
1865
1821
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
1866
1822
  frt_uchar *norms;
1867
1823
  norms = frt_ir_get_norms(ir, frb_field(rfield));
1868
1824
  if (norms) {
1869
- return rb_str_new((char *)norms, ir->max_doc(ir));
1825
+ return rb_str_new((char *)norms, ir->max_doc_num(ir));
1870
1826
  } else {
1871
1827
  return Qnil;
1872
1828
  }
@@ -1879,17 +1835,16 @@ frb_ir_norms(VALUE self, VALUE rfield)
1879
1835
  * Expert: Get the norm values into a string +buffer+ starting at +offset+.
1880
1836
  */
1881
1837
  static VALUE
1882
- frb_ir_get_norms_into(VALUE self, VALUE rfield, VALUE rnorms, VALUE roffset)
1883
- {
1838
+ frb_ir_get_norms_into(VALUE self, VALUE rfield, VALUE rnorms, VALUE roffset) {
1884
1839
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
1885
1840
  int offset;
1886
1841
  offset = FIX2INT(roffset);
1887
1842
  Check_Type(rnorms, T_STRING);
1888
- if (RSTRING_LEN(rnorms) < offset + ir->max_doc(ir)) {
1843
+ if (RSTRING_LEN(rnorms) < offset + ir->max_doc_num(ir)) {
1889
1844
  rb_raise(rb_eArgError, "supplied a string of length:%ld to "
1890
1845
  "IndexReader#get_norms_into but needed a string of length "
1891
1846
  "offset:%d + maxdoc:%d",
1892
- RSTRING_LEN(rnorms), offset, ir->max_doc(ir));
1847
+ RSTRING_LEN(rnorms), offset, ir->max_doc_num(ir));
1893
1848
  }
1894
1849
 
1895
1850
  frt_ir_get_norms_into(ir, frb_field(rfield),
@@ -1935,8 +1890,7 @@ frb_ir_commit(VALUE self) {
1935
1890
  * errors.
1936
1891
  */
1937
1892
  static VALUE
1938
- frb_ir_close(VALUE self)
1939
- {
1893
+ frb_ir_close(VALUE self) {
1940
1894
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
1941
1895
  ((struct RData *)(self))->data = NULL;
1942
1896
  ((struct RData *)(self))->dmark = NULL;
@@ -1953,28 +1907,26 @@ frb_ir_close(VALUE self)
1953
1907
  * IndexReader or committed by any other IndexReader.
1954
1908
  */
1955
1909
  static VALUE
1956
- frb_ir_has_deletions(VALUE self)
1957
- {
1910
+ frb_ir_has_deletions(VALUE self) {
1958
1911
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
1959
1912
  return ir->has_deletions(ir) ? Qtrue : Qfalse;
1960
1913
  }
1961
1914
 
1962
- /*
1963
- * call-seq:
1964
- * index_reader.delete(doc_id) -> index_reader
1915
+ /* call-seq:
1916
+ * index_reader.delete(doc_num) -> index_reader
1965
1917
  *
1966
- * Delete document referenced internally by document id +doc_id+. The
1918
+ * Delete document referenced internally by document id +doc_num+. The
1967
1919
  * document_id is the number used to reference documents in the index and is
1968
1920
  * returned by search methods.
1969
1921
  */
1970
1922
  static VALUE
1971
- frb_ir_delete(VALUE self, VALUE rdoc_id) {
1923
+ frb_ir_delete(VALUE self, VALUE rdoc_num) {
1972
1924
  int ex_code = 0;
1973
1925
  const char *msg = NULL;
1974
1926
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
1975
1927
 
1976
1928
  FRT_TRY
1977
- frt_ir_delete_doc(ir, FIX2INT(rdoc_id));
1929
+ frt_ir_delete_doc(ir, FIX2INT(rdoc_num));
1978
1930
  FRT_XCATCHALL
1979
1931
  ex_code = xcontext.excode;
1980
1932
  msg = xcontext.msg;
@@ -1988,33 +1940,30 @@ frb_ir_delete(VALUE self, VALUE rdoc_id) {
1988
1940
  return self;
1989
1941
  }
1990
1942
 
1991
- /*
1992
- * call-seq:
1993
- * index_reader.deleted?(doc_id) -> bool
1943
+ /* call-seq:
1944
+ * index_reader.deleted?(doc_num) -> bool
1994
1945
  *
1995
- * Returns true if the document at +doc_id+ has been deleted.
1946
+ * Returns true if the document at +doc_num+ has been deleted.
1996
1947
  */
1997
1948
  static VALUE
1998
- frb_ir_is_deleted(VALUE self, VALUE rdoc_id)
1999
- {
1949
+ frb_ir_is_deleted(VALUE self, VALUE rdoc_num) {
2000
1950
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2001
- return ir->is_deleted(ir, FIX2INT(rdoc_id)) ? Qtrue : Qfalse;
1951
+ return ir->is_deleted(ir, FIX2INT(rdoc_num)) ? Qtrue : Qfalse;
2002
1952
  }
2003
1953
 
2004
- /*
2005
- * call-seq:
1954
+ /* call-seq:
2006
1955
  * index_reader.max_doc -> number
2007
1956
  *
2008
1957
  * Returns 1 + the maximum document id in the index. It is the
2009
1958
  * document_id that will be used by the next document added to the index. If
2010
1959
  * there are no deletions, this number also refers to the number of documents
2011
1960
  * in the index.
1961
+ * TODO: Rename to next_doc_num?
2012
1962
  */
2013
1963
  static VALUE
2014
- frb_ir_max_doc(VALUE self)
2015
- {
1964
+ frb_ir_max_doc_num(VALUE self) {
2016
1965
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2017
- return INT2FIX(ir->max_doc(ir));
1966
+ return INT2FIX(ir->max_doc_num(ir));
2018
1967
  }
2019
1968
 
2020
1969
  /*
@@ -2026,8 +1975,7 @@ frb_ir_max_doc(VALUE self)
2026
1975
  * deleted from the index.
2027
1976
  */
2028
1977
  static VALUE
2029
- frb_ir_num_docs(VALUE self)
2030
- {
1978
+ frb_ir_num_docs(VALUE self) {
2031
1979
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2032
1980
  return INT2FIX(ir->num_docs(ir));
2033
1981
  }
@@ -2042,31 +1990,43 @@ frb_ir_num_docs(VALUE self)
2042
1990
  * effect on these documents.
2043
1991
  */
2044
1992
  static VALUE
2045
- frb_ir_undelete_all(VALUE self)
2046
- {
1993
+ frb_ir_undelete_all(VALUE self) {
2047
1994
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2048
1995
  frt_ir_undelete_all(ir);
2049
1996
  return self;
2050
1997
  }
2051
1998
 
2052
1999
  static VALUE
2053
- frb_get_doc_range(FrtIndexReader *ir, int pos, int len, int max)
2054
- {
2000
+ frb_get_doc_range(FrtIndexReader *ir, int pos, int len, int max) {
2001
+ int ex_code = 0;
2002
+ const char *msg = NULL;
2055
2003
  VALUE ary;
2056
2004
  int i;
2057
2005
  max = FRT_MIN(max, pos+len);
2058
2006
  len = max - pos;
2059
2007
  ary = rb_ary_new2(len);
2060
- for (i = 0; i < len; i++) {
2061
- rb_ary_store(ary, i, frb_get_lazy_doc(ir->get_lazy_doc(ir, i + pos)));
2008
+
2009
+ FRT_TRY
2010
+ for (i = 0; i < len; i++) {
2011
+ rb_ary_store(ary, i, frb_get_lazy_doc(ir->get_lazy_doc(ir, i + pos)));
2012
+ }
2013
+ FRT_XCATCHALL
2014
+ ex_code = xcontext.excode;
2015
+ msg = xcontext.msg;
2016
+ FRT_HANDLED();
2017
+ FRT_XENDTRY
2018
+
2019
+ if (ex_code && msg) {
2020
+ frb_raise(ex_code, msg);
2062
2021
  }
2022
+
2063
2023
  return ary;
2064
2024
  }
2065
2025
 
2066
2026
  /*
2067
2027
  * call-seq:
2068
- * index_reader.get_document(doc_id) -> LazyDoc
2069
- * index_reader[doc_id] -> LazyDoc
2028
+ * index_reader.get_document(doc_num) -> LazyDoc
2029
+ * index_reader[doc_num] -> LazyDoc
2070
2030
  *
2071
2031
  * Retrieve a document from the index. See LazyDoc for more details on the
2072
2032
  * document returned. Documents are referenced internally by document ids
@@ -2077,7 +2037,7 @@ frb_ir_get_doc(int argc, VALUE *argv, VALUE self) {
2077
2037
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2078
2038
  VALUE arg1, arg2;
2079
2039
  long pos, len;
2080
- long max = ir->max_doc(ir);
2040
+ long max = ir->max_doc_num(ir);
2081
2041
  rb_scan_args(argc, argv, "11", &arg1, &arg2);
2082
2042
  if (argc == 1) {
2083
2043
  if (FIXNUM_P(arg1)) {
@@ -2087,7 +2047,24 @@ frb_ir_get_doc(int argc, VALUE *argv, VALUE self) {
2087
2047
  rb_raise(rb_eArgError, "index %ld is out of range [%d..%ld] for "
2088
2048
  "IndexReader#[]", pos, 0, max);
2089
2049
  }
2090
- return frb_get_lazy_doc(ir->get_lazy_doc(ir, pos));
2050
+
2051
+ int ex_code = 0;
2052
+ const char *msg = NULL;
2053
+ VALUE ld = Qnil;
2054
+
2055
+ FRT_TRY
2056
+ ld = frb_get_lazy_doc(ir->get_lazy_doc(ir, pos));
2057
+ FRT_XCATCHALL
2058
+ ex_code = xcontext.excode;
2059
+ msg = xcontext.msg;
2060
+ FRT_HANDLED();
2061
+ FRT_XENDTRY
2062
+
2063
+ if (ex_code && msg) {
2064
+ frb_raise(ex_code, msg);
2065
+ }
2066
+
2067
+ return ld;
2091
2068
  }
2092
2069
 
2093
2070
  /* check if idx is Range */
@@ -2118,55 +2095,48 @@ frb_ir_get_doc(int argc, VALUE *argv, VALUE self) {
2118
2095
  * index to search the latest documents added to the index.
2119
2096
  */
2120
2097
  static VALUE
2121
- frb_ir_is_latest(VALUE self)
2122
- {
2098
+ frb_ir_is_latest(VALUE self) {
2123
2099
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2124
2100
  return frt_ir_is_latest(ir) ? Qtrue : Qfalse;
2125
2101
  }
2126
2102
 
2127
- /*
2128
- * call-seq:
2129
- * index_reader.term_vector(doc_id, field) -> TermVector
2103
+ /* call-seq:
2104
+ * index_reader.term_vector(doc_num, field) -> TermVector
2130
2105
  *
2131
- * Return the TermVector for the field +field+ in the document at +doc_id+ in
2106
+ * Return the TermVector for the field +field+ in the document at +doc_num+ in
2132
2107
  * the index. Return nil if no such term_vector exists. See TermVector.
2133
2108
  */
2134
2109
  static VALUE
2135
- frb_ir_term_vector(VALUE self, VALUE rdoc_id, VALUE rfield)
2136
- {
2110
+ frb_ir_term_vector(VALUE self, VALUE rdoc_num, VALUE rfield) {
2137
2111
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2138
2112
  FrtTermVector *tv;
2139
2113
  VALUE rtv;
2140
- tv = ir->term_vector(ir, FIX2INT(rdoc_id), frb_field(rfield));
2114
+ tv = ir->term_vector(ir, FIX2INT(rdoc_num), frb_field(rfield));
2141
2115
  if (tv) {
2142
2116
  rtv = frb_get_tv(tv);
2143
2117
  frt_tv_destroy(tv);
2144
2118
  return rtv;
2145
- }
2146
- else {
2119
+ } else {
2147
2120
  return Qnil;
2148
2121
  }
2149
2122
  }
2150
2123
 
2151
2124
  static void
2152
- frb_add_each_tv(void *key, void *value, void *rtvs)
2153
- {
2125
+ frb_add_each_tv(void *key, void *value, void *rtvs) {
2154
2126
  rb_hash_aset((VALUE)rtvs, ID2SYM((ID)key), frb_get_tv(value));
2155
2127
  }
2156
2128
 
2157
- /*
2158
- * call-seq:
2159
- * index_reader.term_vectors(doc_id) -> hash of TermVector
2129
+ /* call-seq:
2130
+ * index_reader.term_vectors(doc_num) -> hash of TermVector
2160
2131
  *
2161
- * Return the TermVectors for the document at +doc_id+ in the index. The
2132
+ * Return the TermVectors for the document at +doc_num+ in the index. The
2162
2133
  * value returned is a hash of the TermVectors for each field in the document
2163
2134
  * and they are referenced by field names (as symbols).
2164
2135
  */
2165
2136
  static VALUE
2166
- frb_ir_term_vectors(VALUE self, VALUE rdoc_id)
2167
- {
2137
+ frb_ir_term_vectors(VALUE self, VALUE rdoc_num) {
2168
2138
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2169
- FrtHash *tvs = ir->term_vectors(ir, FIX2INT(rdoc_id));
2139
+ FrtHash *tvs = ir->term_vectors(ir, FIX2INT(rdoc_num));
2170
2140
  VALUE rtvs = rb_hash_new();
2171
2141
  frt_h_each(tvs, &frb_add_each_tv, (void *)rtvs);
2172
2142
  frt_h_destroy(tvs);
@@ -2182,8 +2152,7 @@ frb_ir_term_vectors(VALUE self, VALUE rdoc_id)
2182
2152
  * See TermDocEnum for more info.
2183
2153
  */
2184
2154
  static VALUE
2185
- frb_ir_term_docs(VALUE self)
2186
- {
2155
+ frb_ir_term_docs(VALUE self) {
2187
2156
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2188
2157
  return frb_get_tde(self, ir->term_docs(ir));
2189
2158
  }
@@ -2196,8 +2165,7 @@ frb_ir_term_docs(VALUE self)
2196
2165
  * term +term+ in the field +field+. See TermDocEnum for more info.
2197
2166
  */
2198
2167
  static VALUE
2199
- frb_ir_term_docs_for(VALUE self, VALUE rfield, VALUE rterm)
2200
- {
2168
+ frb_ir_term_docs_for(VALUE self, VALUE rfield, VALUE rterm) {
2201
2169
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2202
2170
  return frb_get_tde(self, ir_term_docs_for(ir,
2203
2171
  frb_field(rfield),
@@ -2213,8 +2181,7 @@ frb_ir_term_docs_for(VALUE self, VALUE rfield, VALUE rterm)
2213
2181
  * more info.
2214
2182
  */
2215
2183
  static VALUE
2216
- frb_ir_term_positions(VALUE self)
2217
- {
2184
+ frb_ir_term_positions(VALUE self) {
2218
2185
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2219
2186
  return frb_get_tde(self, ir->term_positions(ir));
2220
2187
  }
@@ -2228,8 +2195,7 @@ frb_ir_term_positions(VALUE self)
2228
2195
  * TermDocEnum for more info.
2229
2196
  */
2230
2197
  static VALUE
2231
- frb_ir_t_pos_for(VALUE self, VALUE rfield, VALUE rterm)
2232
- {
2198
+ frb_ir_t_pos_for(VALUE self, VALUE rfield, VALUE rterm) {
2233
2199
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2234
2200
  return frb_get_tde(self, frt_ir_term_positions_for(ir,
2235
2201
  frb_field(rfield),
@@ -2244,8 +2210,7 @@ frb_ir_t_pos_for(VALUE self, VALUE rfield, VALUE rterm)
2244
2210
  * field +field+.
2245
2211
  */
2246
2212
  static VALUE
2247
- frb_ir_doc_freq(VALUE self, VALUE rfield, VALUE rterm)
2248
- {
2213
+ frb_ir_doc_freq(VALUE self, VALUE rfield, VALUE rterm) {
2249
2214
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2250
2215
  return INT2FIX(frt_ir_doc_freq(ir,
2251
2216
  frb_field(rfield),
@@ -2260,8 +2225,7 @@ frb_ir_doc_freq(VALUE self, VALUE rfield, VALUE rterm)
2260
2225
  * terms in the field +field+ in the index.
2261
2226
  */
2262
2227
  static VALUE
2263
- frb_ir_terms(VALUE self, VALUE rfield)
2264
- {
2228
+ frb_ir_terms(VALUE self, VALUE rfield) {
2265
2229
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2266
2230
  return frb_get_te(self, frt_ir_terms(ir, frb_field(rfield)));
2267
2231
  }
@@ -2274,8 +2238,7 @@ frb_ir_terms(VALUE self, VALUE rfield)
2274
2238
  * at term +term+.
2275
2239
  */
2276
2240
  static VALUE
2277
- frb_ir_terms_from(VALUE self, VALUE rfield, VALUE rterm)
2278
- {
2241
+ frb_ir_terms_from(VALUE self, VALUE rfield, VALUE rterm) {
2279
2242
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2280
2243
  return frb_get_te(self, frt_ir_terms_from(ir,
2281
2244
  frb_field(rfield),
@@ -2289,8 +2252,7 @@ frb_ir_terms_from(VALUE self, VALUE rfield, VALUE rterm)
2289
2252
  * Same return a count of the number of terms in the field
2290
2253
  */
2291
2254
  static VALUE
2292
- frb_ir_term_count(VALUE self, VALUE rfield)
2293
- {
2255
+ frb_ir_term_count(VALUE self, VALUE rfield) {
2294
2256
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2295
2257
  FrtTermEnum *te = frt_ir_terms(ir, frb_field(rfield));
2296
2258
  int count = 0;
@@ -2311,8 +2273,7 @@ frb_ir_term_count(VALUE self, VALUE rfield)
2311
2273
  * gathered from the FieldInfos object.
2312
2274
  */
2313
2275
  static VALUE
2314
- frb_ir_fields(VALUE self)
2315
- {
2276
+ frb_ir_fields(VALUE self) {
2316
2277
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2317
2278
  FrtFieldInfos *fis = ir->fis;
2318
2279
  VALUE rfield_names = rb_ary_new();
@@ -2345,8 +2306,7 @@ static VALUE frb_ir_field_infos(VALUE self) {
2345
2306
  * of field names can also be gathered from the FieldInfos object.
2346
2307
  */
2347
2308
  static VALUE
2348
- frb_ir_tk_fields(VALUE self)
2349
- {
2309
+ frb_ir_tk_fields(VALUE self) {
2350
2310
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2351
2311
  FrtFieldInfos *fis = ir->fis;
2352
2312
  VALUE rfield_names = rb_ary_new();
@@ -2377,14 +2337,28 @@ static VALUE frb_ir_to_enum(VALUE self) {
2377
2337
  static VALUE frb_ir_each(VALUE self) {
2378
2338
  FrtIndexReader *ir = (FrtIndexReader *)DATA_PTR(self);
2379
2339
  if (rb_block_given_p()) {
2340
+ int ex_code = 0;
2341
+ const char *msg = NULL;
2380
2342
  long i;
2381
- long max_doc = ir->max_doc(ir);
2343
+ int max_doc_num = ir->max_doc_num(ir);
2382
2344
  VALUE rld;
2383
- for (i = 0; i < max_doc; i++) {
2384
- if (ir->is_deleted(ir, i)) continue;
2385
- rld = frb_get_lazy_doc(ir->get_lazy_doc(ir, i));
2386
- rb_yield(rld);
2345
+
2346
+ FRT_TRY
2347
+ for (i = 0; i < max_doc_num; i++) {
2348
+ if (ir->is_deleted(ir, i)) continue;
2349
+ rld = frb_get_lazy_doc(ir->get_lazy_doc(ir, i));
2350
+ rb_yield(rld);
2351
+ }
2352
+ FRT_XCATCHALL
2353
+ ex_code = xcontext.excode;
2354
+ msg = xcontext.msg;
2355
+ FRT_HANDLED();
2356
+ FRT_XENDTRY
2357
+
2358
+ if (ex_code && msg) {
2359
+ frb_raise(ex_code, msg);
2387
2360
  }
2361
+
2388
2362
  return self;
2389
2363
  } else {
2390
2364
  return frb_ir_to_enum(self);
@@ -2511,8 +2485,8 @@ Init_TermEnum(void) {
2511
2485
  *
2512
2486
  * tde = index_reader.term_docs_for(:content, "fox")
2513
2487
  *
2514
- * tde.each do |doc_id, freq|
2515
- * puts "fox appeared #{freq} times in document #{doc_id}:"
2488
+ * tde.each do |doc_num, freq|
2489
+ * puts "fox appeared #{freq} times in document #{doc_num}:"
2516
2490
  * positions = []
2517
2491
  * tde.each_position {|pos| positions << pos}
2518
2492
  * puts " #{positions.join(', ')}"
@@ -2537,7 +2511,7 @@ static void Init_TermDocEnum(void) {
2537
2511
  rb_define_alloc_func(cTermDocEnum, frb_tde_alloc);
2538
2512
  rb_define_method(cTermDocEnum, "seek", frb_tde_seek, 2);
2539
2513
  rb_define_method(cTermDocEnum, "seek_term_enum", frb_tde_seek_te, 1);
2540
- rb_define_method(cTermDocEnum, "doc", frb_tde_doc, 0);
2514
+ rb_define_method(cTermDocEnum, "doc_num", frb_tde_doc_num, 0);
2541
2515
  rb_define_method(cTermDocEnum, "freq", frb_tde_freq, 0);
2542
2516
  rb_define_method(cTermDocEnum, "next?", frb_tde_next, 0);
2543
2517
  rb_define_method(cTermDocEnum, "next_position", frb_tde_next_position, 0);
@@ -2606,7 +2580,7 @@ static void Init_TVTerm(void) {
2606
2580
  *
2607
2581
  * == Example
2608
2582
  *
2609
- * tv = index_reader.term_vector(doc_id, :content)
2583
+ * tv = index_reader.term_vector(doc_num, :content)
2610
2584
  * tv_term = tv.find {|tvt| tvt.term == "fox"}
2611
2585
  *
2612
2586
  * # get the term frequency
@@ -2832,7 +2806,7 @@ void Init_IndexReader(void) {
2832
2806
  rb_define_method(cIndexReader, "has_deletions?", frb_ir_has_deletions, 0);
2833
2807
  rb_define_method(cIndexReader, "delete", frb_ir_delete, 1);
2834
2808
  rb_define_method(cIndexReader, "deleted?", frb_ir_is_deleted, 1);
2835
- rb_define_method(cIndexReader, "max_doc", frb_ir_max_doc, 0);
2809
+ rb_define_method(cIndexReader, "max_doc_num", frb_ir_max_doc_num, 0);
2836
2810
  rb_define_method(cIndexReader, "num_docs", frb_ir_num_docs, 0);
2837
2811
  rb_define_method(cIndexReader, "undelete_all", frb_ir_undelete_all, 0);
2838
2812
  rb_define_method(cIndexReader, "latest?", frb_ir_is_latest, 0);