isomorfeus-ferret 0.13.7 → 0.13.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -4
  3. data/ext/isomorfeus_ferret_ext/bm_store.c +3 -3
  4. data/ext/isomorfeus_ferret_ext/frb_analysis.c +7 -4
  5. data/ext/isomorfeus_ferret_ext/frb_index.c +18 -24
  6. data/ext/isomorfeus_ferret_ext/frb_qparser.c +2 -1
  7. data/ext/isomorfeus_ferret_ext/frb_search.c +23 -19
  8. data/ext/isomorfeus_ferret_ext/frb_store.c +34 -36
  9. data/ext/isomorfeus_ferret_ext/frt_analysis.c +4 -4
  10. data/ext/isomorfeus_ferret_ext/frt_analysis.h +9 -9
  11. data/ext/isomorfeus_ferret_ext/frt_bitvector.c +1 -1
  12. data/ext/isomorfeus_ferret_ext/frt_bitvector.h +1 -1
  13. data/ext/isomorfeus_ferret_ext/frt_compound_io.c +41 -66
  14. data/ext/isomorfeus_ferret_ext/frt_config.h +8 -0
  15. data/ext/isomorfeus_ferret_ext/frt_except.c +1 -0
  16. data/ext/isomorfeus_ferret_ext/frt_field_index.c +1 -1
  17. data/ext/isomorfeus_ferret_ext/frt_filter.c +2 -4
  18. data/ext/isomorfeus_ferret_ext/frt_fs_store.c +24 -19
  19. data/ext/isomorfeus_ferret_ext/frt_global.c +6 -4
  20. data/ext/isomorfeus_ferret_ext/frt_global.h +1 -1
  21. data/ext/isomorfeus_ferret_ext/frt_hash.c +40 -48
  22. data/ext/isomorfeus_ferret_ext/frt_hash.h +14 -16
  23. data/ext/isomorfeus_ferret_ext/frt_ind.c +3 -4
  24. data/ext/isomorfeus_ferret_ext/frt_index.c +152 -222
  25. data/ext/isomorfeus_ferret_ext/frt_index.h +31 -31
  26. data/ext/isomorfeus_ferret_ext/frt_lang.c +1 -4
  27. data/ext/isomorfeus_ferret_ext/frt_multimapper.c +8 -9
  28. data/ext/isomorfeus_ferret_ext/frt_multimapper.h +1 -1
  29. data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +7 -7
  30. data/ext/isomorfeus_ferret_ext/frt_q_fuzzy.c +1 -1
  31. data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +8 -3
  32. data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +2 -2
  33. data/ext/isomorfeus_ferret_ext/frt_q_parser.c +1742 -1742
  34. data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +2 -3
  35. data/ext/isomorfeus_ferret_ext/frt_q_prefix.c +1 -1
  36. data/ext/isomorfeus_ferret_ext/frt_q_range.c +1 -1
  37. data/ext/isomorfeus_ferret_ext/frt_q_span.c +12 -11
  38. data/ext/isomorfeus_ferret_ext/frt_q_term.c +2 -2
  39. data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +1 -1
  40. data/ext/isomorfeus_ferret_ext/frt_ram_store.c +24 -40
  41. data/ext/isomorfeus_ferret_ext/frt_search.c +30 -29
  42. data/ext/isomorfeus_ferret_ext/frt_search.h +18 -19
  43. data/ext/isomorfeus_ferret_ext/frt_sort.c +1 -1
  44. data/ext/isomorfeus_ferret_ext/frt_store.c +47 -40
  45. data/ext/isomorfeus_ferret_ext/frt_store.h +45 -47
  46. data/ext/isomorfeus_ferret_ext/frt_threading.h +12 -5
  47. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +4 -3
  48. data/ext/isomorfeus_ferret_ext/test_1710.c +1 -2
  49. data/ext/isomorfeus_ferret_ext/test_compound_io.c +8 -8
  50. data/ext/isomorfeus_ferret_ext/test_fields.c +7 -7
  51. data/ext/isomorfeus_ferret_ext/test_file_deleter.c +1 -1
  52. data/ext/isomorfeus_ferret_ext/test_filter.c +5 -4
  53. data/ext/isomorfeus_ferret_ext/test_fs_store.c +1 -1
  54. data/ext/isomorfeus_ferret_ext/test_highlighter.c +4 -2
  55. data/ext/isomorfeus_ferret_ext/test_index.c +63 -63
  56. data/ext/isomorfeus_ferret_ext/test_q_const_score.c +3 -2
  57. data/ext/isomorfeus_ferret_ext/test_q_filtered.c +4 -3
  58. data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +4 -2
  59. data/ext/isomorfeus_ferret_ext/test_q_span.c +9 -2
  60. data/ext/isomorfeus_ferret_ext/test_ram_store.c +4 -4
  61. data/ext/isomorfeus_ferret_ext/test_search.c +10 -5
  62. data/ext/isomorfeus_ferret_ext/test_segments.c +4 -3
  63. data/ext/isomorfeus_ferret_ext/test_sort.c +18 -10
  64. data/ext/isomorfeus_ferret_ext/test_store.c +1 -1
  65. data/ext/isomorfeus_ferret_ext/test_term.c +5 -3
  66. data/ext/isomorfeus_ferret_ext/test_term_vectors.c +2 -2
  67. data/ext/isomorfeus_ferret_ext/test_threading.c +5 -4
  68. data/lib/isomorfeus/ferret/index/index.rb +8 -3
  69. data/lib/isomorfeus/ferret/version.rb +1 -1
  70. metadata +16 -2
@@ -4,7 +4,7 @@
4
4
  #include "frt_search.h"
5
5
  #include "frt_array.h"
6
6
 
7
- #undef close
7
+ // #undef close
8
8
 
9
9
  #define PhQ(query) ((FrtPhraseQuery *)(query))
10
10
 
@@ -27,7 +27,6 @@ static int phrase_pos_cmp(const void *p1, const void *p2) {
27
27
  return strcmp(((FrtPhrasePosition *)p1)->terms[0], ((FrtPhrasePosition *)p2)->terms[0]);
28
28
  }
29
29
 
30
-
31
30
  /***************************************************************************
32
31
  *
33
32
  * PhraseScorer
@@ -1061,7 +1060,7 @@ static FrtQuery *phq_rewrite(FrtQuery *self, FrtIndexReader *ir)
1061
1060
  return q;
1062
1061
  }
1063
1062
  } else {
1064
- self->ref_cnt++;
1063
+ FRT_REF(self);
1065
1064
  return self;
1066
1065
  }
1067
1066
  }
@@ -2,7 +2,7 @@
2
2
  #include "frt_global.h"
3
3
  #include "frt_search.h"
4
4
 
5
- #undef close
5
+ // #undef close
6
6
 
7
7
  /****************************************************************************
8
8
  *
@@ -2,7 +2,7 @@
2
2
  #include "frt_global.h"
3
3
  #include "frt_search.h"
4
4
 
5
- #undef close
5
+ // #undef close
6
6
 
7
7
  /*****************************************************************************
8
8
  *
@@ -4,7 +4,7 @@
4
4
  #include "frt_search.h"
5
5
  #include "frt_hashset.h"
6
6
 
7
- #undef close
7
+ // #undef close
8
8
 
9
9
  #define CLAUSE_INIT_CAPA 4
10
10
 
@@ -66,11 +66,11 @@ static FrtMatchVector *mv_to_term_mv(FrtMatchVector *term_mv, FrtMatchVector *fu
66
66
  typedef struct TVTermDocEnum
67
67
  {
68
68
  FrtTermDocEnum super;
69
- int doc;
70
- int index;
71
- int freq;
72
- int *positions;
73
- FrtTermVector *tv;
69
+ int doc;
70
+ int index;
71
+ int freq;
72
+ int *positions;
73
+ FrtTermVector *tv;
74
74
  } TVTermDocEnum;
75
75
 
76
76
  static void tv_tde_seek(FrtTermDocEnum *tde, int field_num, const char *term)
@@ -131,7 +131,7 @@ static int tv_tde_doc_num(FrtTermDocEnum *tde)
131
131
  static FrtTermDocEnum *spanq_ir_term_positions(FrtIndexReader *ir)
132
132
  {
133
133
  TVTermDocEnum *tv_tde = FRT_ALLOC(TVTermDocEnum);
134
- FrtTermDocEnum *tde = (FrtTermDocEnum *)tv_tde;
134
+ FrtTermDocEnum *tde = (FrtTermDocEnum *)tv_tde;
135
135
  tv_tde->tv = (FrtTermVector *)ir->store;
136
136
  tde->seek = &tv_tde_seek;
137
137
  tde->doc_num = &tv_tde_doc_num;
@@ -154,6 +154,7 @@ static FrtMatchVector *spanq_get_matchv_i(FrtQuery *self, FrtMatchVector *mv, Fr
154
154
  ir->fis = frt_fis_new(FRT_STORE_NO, FRT_COMPRESSION_NONE, FRT_INDEX_NO, FRT_TERM_VECTOR_NO);
155
155
  frt_fis_add_field(ir->fis, frt_fi_new(tv->field, FRT_STORE_NO, FRT_COMPRESSION_NONE, FRT_INDEX_NO, FRT_TERM_VECTOR_NO));
156
156
  ir->store = (FrtStore *)tv;
157
+ FRT_REF((FrtStore *)tv);
157
158
  ir->term_positions = &spanq_ir_term_positions;
158
159
  sp_enum = SpQ(self)->get_spans(self, ir);
159
160
  while (sp_enum->next(sp_enum)) {
@@ -1727,7 +1728,7 @@ static FrtQuery *spanfq_rewrite(FrtQuery *self, FrtIndexReader *ir) {
1727
1728
  frt_q_deref(q);
1728
1729
  SpFQ(self)->match = rq;
1729
1730
 
1730
- self->ref_cnt++;
1731
+ FRT_REF(self);
1731
1732
  return self; /* no clauses rewrote */
1732
1733
  }
1733
1734
 
@@ -1864,7 +1865,7 @@ static FrtQuery *spanoq_rewrite(FrtQuery *self, FrtIndexReader *ir) {
1864
1865
  soq->clauses[i] = rewritten;
1865
1866
  }
1866
1867
 
1867
- self->ref_cnt++;
1868
+ FRT_REF(self);
1868
1869
  return self;
1869
1870
  }
1870
1871
 
@@ -2050,7 +2051,7 @@ static FrtQuery *spannq_rewrite(FrtQuery *self, FrtIndexReader *ir)
2050
2051
  snq->clauses[i] = rewritten;
2051
2052
  }
2052
2053
 
2053
- self->ref_cnt++;
2054
+ FRT_REF(self);
2054
2055
  return self;
2055
2056
  }
2056
2057
 
@@ -2207,7 +2208,7 @@ static FrtQuery *spanxq_rewrite(FrtQuery *self, FrtIndexReader *ir) {
2207
2208
  frt_q_deref(q);
2208
2209
  sxq->exc = rq;
2209
2210
 
2210
- self->ref_cnt++;
2211
+ FRT_REF(self);
2211
2212
  return self;
2212
2213
  }
2213
2214
 
@@ -2,8 +2,8 @@
2
2
  #include <string.h>
3
3
  #include "frt_search.h"
4
4
 
5
- #undef close
6
- #undef read
5
+ // #undef close
6
+ // #undef read
7
7
 
8
8
  #define TQ(query) ((FrtTermQuery *)(query))
9
9
  #define TSc(scorer) ((TermScorer *)(scorer))
@@ -2,7 +2,7 @@
2
2
  #include "frt_global.h"
3
3
  #include "frt_search.h"
4
4
 
5
- #undef close
5
+ // #undef close
6
6
 
7
7
  /****************************************************************************
8
8
  *
@@ -20,17 +20,16 @@ static void rf_extend_if_necessary(FrtRAMFile *rf, int buf_num) {
20
20
  }
21
21
 
22
22
  static void rf_close(void *p) {
23
- int i;
24
23
  FrtRAMFile *rf = (FrtRAMFile *)p;
25
- if (rf->ref_cnt > 0) {
26
- return;
27
- }
28
- free(rf->name);
29
- for (i = 0; i < rf->bufcnt; i++) {
30
- free(rf->buffers[i]);
24
+ if (FRT_DEREF(rf) == 0) {
25
+ int i;
26
+ free(rf->name);
27
+ for (i = 0; i < rf->bufcnt; i++) {
28
+ free(rf->buffers[i]);
29
+ }
30
+ free(rf->buffers);
31
+ free(rf);
31
32
  }
32
- free(rf->buffers);
33
- free(rf);
34
33
  }
35
34
 
36
35
  static void ram_touch(FrtStore *store, const char *filename) {
@@ -50,7 +49,6 @@ static int ram_exists(FrtStore *store, const char *filename) {
50
49
  static int ram_remove(FrtStore *store, const char *filename) {
51
50
  FrtRAMFile *rf = (FrtRAMFile *)frt_h_rem(store->dir.ht, filename, false);
52
51
  if (rf != NULL) {
53
- FRT_DEREF(rf);
54
52
  rf_close(rf);
55
53
  return true;
56
54
  } else {
@@ -74,7 +72,7 @@ static void ram_rename(FrtStore *store, const char *from, const char *to) {
74
72
  /* clean up the file we are overwriting */
75
73
  tmp = (FrtRAMFile *)frt_h_get(store->dir.ht, to);
76
74
  if (tmp != NULL) {
77
- FRT_DEREF(tmp);
75
+ frt_h_del(store->dir.ht, to);
78
76
  }
79
77
 
80
78
  frt_h_set(store->dir.ht, rf->name, rf);
@@ -99,16 +97,7 @@ static void ram_each(FrtStore *store, void (*func)(const char *fname, void *arg)
99
97
  }
100
98
 
101
99
  static void ram_close_i(FrtStore *store) {
102
- FrtHash *ht = store->dir.ht;
103
- int i;
104
- for (i = 0; i <= ht->mask; i++) {
105
- FrtRAMFile *rf = (FrtRAMFile *)ht->table[i].value;
106
- if (rf) {
107
- FRT_DEREF(rf);
108
- }
109
- }
110
100
  frt_h_destroy(store->dir.ht);
111
- frt_store_destroy(store);
112
101
  }
113
102
 
114
103
  /*
@@ -120,7 +109,6 @@ static void ram_clear(FrtStore *store) {
120
109
  for (i = 0; i <= ht->mask; i++) {
121
110
  FrtRAMFile *rf = (FrtRAMFile *)ht->table[i].value;
122
111
  if (rf && !frt_file_is_lock(rf->name)) {
123
- FRT_DEREF(rf);
124
112
  frt_h_del(ht, rf->name);
125
113
  }
126
114
  }
@@ -132,7 +120,6 @@ static void ram_clear_locks(FrtStore *store) {
132
120
  for (i = 0; i <= ht->mask; i++) {
133
121
  FrtRAMFile *rf = (FrtRAMFile *)ht->table[i].value;
134
122
  if (rf && frt_file_is_lock(rf->name)) {
135
- FRT_DEREF(rf);
136
123
  frt_h_del(ht, rf->name);
137
124
  }
138
125
  }
@@ -144,13 +131,12 @@ static void ram_clear_all(FrtStore *store) {
144
131
  for (i = 0; i <= ht->mask; i++) {
145
132
  FrtRAMFile *rf = (FrtRAMFile *)ht->table[i].value;
146
133
  if (rf) {
147
- FRT_DEREF(rf);
148
134
  frt_h_del(ht, rf->name);
149
135
  }
150
136
  }
151
137
  }
152
138
 
153
- static off_t ram_length(FrtStore *store, const char *filename) {
139
+ static frt_off_t ram_length(FrtStore *store, const char *filename) {
154
140
  FrtRAMFile *rf = (FrtRAMFile *)frt_h_get(store->dir.ht, filename);
155
141
  if (rf != NULL) {
156
142
  return rf->len;
@@ -165,7 +151,7 @@ static void ramo_flush_i(FrtOutStream *os, const frt_uchar *src, int len) {
165
151
  FrtRAMFile *rf = os->file.rf;
166
152
  int buffer_number, buffer_offset, bytes_in_buffer, bytes_to_copy;
167
153
  int src_offset;
168
- off_t pointer = os->pointer;
154
+ frt_off_t pointer = os->pointer;
169
155
 
170
156
  buffer_number = (int)(pointer / FRT_BUFFER_SIZE);
171
157
  buffer_offset = pointer % FRT_BUFFER_SIZE;
@@ -193,7 +179,7 @@ static void ramo_flush_i(FrtOutStream *os, const frt_uchar *src, int len) {
193
179
  }
194
180
  }
195
181
 
196
- static void ramo_seek_i(FrtOutStream *os, off_t pos) {
182
+ static void ramo_seek_i(FrtOutStream *os, frt_off_t pos) {
197
183
  os->pointer = pos;
198
184
  }
199
185
 
@@ -203,9 +189,7 @@ void frt_ramo_reset(FrtOutStream *os) {
203
189
  }
204
190
 
205
191
  static void ramo_close_i(FrtOutStream *os) {
206
- FrtRAMFile *rf = os->file.rf;
207
- FRT_DEREF(rf);
208
- rf_close(rf);
192
+ rf_close(os->file.rf);
209
193
  }
210
194
 
211
195
  void frt_ramo_write_to(FrtOutStream *os, FrtOutStream *other_o) {
@@ -232,8 +216,6 @@ static const struct FrtOutStreamMethods RAM_OUT_STREAM_METHODS = {
232
216
  FrtOutStream *frt_ram_new_buffer(void) {
233
217
  FrtRAMFile *rf = rf_new("");
234
218
  FrtOutStream *os = frt_os_new();
235
-
236
- FRT_DEREF(rf);
237
219
  os->file.rf = rf;
238
220
  os->pointer = 0;
239
221
  os->m = &RAM_OUT_STREAM_METHODS;
@@ -261,12 +243,12 @@ static FrtOutStream *ram_new_output(FrtStore *store, const char *filename) {
261
243
  }
262
244
 
263
245
  static void rami_read_i(FrtInStream *is, frt_uchar *b, int len) {
264
- FrtRAMFile *rf = is->file.rf;
246
+ FrtRAMFile *rf = is->f->file.rf;
265
247
 
266
248
  int offset = 0;
267
249
  int buffer_number, buffer_offset, bytes_in_buffer, bytes_to_copy;
268
250
  int remainder = len;
269
- off_t start = is->d.pointer;
251
+ frt_off_t start = is->d.pointer;
270
252
  frt_uchar *buffer;
271
253
 
272
254
  while (remainder > 0) {
@@ -289,17 +271,16 @@ static void rami_read_i(FrtInStream *is, frt_uchar *b, int len) {
289
271
  is->d.pointer += len;
290
272
  }
291
273
 
292
- static off_t rami_length_i(FrtInStream *is) {
293
- return is->file.rf->len;
274
+ static frt_off_t rami_length_i(FrtInStream *is) {
275
+ return is->f->file.rf->len;
294
276
  }
295
277
 
296
- static void rami_seek_i(FrtInStream *is, off_t pos) {
278
+ static void rami_seek_i(FrtInStream *is, frt_off_t pos) {
297
279
  is->d.pointer = pos;
298
280
  }
299
281
 
300
282
  static void rami_close_i(FrtInStream *is) {
301
- FrtRAMFile *rf = is->file.rf;
302
- FRT_DEREF(rf);
283
+ FrtRAMFile *rf = is->f->file.rf;
303
284
  rf_close(rf);
304
285
  }
305
286
 
@@ -319,7 +300,8 @@ static FrtInStream *ram_open_input(FrtStore *store, const char *filename) {
319
300
  }
320
301
  FRT_REF(rf);
321
302
  is = frt_is_new();
322
- is->file.rf = rf;
303
+ is->f->file.rf = rf;
304
+ is->f->ref_cnt = 1;
323
305
  is->d.pointer = 0;
324
306
  is->m = &RAM_IN_STREAM_METHODS;
325
307
 
@@ -351,6 +333,7 @@ static FrtLock *ram_open_lock_i(FrtStore *store, const char *lockname) {
351
333
  snprintf(lname, 100, "%s%s.lck", FRT_LOCK_PREFIX, lockname);
352
334
  lock->name = frt_estrdup(lname);
353
335
  lock->store = store;
336
+ FRT_REF(store);
354
337
  lock->obtain = &ram_lock_obtain;
355
338
  lock->release = &ram_lock_release;
356
339
  lock->is_locked = &ram_lock_is_locked;
@@ -359,6 +342,7 @@ static FrtLock *ram_open_lock_i(FrtStore *store, const char *lockname) {
359
342
  }
360
343
 
361
344
  static void ram_close_lock_i(FrtLock *lock) {
345
+ FRT_DEREF(lock->store);
362
346
  free(lock->name);
363
347
  free(lock);
364
348
  }
@@ -415,7 +399,7 @@ FrtStore *frt_open_ram_store_and_copy(FrtStore *store, FrtStore *from_store, boo
415
399
  from_store->each(from_store, &copy_files, &cfa);
416
400
 
417
401
  if (close_dir) {
418
- frt_store_deref(from_store);
402
+ frt_store_close(from_store);
419
403
  }
420
404
 
421
405
  return store;
@@ -3,7 +3,7 @@
3
3
  #include "frt_search.h"
4
4
  #include "frt_array.h"
5
5
 
6
- #undef close
6
+ // #undef close
7
7
 
8
8
  /***************************************************************************
9
9
  *
@@ -303,7 +303,7 @@ const char *frt_q_get_query_name(FrtQueryType type) {
303
303
  static FrtQuery *q_rewrite(FrtQuery *self, FrtIndexReader *ir)
304
304
  {
305
305
  (void)ir;
306
- self->ref_cnt++;
306
+ FRT_REF(self);
307
307
  return self;
308
308
  }
309
309
 
@@ -318,13 +318,12 @@ FrtSimilarity *frt_q_get_similarity_i(FrtQuery *self, FrtSearcher *searcher) {
318
318
  return searcher->get_similarity(searcher);
319
319
  }
320
320
 
321
- void frt_q_destroy_i(FrtQuery *self) {
322
- free(self);
321
+ void frt_q_destroy_i(FrtQuery *q) {
322
+ free(q);
323
323
  }
324
324
 
325
- void frt_q_deref(FrtQuery *self) {
326
- if (--(self->ref_cnt) == 0)
327
- self->destroy_i(self);
325
+ void frt_q_deref(FrtQuery *q) {
326
+ if (FRT_DEREF(q) == 0) q->destroy_i(q);
328
327
  }
329
328
 
330
329
  FrtWeight *frt_q_create_weight_unsup(FrtQuery *self, FrtSearcher *searcher) {
@@ -1180,11 +1179,13 @@ static FrtTermVector *isea_get_term_vector(FrtSearcher *self, const int doc_num,
1180
1179
  return ir->term_vector(ir, doc_num, field);
1181
1180
  }
1182
1181
 
1183
- static void isea_close(FrtSearcher *self) {
1184
- if (ISEA(self)->ir && ISEA(self)->close_ir) {
1185
- frt_ir_close(ISEA(self)->ir);
1182
+ static void isea_close(FrtSearcher *isea) {
1183
+ if (FRT_DEREF(isea) == 0) {
1184
+ if (ISEA(isea)->ir) {
1185
+ frt_ir_close(ISEA(isea)->ir);
1186
+ }
1187
+ free(isea);
1186
1188
  }
1187
- free(self);
1188
1189
  }
1189
1190
 
1190
1191
  FrtSearcher *frt_isea_alloc(void) {
@@ -1193,8 +1194,8 @@ FrtSearcher *frt_isea_alloc(void) {
1193
1194
 
1194
1195
  FrtSearcher *frt_isea_init(FrtSearcher *self, FrtIndexReader *ir) {
1195
1196
  ISEA(self)->ir = ir;
1196
- ISEA(self)->close_ir = true;
1197
-
1197
+ FRT_REF(ir);
1198
+ self->ref_cnt = 1;
1198
1199
  self->similarity = frt_sim_create_default();
1199
1200
  self->doc_freq = &frt_isea_doc_freq;
1200
1201
  self->get_doc = &isea_get_doc;
@@ -1304,7 +1305,7 @@ static void cdfsea_search_each_w(FrtSearcher *self, FrtWeight *w, FrtFilter *fil
1304
1305
  static FrtQuery *cdfsea_rewrite(FrtSearcher *self, FrtQuery *original)
1305
1306
  {
1306
1307
  (void)self;
1307
- original->ref_cnt++;
1308
+ FRT_REF(original);
1308
1309
  return original;
1309
1310
  }
1310
1311
 
@@ -1721,31 +1722,32 @@ static FrtSimilarity *msea_get_similarity(FrtSearcher *self) {
1721
1722
  return self->similarity;
1722
1723
  }
1723
1724
 
1724
- static void msea_close(FrtSearcher *self) {
1725
- int i;
1726
- FrtSearcher *s;
1727
- FrtMultiSearcher *msea = MSEA(self);
1728
- if (msea->close_subs) {
1729
- for (i = 0; i < msea->s_cnt; i++) {
1730
- s = msea->searchers[i];
1725
+ static void msea_close(FrtSearcher *msea) {
1726
+ if (FRT_DEREF(msea) == 0) {
1727
+ FrtMultiSearcher *rmsea = MSEA(msea);
1728
+ FrtSearcher *s;
1729
+ int i;
1730
+ for (i = 0; i < rmsea->s_cnt; i++) {
1731
+ s = rmsea->searchers[i];
1731
1732
  s->close(s);
1732
1733
  }
1734
+ free(rmsea->searchers);
1735
+ free(rmsea->starts);
1736
+ free(msea);
1733
1737
  }
1734
- free(msea->searchers);
1735
- free(msea->starts);
1736
- free(self);
1737
1738
  }
1738
1739
 
1739
1740
  FrtSearcher *frt_msea_alloc(void) {
1740
1741
  return (FrtSearcher *)FRT_ALLOC(FrtMultiSearcher);
1741
1742
  }
1742
1743
 
1743
- FrtSearcher *frt_msea_init(FrtSearcher *self, FrtSearcher **searchers, int s_cnt, bool close_subs) {
1744
+ FrtSearcher *frt_msea_init(FrtSearcher *self, FrtSearcher **searchers, int s_cnt) {
1744
1745
  int i, max_doc = 0;
1745
1746
  int *starts = FRT_ALLOC_N(int, s_cnt + 1);
1746
1747
  for (i = 0; i < s_cnt; i++) {
1747
1748
  starts[i] = max_doc;
1748
1749
  max_doc += searchers[i]->max_doc(searchers[i]);
1750
+ FRT_REF(searchers[i]);
1749
1751
  }
1750
1752
  starts[i] = max_doc;
1751
1753
 
@@ -1753,8 +1755,7 @@ FrtSearcher *frt_msea_init(FrtSearcher *self, FrtSearcher **searchers, int s_cnt
1753
1755
  MSEA(self)->searchers = searchers;
1754
1756
  MSEA(self)->starts = starts;
1755
1757
  MSEA(self)->max_doc = max_doc;
1756
- MSEA(self)->close_subs = close_subs;
1757
-
1758
+ self->ref_cnt = 1;
1758
1759
  self->similarity = frt_sim_create_default();
1759
1760
  self->doc_freq = &msea_doc_freq;
1760
1761
  self->get_doc = &msea_get_doc;
@@ -1777,7 +1778,7 @@ FrtSearcher *frt_msea_init(FrtSearcher *self, FrtSearcher **searchers, int s_cnt
1777
1778
  return self;
1778
1779
  }
1779
1780
 
1780
- FrtSearcher *frt_msea_new(FrtSearcher **searchers, int s_cnt, bool close_subs) {
1781
+ FrtSearcher *frt_msea_new(FrtSearcher **searchers, int s_cnt) {
1781
1782
  FrtSearcher *self = frt_msea_alloc();
1782
- return frt_msea_init(self, searchers, s_cnt, close_subs);
1783
+ return frt_msea_init(self, searchers, s_cnt);
1783
1784
  }
@@ -103,7 +103,7 @@ typedef struct FrtFilter {
103
103
  unsigned long long (*hash)(struct FrtFilter *self);
104
104
  int (*eq)(struct FrtFilter *self, struct FrtFilter *o);
105
105
  void (*destroy_i)(struct FrtFilter *self);
106
- int ref_cnt;
106
+ _Atomic unsigned int ref_cnt;
107
107
  VALUE rfilter;
108
108
  } FrtFilter;
109
109
 
@@ -228,7 +228,7 @@ typedef enum {
228
228
  } FrtQueryType;
229
229
 
230
230
  struct FrtQuery {
231
- int ref_cnt;
231
+ _Atomic unsigned int ref_cnt;
232
232
  float boost;
233
233
  FrtWeight *weight;
234
234
  FrtQuery *(*rewrite)(FrtQuery *self, FrtIndexReader *ir);
@@ -264,7 +264,7 @@ extern FrtQuery *frt_q_create(size_t size);
264
264
 
265
265
  typedef struct FrtTermQuery {
266
266
  FrtQuery super;
267
- ID field;
267
+ ID field;
268
268
  char *term;
269
269
  } FrtTermQuery;
270
270
 
@@ -283,12 +283,12 @@ typedef enum {
283
283
  } FrtBCType;
284
284
 
285
285
  typedef struct FrtBooleanClause {
286
- int ref_cnt;
287
- FrtQuery *query;
288
- FrtBCType occur;
289
- bool is_prohibited : 1;
290
- bool is_required : 1;
291
- VALUE rbc;
286
+ _Atomic unsigned int ref_cnt;
287
+ FrtQuery *query;
288
+ FrtBCType occur;
289
+ bool is_prohibited : 1;
290
+ bool is_required : 1;
291
+ VALUE rbc;
292
292
  } FrtBooleanClause;
293
293
 
294
294
  extern FrtBooleanClause *frt_bc_alloc(void);
@@ -330,7 +330,7 @@ extern FrtBooleanClause *frt_bq_add_clause_nr(FrtQuery *self, FrtBooleanClause *
330
330
  typedef struct FrtPhraseQuery {
331
331
  FrtQuery super;
332
332
  int slop;
333
- ID field;
333
+ ID field;
334
334
  FrtPhrasePosition *positions;
335
335
  int pos_cnt;
336
336
  int pos_capa;
@@ -351,7 +351,7 @@ extern void frt_phq_set_slop(FrtQuery *self, int slop);
351
351
  #define MULTI_TERM_QUERY_MAX_TERMS 256
352
352
  typedef struct FrtMultiTermQuery {
353
353
  FrtQuery super;
354
- ID field;
354
+ ID field;
355
355
  FrtPriorityQueue *boosted_terms;
356
356
  float min_boost;
357
357
  } FrtMultiTermQuery;
@@ -377,7 +377,7 @@ typedef struct FrtMTQSubQuery {
377
377
 
378
378
  typedef struct FrtPrefixQuery {
379
379
  FrtMTQSubQuery super;
380
- ID field;
380
+ ID field;
381
381
  char *prefix;
382
382
  } FrtPrefixQuery;
383
383
 
@@ -395,7 +395,7 @@ extern FrtQuery *frt_prefixq_new(ID field, const char *prefix);
395
395
 
396
396
  typedef struct FrtWildCardQuery {
397
397
  FrtMTQSubQuery super;
398
- ID field;
398
+ ID field;
399
399
  char *pattern;
400
400
  } FrtWildCardQuery;
401
401
 
@@ -415,7 +415,7 @@ extern bool frt_wc_match(const char *pattern, const char *text);
415
415
 
416
416
  typedef struct FrtFuzzyQuery {
417
417
  FrtMTQSubQuery super;
418
- ID field;
418
+ ID field;
419
419
  char *term;
420
420
  const char *text; /* term text after prefix */
421
421
  int text_len;
@@ -514,7 +514,7 @@ struct FrtSpanEnum {
514
514
  /* ** FrtSpanQuery ** */
515
515
  typedef struct FrtSpanQuery {
516
516
  FrtQuery super;
517
- ID field;
517
+ ID field;
518
518
  FrtSpanEnum *(*get_spans)(FrtQuery *self, FrtIndexReader *ir);
519
519
  FrtHashSet *(*get_terms)(FrtQuery *self);
520
520
  } FrtSpanQuery;
@@ -790,6 +790,7 @@ typedef struct FrtPostFilter {
790
790
  } FrtPostFilter;
791
791
 
792
792
  struct FrtSearcher {
793
+ _Atomic unsigned int ref_cnt;
793
794
  FrtSimilarity *similarity;
794
795
  int (*doc_freq)(FrtSearcher *self, ID field, const char *term);
795
796
  FrtDocument *(*get_doc)(FrtSearcher *self, int doc_num);
@@ -849,7 +850,6 @@ extern char **frt_searcher_highlight(FrtSearcher *self,
849
850
  typedef struct FrtIndexSearcher {
850
851
  FrtSearcher super;
851
852
  FrtIndexReader *ir;
852
- bool close_ir : 1;
853
853
  } FrtIndexSearcher;
854
854
 
855
855
  extern FrtSearcher *frt_isea_alloc(void);
@@ -869,12 +869,11 @@ typedef struct FrtMultiSearcher {
869
869
  FrtSearcher **searchers;
870
870
  int *starts;
871
871
  int max_doc;
872
- bool close_subs : 1;
873
872
  } FrtMultiSearcher;
874
873
 
875
874
  extern FrtSearcher *frt_msea_alloc(void);
876
- extern FrtSearcher *frt_msea_init(FrtSearcher *self, FrtSearcher **searchers, int s_cnt, bool close_subs);
877
- extern FrtSearcher *frt_msea_new(FrtSearcher **searchers, int s_cnt, bool close_subs);
875
+ extern FrtSearcher *frt_msea_init(FrtSearcher *self, FrtSearcher **searchers, int s_cnt);
876
+ extern FrtSearcher *frt_msea_new(FrtSearcher **searchers, int s_cnt);
878
877
 
879
878
  /***************************************************************************
880
879
  *
@@ -3,7 +3,7 @@
3
3
  #include "frt_index.h"
4
4
  #include "frt_field_index.h"
5
5
 
6
- #undef close
6
+ // #undef close
7
7
 
8
8
  /***************************************************************************
9
9
  *