isomorfeus-ferret 0.12.7 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +101 -19
  3. data/README.md +54 -1
  4. data/ext/isomorfeus_ferret_ext/bm_bitvector.c +22 -30
  5. data/ext/isomorfeus_ferret_ext/bm_hash.c +6 -12
  6. data/ext/isomorfeus_ferret_ext/bm_micro_string.c +3 -6
  7. data/ext/isomorfeus_ferret_ext/bm_store.c +11 -22
  8. data/ext/isomorfeus_ferret_ext/brotli_common_dictionary.c +1 -1
  9. data/ext/isomorfeus_ferret_ext/brotli_dec_decode.c +1 -1
  10. data/ext/isomorfeus_ferret_ext/bzip_blocksort.c +1094 -0
  11. data/ext/isomorfeus_ferret_ext/bzip_huffman.c +205 -0
  12. data/ext/isomorfeus_ferret_ext/bzlib.c +1572 -0
  13. data/ext/isomorfeus_ferret_ext/bzlib.h +282 -0
  14. data/ext/isomorfeus_ferret_ext/bzlib_compress.c +672 -0
  15. data/ext/isomorfeus_ferret_ext/bzlib_crctable.c +104 -0
  16. data/ext/isomorfeus_ferret_ext/bzlib_decompress.c +652 -0
  17. data/ext/isomorfeus_ferret_ext/bzlib_private.h +509 -0
  18. data/ext/isomorfeus_ferret_ext/bzlib_randtable.c +84 -0
  19. data/ext/isomorfeus_ferret_ext/fio_tmpfile.h +53 -53
  20. data/ext/isomorfeus_ferret_ext/frb_analysis.c +785 -1192
  21. data/ext/isomorfeus_ferret_ext/frb_index.c +492 -474
  22. data/ext/isomorfeus_ferret_ext/frb_qparser.c +48 -60
  23. data/ext/isomorfeus_ferret_ext/frb_search.c +1520 -1002
  24. data/ext/isomorfeus_ferret_ext/frb_store.c +96 -96
  25. data/ext/isomorfeus_ferret_ext/frb_threading.h +0 -1
  26. data/ext/isomorfeus_ferret_ext/frb_utils.c +147 -196
  27. data/ext/isomorfeus_ferret_ext/frt_analysis.c +695 -1090
  28. data/ext/isomorfeus_ferret_ext/frt_analysis.h +174 -170
  29. data/ext/isomorfeus_ferret_ext/frt_array.c +2 -4
  30. data/ext/isomorfeus_ferret_ext/frt_bitvector.c +9 -16
  31. data/ext/isomorfeus_ferret_ext/frt_bitvector.h +32 -81
  32. data/ext/isomorfeus_ferret_ext/frt_document.c +15 -20
  33. data/ext/isomorfeus_ferret_ext/frt_document.h +10 -10
  34. data/ext/isomorfeus_ferret_ext/frt_except.c +5 -12
  35. data/ext/isomorfeus_ferret_ext/frt_field_index.c +3 -3
  36. data/ext/isomorfeus_ferret_ext/frt_field_index.h +6 -7
  37. data/ext/isomorfeus_ferret_ext/frt_filter.c +35 -46
  38. data/ext/isomorfeus_ferret_ext/frt_fs_store.c +1 -0
  39. data/ext/isomorfeus_ferret_ext/frt_global.c +105 -63
  40. data/ext/isomorfeus_ferret_ext/frt_global.h +7 -3
  41. data/ext/isomorfeus_ferret_ext/frt_hash.c +1 -2
  42. data/ext/isomorfeus_ferret_ext/frt_ind.c +32 -35
  43. data/ext/isomorfeus_ferret_ext/frt_ind.h +9 -9
  44. data/ext/isomorfeus_ferret_ext/frt_index.c +580 -399
  45. data/ext/isomorfeus_ferret_ext/frt_index.h +272 -291
  46. data/ext/isomorfeus_ferret_ext/frt_mempool.c +1 -2
  47. data/ext/isomorfeus_ferret_ext/frt_multimapper.c +4 -7
  48. data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +67 -91
  49. data/ext/isomorfeus_ferret_ext/frt_q_const_score.c +35 -38
  50. data/ext/isomorfeus_ferret_ext/frt_q_filtered_query.c +53 -72
  51. data/ext/isomorfeus_ferret_ext/frt_q_fuzzy.c +25 -32
  52. data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +21 -23
  53. data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +66 -103
  54. data/ext/isomorfeus_ferret_ext/frt_q_parser.c +207 -195
  55. data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +20 -16
  56. data/ext/isomorfeus_ferret_ext/frt_q_prefix.c +17 -14
  57. data/ext/isomorfeus_ferret_ext/frt_q_range.c +102 -131
  58. data/ext/isomorfeus_ferret_ext/frt_q_span.c +179 -178
  59. data/ext/isomorfeus_ferret_ext/frt_q_term.c +47 -60
  60. data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +18 -16
  61. data/ext/isomorfeus_ferret_ext/frt_ram_store.c +45 -84
  62. data/ext/isomorfeus_ferret_ext/frt_search.c +105 -146
  63. data/ext/isomorfeus_ferret_ext/frt_search.h +331 -320
  64. data/ext/isomorfeus_ferret_ext/frt_similarity.c +5 -13
  65. data/ext/isomorfeus_ferret_ext/frt_similarity.h +7 -12
  66. data/ext/isomorfeus_ferret_ext/frt_sort.c +105 -149
  67. data/ext/isomorfeus_ferret_ext/frt_store.c +13 -7
  68. data/ext/isomorfeus_ferret_ext/frt_store.h +10 -2
  69. data/ext/isomorfeus_ferret_ext/frt_threading.h +0 -1
  70. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +21 -109
  71. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +2 -32
  72. data/ext/isomorfeus_ferret_ext/lz4.c +2495 -0
  73. data/ext/isomorfeus_ferret_ext/lz4.h +774 -0
  74. data/ext/isomorfeus_ferret_ext/lz4frame.c +1899 -0
  75. data/ext/isomorfeus_ferret_ext/lz4frame.h +623 -0
  76. data/ext/isomorfeus_ferret_ext/lz4hc.c +1615 -0
  77. data/ext/isomorfeus_ferret_ext/lz4hc.h +413 -0
  78. data/ext/isomorfeus_ferret_ext/lz4xxhash.c +1030 -0
  79. data/ext/isomorfeus_ferret_ext/lz4xxhash.h +328 -0
  80. data/ext/isomorfeus_ferret_ext/stem_modules.h +0 -86
  81. data/ext/isomorfeus_ferret_ext/test.c +1 -2
  82. data/ext/isomorfeus_ferret_ext/test_1710.c +11 -12
  83. data/ext/isomorfeus_ferret_ext/test_analysis.c +590 -583
  84. data/ext/isomorfeus_ferret_ext/test_compound_io.c +1 -1
  85. data/ext/isomorfeus_ferret_ext/test_document.c +19 -15
  86. data/ext/isomorfeus_ferret_ext/test_except.c +1 -2
  87. data/ext/isomorfeus_ferret_ext/test_fields.c +59 -60
  88. data/ext/isomorfeus_ferret_ext/test_file_deleter.c +10 -27
  89. data/ext/isomorfeus_ferret_ext/test_filter.c +11 -8
  90. data/ext/isomorfeus_ferret_ext/test_hash.c +2 -2
  91. data/ext/isomorfeus_ferret_ext/test_hashset.c +1 -1
  92. data/ext/isomorfeus_ferret_ext/test_highlighter.c +15 -11
  93. data/ext/isomorfeus_ferret_ext/test_index.c +372 -365
  94. data/ext/isomorfeus_ferret_ext/test_q_const_score.c +5 -3
  95. data/ext/isomorfeus_ferret_ext/test_q_filtered.c +5 -3
  96. data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +13 -10
  97. data/ext/isomorfeus_ferret_ext/test_q_parser.c +45 -7
  98. data/ext/isomorfeus_ferret_ext/test_q_span.c +15 -12
  99. data/ext/isomorfeus_ferret_ext/test_ram_store.c +3 -3
  100. data/ext/isomorfeus_ferret_ext/test_search.c +60 -62
  101. data/ext/isomorfeus_ferret_ext/test_segments.c +5 -4
  102. data/ext/isomorfeus_ferret_ext/test_sort.c +17 -14
  103. data/ext/isomorfeus_ferret_ext/test_store.c +2 -0
  104. data/ext/isomorfeus_ferret_ext/test_term.c +3 -1
  105. data/ext/isomorfeus_ferret_ext/test_term_vectors.c +9 -10
  106. data/ext/isomorfeus_ferret_ext/test_test.c +1 -2
  107. data/ext/isomorfeus_ferret_ext/test_threading.c +9 -10
  108. data/ext/isomorfeus_ferret_ext/testhelper.c +1 -2
  109. data/lib/isomorfeus/ferret/version.rb +1 -1
  110. metadata +27 -57
  111. data/ext/isomorfeus_ferret_ext/email.rl +0 -21
  112. data/ext/isomorfeus_ferret_ext/frt_scanner.c +0 -900
  113. data/ext/isomorfeus_ferret_ext/frt_scanner.h +0 -28
  114. data/ext/isomorfeus_ferret_ext/frt_scanner_mb.c +0 -6706
  115. data/ext/isomorfeus_ferret_ext/frt_scanner_utf8.c +0 -4420
  116. data/ext/isomorfeus_ferret_ext/scanner.h +0 -28
  117. data/ext/isomorfeus_ferret_ext/scanner.in +0 -43
  118. data/ext/isomorfeus_ferret_ext/scanner.rl +0 -84
  119. data/ext/isomorfeus_ferret_ext/scanner_mb.rl +0 -200
  120. data/ext/isomorfeus_ferret_ext/scanner_utf8.rl +0 -85
  121. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_basque.c +0 -1167
  122. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_basque.h +0 -6
  123. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_catalan.c +0 -1433
  124. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_catalan.h +0 -6
  125. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.c +0 -301
  126. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.h +0 -6
  127. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.c +0 -590
  128. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.h +0 -6
  129. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.c +0 -1049
  130. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.h +0 -6
  131. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.c +0 -705
  132. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.h +0 -6
  133. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.c +0 -1239
  134. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.h +0 -6
  135. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.c +0 -477
  136. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.h +0 -6
  137. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.c +0 -1217
  138. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.h +0 -7
  139. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_indonesian.c +0 -394
  140. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_indonesian.h +0 -6
  141. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_irish.c +0 -457
  142. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_irish.h +0 -6
  143. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.c +0 -1009
  144. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.h +0 -6
  145. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.c +0 -259
  146. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.h +0 -6
  147. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.c +0 -704
  148. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.h +0 -6
  149. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.c +0 -948
  150. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.h +0 -6
  151. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.c +0 -1028
  152. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.h +0 -6
  153. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.c +0 -275
  154. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.h +0 -6
  155. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_hungarian.c +0 -849
  156. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_hungarian.h +0 -6
  157. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.c +0 -952
  158. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.h +0 -6
  159. data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.c +0 -669
  160. data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.h +0 -6
  161. data/ext/isomorfeus_ferret_ext/stem_modules.txt +0 -63
  162. data/ext/isomorfeus_ferret_ext/uchar-ucs4.rl +0 -1854
  163. data/ext/isomorfeus_ferret_ext/uchar-utf8.rl +0 -1999
  164. data/ext/isomorfeus_ferret_ext/url.rl +0 -27
@@ -2,6 +2,9 @@
2
2
  #include <string.h>
3
3
  #include "frt_search.h"
4
4
 
5
+ #undef close
6
+ #undef read
7
+
5
8
  #define TQ(query) ((FrtTermQuery *)(query))
6
9
  #define TSc(scorer) ((TermScorer *)(scorer))
7
10
 
@@ -14,30 +17,27 @@
14
17
  #define SCORE_CACHE_SIZE 32
15
18
  #define TDE_READ_SIZE 32
16
19
 
17
- typedef struct TermScorer
18
- {
19
- FrtScorer super;
20
- int docs[TDE_READ_SIZE];
21
- int freqs[TDE_READ_SIZE];
22
- int pointer;
23
- int pointer_max;
24
- float score_cache[SCORE_CACHE_SIZE];
25
- FrtWeight *weight;
26
- FrtTermDocEnum *tde;
27
- frt_uchar *norms;
28
- float weight_value;
20
+ typedef struct TermScorer {
21
+ FrtScorer super;
22
+ int docs[TDE_READ_SIZE];
23
+ int freqs[TDE_READ_SIZE];
24
+ int pointer;
25
+ int pointer_max;
26
+ float score_cache[SCORE_CACHE_SIZE];
27
+ FrtWeight *weight;
28
+ FrtTermDocEnum *tde;
29
+ frt_uchar *norms;
30
+ float weight_value;
29
31
  } TermScorer;
30
32
 
31
- static float tsc_score(FrtScorer *self)
32
- {
33
+ static float tsc_score(FrtScorer *self) {
33
34
  TermScorer *ts = TSc(self);
34
35
  int freq = ts->freqs[ts->pointer];
35
36
  float score;
36
37
  /* compute tf(f)*weight */
37
38
  if (freq < SCORE_CACHE_SIZE) { /* check cache */
38
39
  score = ts->score_cache[freq]; /* cache hit */
39
- }
40
- else {
40
+ } else {
41
41
  /* cache miss */
42
42
  score = frt_sim_tf(self->similarity, (float)freq) * ts->weight_value;
43
43
  }
@@ -46,19 +46,16 @@ static float tsc_score(FrtScorer *self)
46
46
  return score;
47
47
  }
48
48
 
49
- static bool tsc_next(FrtScorer *self)
50
- {
49
+ static bool tsc_next(FrtScorer *self) {
51
50
  TermScorer *ts = TSc(self);
52
51
 
53
52
  ts->pointer++;
54
53
  if (ts->pointer >= ts->pointer_max) {
55
54
  /* refill buffer */
56
- ts->pointer_max = ts->tde->read(ts->tde, ts->docs, ts->freqs,
57
- TDE_READ_SIZE);
55
+ ts->pointer_max = ts->tde->read(ts->tde, ts->docs, ts->freqs, TDE_READ_SIZE);
58
56
  if (ts->pointer_max != 0) {
59
57
  ts->pointer = 0;
60
- }
61
- else {
58
+ } else {
62
59
  return false;
63
60
  }
64
61
  }
@@ -66,8 +63,7 @@ static bool tsc_next(FrtScorer *self)
66
63
  return true;
67
64
  }
68
65
 
69
- static bool tsc_skip_to(FrtScorer *self, int doc_num)
70
- {
66
+ static bool tsc_skip_to(FrtScorer *self, int doc_num) {
71
67
  TermScorer *ts = TSc(self);
72
68
  FrtTermDocEnum *tde = ts->tde;
73
69
 
@@ -86,14 +82,12 @@ static bool tsc_skip_to(FrtScorer *self, int doc_num)
86
82
  ts->docs[0] = self->doc = tde->doc_num(tde);
87
83
  ts->freqs[0] = tde->freq(tde);
88
84
  return true;
89
- }
90
- else {
85
+ } else {
91
86
  return false;
92
87
  }
93
88
  }
94
89
 
95
- static FrtExplanation *tsc_explain(FrtScorer *self, int doc_num)
96
- {
90
+ static FrtExplanation *tsc_explain(FrtScorer *self, int doc_num) {
97
91
  TermScorer *ts = TSc(self);
98
92
  FrtQuery *query = ts->weight->get_query(ts->weight);
99
93
  int tf = 0;
@@ -107,14 +101,12 @@ static FrtExplanation *tsc_explain(FrtScorer *self, int doc_num)
107
101
  rb_id2name(TQ(query)->field), TQ(query)->term, tf);
108
102
  }
109
103
 
110
- static void tsc_destroy(FrtScorer *self)
111
- {
104
+ static void tsc_destroy(FrtScorer *self) {
112
105
  TSc(self)->tde->close(TSc(self)->tde);
113
106
  frt_scorer_destroy_i(self);
114
107
  }
115
108
 
116
- static FrtScorer *tsc_new(FrtWeight *weight, FrtTermDocEnum *tde, frt_uchar *norms)
117
- {
109
+ static FrtScorer *tsc_new(FrtWeight *weight, FrtTermDocEnum *tde, frt_uchar *norms) {
118
110
  int i;
119
111
  FrtScorer *self = frt_scorer_new(TermScorer, weight->similarity);
120
112
  TSc(self)->weight = weight;
@@ -141,8 +133,7 @@ static FrtScorer *tsc_new(FrtWeight *weight, FrtTermDocEnum *tde, frt_uchar *nor
141
133
  *
142
134
  ***************************************************************************/
143
135
 
144
- static FrtScorer *tw_scorer(FrtWeight *self, FrtIndexReader *ir)
145
- {
136
+ static FrtScorer *tw_scorer(FrtWeight *self, FrtIndexReader *ir) {
146
137
  FrtTermQuery *tq = TQ(self->query);
147
138
  FrtTermDocEnum *tde = ir_term_docs_for(ir, tq->field, tq->term);
148
139
  /* ir_term_docs_for should always return a TermDocEnum */
@@ -151,8 +142,7 @@ static FrtScorer *tw_scorer(FrtWeight *self, FrtIndexReader *ir)
151
142
  return tsc_new(self, tde, frt_ir_get_norms(ir, tq->field));
152
143
  }
153
144
 
154
- static FrtExplanation *tw_explain(FrtWeight *self, FrtIndexReader *ir, int doc_num)
155
- {
145
+ static FrtExplanation *tw_explain(FrtWeight *self, FrtIndexReader *ir, int doc_num) {
156
146
  FrtExplanation *qnorm_expl;
157
147
  FrtExplanation *field_expl;
158
148
  FrtScorer *scorer;
@@ -160,7 +150,7 @@ static FrtExplanation *tw_explain(FrtWeight *self, FrtIndexReader *ir, int doc_n
160
150
  frt_uchar *field_norms;
161
151
  float field_norm;
162
152
  FrtExplanation *field_norm_expl;
163
- char *query_str = self->query->to_s(self->query, (FrtSymbol)NULL);
153
+ char *query_str = self->query->to_s(self->query, (ID)NULL);
164
154
  FrtTermQuery *tq = TQ(self->query);
165
155
  char *term = tq->term;
166
156
  FrtExplanation *expl = frt_expl_new(0.0, "weight(%s in %d), product of:", query_str, doc_num);
@@ -203,14 +193,12 @@ static FrtExplanation *tw_explain(FrtWeight *self, FrtIndexReader *ir, int doc_n
203
193
  }
204
194
  }
205
195
 
206
- static char *tw_to_s(FrtWeight *self)
207
- {
196
+ static char *tw_to_s(FrtWeight *self) {
208
197
  return frt_strfmt("TermWeight(%f)", self->value);
209
198
  }
210
199
 
211
- static FrtWeight *tw_new(FrtQuery *query, FrtSearcher *searcher)
212
- {
213
- FrtWeight *self = w_new(FrtWeight, query);
200
+ static FrtWeight *tw_new(FrtQuery *query, FrtSearcher *searcher) {
201
+ FrtWeight *self = w_new(FrtWeight, query);
214
202
  self->scorer = &tw_scorer;
215
203
  self->explain = &tw_explain;
216
204
  self->to_s = &tw_to_s;
@@ -231,14 +219,12 @@ static FrtWeight *tw_new(FrtQuery *query, FrtSearcher *searcher)
231
219
  *
232
220
  ***************************************************************************/
233
221
 
234
- static void tq_destroy(FrtQuery *self)
235
- {
222
+ static void tq_destroy(FrtQuery *self) {
236
223
  free(TQ(self)->term);
237
224
  frt_q_destroy_i(self);
238
225
  }
239
226
 
240
- static char *tq_to_s(FrtQuery *self, FrtSymbol default_field)
241
- {
227
+ static char *tq_to_s(FrtQuery *self, ID default_field) {
242
228
  const char *field_name = rb_id2name(TQ(self)->field);
243
229
  size_t flen = strlen(field_name);
244
230
  const char *term = TQ(self)->term;
@@ -260,25 +246,19 @@ static char *tq_to_s(FrtQuery *self, FrtSymbol default_field)
260
246
  return buffer;
261
247
  }
262
248
 
263
- static void tq_extract_terms(FrtQuery *self, FrtHashSet *terms)
264
- {
249
+ static void tq_extract_terms(FrtQuery *self, FrtHashSet *terms) {
265
250
  frt_hs_add(terms, frt_term_new(TQ(self)->field, TQ(self)->term));
266
251
  }
267
252
 
268
- static unsigned long long tq_hash(FrtQuery *self)
269
- {
253
+ static unsigned long long tq_hash(FrtQuery *self) {
270
254
  return frt_str_hash(TQ(self)->term) ^ frt_str_hash(rb_id2name(TQ(self)->field));
271
255
  }
272
256
 
273
- static int tq_eq(FrtQuery *self, FrtQuery *o)
274
- {
275
- return (strcmp(TQ(self)->term, TQ(o)->term) == 0)
276
- && (TQ(self)->field == TQ(o)->field);
257
+ static int tq_eq(FrtQuery *self, FrtQuery *o) {
258
+ return (strcmp(TQ(self)->term, TQ(o)->term) == 0) && (TQ(self)->field == TQ(o)->field);
277
259
  }
278
260
 
279
- static FrtMatchVector *tq_get_matchv_i(FrtQuery *self, FrtMatchVector *mv,
280
- FrtTermVector *tv)
281
- {
261
+ static FrtMatchVector *tq_get_matchv_i(FrtQuery *self, FrtMatchVector *mv, FrtTermVector *tv) {
282
262
  if (tv->field == TQ(self)->field) {
283
263
  int i;
284
264
  FrtTVTerm *tv_term = frt_tv_get_tv_term(tv, TQ(self)->term);
@@ -292,9 +272,11 @@ static FrtMatchVector *tq_get_matchv_i(FrtQuery *self, FrtMatchVector *mv,
292
272
  return mv;
293
273
  }
294
274
 
295
- FrtQuery *frt_tq_new(FrtSymbol field, const char *term)
296
- {
297
- FrtQuery *self = frt_q_new(FrtTermQuery);
275
+ FrtQuery *frt_tq_alloc(void) {
276
+ return frt_q_new(FrtTermQuery);
277
+ }
278
+
279
+ FrtQuery *frt_tq_init(FrtQuery *self, ID field, const char *term) {
298
280
  TQ(self)->field = field;
299
281
  TQ(self)->term = frt_estrdup(term);
300
282
  self->type = TERM_QUERY;
@@ -309,3 +291,8 @@ FrtQuery *frt_tq_new(FrtSymbol field, const char *term)
309
291
 
310
292
  return self;
311
293
  }
294
+
295
+ FrtQuery *frt_tq_new(ID field, const char *term) {
296
+ FrtQuery *self = frt_tq_alloc();
297
+ return frt_tq_init(self, field, term);
298
+ }
@@ -2,6 +2,8 @@
2
2
  #include "frt_global.h"
3
3
  #include "frt_search.h"
4
4
 
5
+ #undef close
6
+
5
7
  /****************************************************************************
6
8
  *
7
9
  * FrtWildCardQuery
@@ -10,8 +12,7 @@
10
12
 
11
13
  #define WCQ(query) ((FrtWildCardQuery *)(query))
12
14
 
13
- static char *wcq_to_s(FrtQuery *self, FrtSymbol default_field)
14
- {
15
+ static char *wcq_to_s(FrtQuery *self, ID default_field) {
15
16
  char *buffer, *bptr;
16
17
  const char *field_name = rb_id2name(WCQ(self)->field);
17
18
  const char *pattern = WCQ(self)->pattern;
@@ -30,8 +31,7 @@ static char *wcq_to_s(FrtQuery *self, FrtSymbol default_field)
30
31
  return buffer;
31
32
  }
32
33
 
33
- bool frt_wc_match(const char *pattern, const char *text)
34
- {
34
+ bool frt_wc_match(const char *pattern, const char *text) {
35
35
  const char *p = pattern, *t = text, *xt;
36
36
 
37
37
  /* include '\0' as we need to match empty string */
@@ -77,8 +77,7 @@ bool frt_wc_match(const char *pattern, const char *text)
77
77
  return false;
78
78
  }
79
79
 
80
- static FrtQuery *wcq_rewrite(FrtQuery *self, FrtIndexReader *ir)
81
- {
80
+ static FrtQuery *wcq_rewrite(FrtQuery *self, FrtIndexReader *ir) {
82
81
  FrtQuery *q;
83
82
  const char *pattern = WCQ(self)->pattern;
84
83
  const char *first_star = strchr(pattern, FRT_WILD_STRING);
@@ -129,30 +128,28 @@ static FrtQuery *wcq_rewrite(FrtQuery *self, FrtIndexReader *ir)
129
128
  return q;
130
129
  }
131
130
 
132
- static void wcq_destroy(FrtQuery *self)
133
- {
131
+ static void wcq_destroy(FrtQuery *self) {
134
132
  free(WCQ(self)->pattern);
135
133
  frt_q_destroy_i(self);
136
134
  }
137
135
 
138
- static unsigned long long wcq_hash(FrtQuery *self)
139
- {
136
+ static unsigned long long wcq_hash(FrtQuery *self) {
140
137
  return frt_str_hash(rb_id2name(WCQ(self)->field)) ^ frt_str_hash(WCQ(self)->pattern);
141
138
  }
142
139
 
143
- static int wcq_eq(FrtQuery *self, FrtQuery *o)
144
- {
140
+ static int wcq_eq(FrtQuery *self, FrtQuery *o) {
145
141
  return (strcmp(WCQ(self)->pattern, WCQ(o)->pattern) == 0)
146
142
  && (WCQ(self)->field == WCQ(o)->field);
147
143
  }
148
144
 
149
- FrtQuery *frt_wcq_new(FrtSymbol field, const char *pattern)
150
- {
151
- FrtQuery *self = frt_q_new(FrtWildCardQuery);
145
+ FrtQuery *frt_wcq_alloc(void) {
146
+ return frt_q_new(FrtWildCardQuery);
147
+ }
152
148
 
149
+ FrtQuery *frt_wcq_init(FrtQuery *self, ID field, const char *pattern) {
153
150
  WCQ(self)->field = field;
154
151
  WCQ(self)->pattern = frt_estrdup(pattern);
155
- FrtMTQMaxTerms(self) = FRT_WILD_CARD_QUERY_MAX_TERMS;
152
+ FrtMTQMaxTerms(self) = FRT_WILD_CARD_QUERY_MAX_TERMS;
156
153
 
157
154
  self->type = WILD_CARD_QUERY;
158
155
  self->rewrite = &wcq_rewrite;
@@ -164,3 +161,8 @@ FrtQuery *frt_wcq_new(FrtSymbol field, const char *pattern)
164
161
 
165
162
  return self;
166
163
  }
164
+
165
+ FrtQuery *frt_wcq_new(ID field, const char *pattern) {
166
+ FrtQuery *self = frt_wcq_alloc();
167
+ return frt_wcq_init(self, field, pattern);
168
+ }
@@ -1,8 +1,7 @@
1
1
  #include "frt_store.h"
2
2
  #include <string.h>
3
3
 
4
- static FrtRAMFile *rf_new(const char *name)
5
- {
4
+ static FrtRAMFile *rf_new(const char *name) {
6
5
  FrtRAMFile *rf = FRT_ALLOC(FrtRAMFile);
7
6
  rf->buffers = FRT_ALLOC(frt_uchar *);
8
7
  rf->buffers[0] = FRT_ALLOC_N(frt_uchar, FRT_BUFFER_SIZE);
@@ -13,16 +12,14 @@ static FrtRAMFile *rf_new(const char *name)
13
12
  return rf;
14
13
  }
15
14
 
16
- static void rf_extend_if_necessary(FrtRAMFile *rf, int buf_num)
17
- {
15
+ static void rf_extend_if_necessary(FrtRAMFile *rf, int buf_num) {
18
16
  while (rf->bufcnt <= buf_num) {
19
17
  FRT_REALLOC_N(rf->buffers, frt_uchar *, (rf->bufcnt + 1));
20
18
  rf->buffers[rf->bufcnt++] = FRT_ALLOC_N(frt_uchar, FRT_BUFFER_SIZE);
21
19
  }
22
20
  }
23
21
 
24
- static void rf_close(void *p)
25
- {
22
+ static void rf_close(void *p) {
26
23
  int i;
27
24
  FrtRAMFile *rf = (FrtRAMFile *)p;
28
25
  if (rf->ref_cnt > 0) {
@@ -36,38 +33,32 @@ static void rf_close(void *p)
36
33
  free(rf);
37
34
  }
38
35
 
39
- static void ram_touch(FrtStore *store, const char *filename)
40
- {
36
+ static void ram_touch(FrtStore *store, const char *filename) {
41
37
  if (frt_h_get(store->dir.ht, filename) == NULL) {
42
38
  frt_h_set(store->dir.ht, filename, rf_new(filename));
43
39
  }
44
40
  }
45
41
 
46
- static int ram_exists(FrtStore *store, const char *filename)
47
- {
42
+ static int ram_exists(FrtStore *store, const char *filename) {
48
43
  if (frt_h_get(store->dir.ht, filename) != NULL) {
49
44
  return true;
50
- }
51
- else {
45
+ } else {
52
46
  return false;
53
47
  }
54
48
  }
55
49
 
56
- static int ram_remove(FrtStore *store, const char *filename)
57
- {
50
+ static int ram_remove(FrtStore *store, const char *filename) {
58
51
  FrtRAMFile *rf = (FrtRAMFile *)frt_h_rem(store->dir.ht, filename, false);
59
52
  if (rf != NULL) {
60
53
  FRT_DEREF(rf);
61
54
  rf_close(rf);
62
55
  return true;
63
- }
64
- else {
56
+ } else {
65
57
  return false;
66
58
  }
67
59
  }
68
60
 
69
- static void ram_rename(FrtStore *store, const char *from, const char *to)
70
- {
61
+ static void ram_rename(FrtStore *store, const char *from, const char *to) {
71
62
  FrtRAMFile *rf = (FrtRAMFile *)frt_h_rem(store->dir.ht, from, false);
72
63
  FrtRAMFile *tmp;
73
64
 
@@ -89,14 +80,11 @@ static void ram_rename(FrtStore *store, const char *from, const char *to)
89
80
  frt_h_set(store->dir.ht, rf->name, rf);
90
81
  }
91
82
 
92
- static int ram_count(FrtStore *store)
93
- {
83
+ static int ram_count(FrtStore *store) {
94
84
  return store->dir.ht->size;
95
85
  }
96
86
 
97
- static void ram_each(FrtStore *store,
98
- void (*func)(const char *fname, void *arg), void *arg)
99
- {
87
+ static void ram_each(FrtStore *store, void (*func)(const char *fname, void *arg), void *arg) {
100
88
  FrtHash *ht = store->dir.ht;
101
89
  int i;
102
90
  for (i = 0; i <= ht->mask; i++) {
@@ -110,8 +98,7 @@ static void ram_each(FrtStore *store,
110
98
  }
111
99
  }
112
100
 
113
- static void ram_close_i(FrtStore *store)
114
- {
101
+ static void ram_close_i(FrtStore *store) {
115
102
  FrtHash *ht = store->dir.ht;
116
103
  int i;
117
104
  for (i = 0; i <= ht->mask; i++) {
@@ -127,8 +114,7 @@ static void ram_close_i(FrtStore *store)
127
114
  /*
128
115
  * Be sure to keep the locks
129
116
  */
130
- static void ram_clear(FrtStore *store)
131
- {
117
+ static void ram_clear(FrtStore *store) {
132
118
  int i;
133
119
  FrtHash *ht = store->dir.ht;
134
120
  for (i = 0; i <= ht->mask; i++) {
@@ -140,8 +126,7 @@ static void ram_clear(FrtStore *store)
140
126
  }
141
127
  }
142
128
 
143
- static void ram_clear_locks(FrtStore *store)
144
- {
129
+ static void ram_clear_locks(FrtStore *store) {
145
130
  int i;
146
131
  FrtHash *ht = store->dir.ht;
147
132
  for (i = 0; i <= ht->mask; i++) {
@@ -153,8 +138,7 @@ static void ram_clear_locks(FrtStore *store)
153
138
  }
154
139
  }
155
140
 
156
- static void ram_clear_all(FrtStore *store)
157
- {
141
+ static void ram_clear_all(FrtStore *store) {
158
142
  int i;
159
143
  FrtHash *ht = store->dir.ht;
160
144
  for (i = 0; i <= ht->mask; i++) {
@@ -166,19 +150,16 @@ static void ram_clear_all(FrtStore *store)
166
150
  }
167
151
  }
168
152
 
169
- static off_t ram_length(FrtStore *store, const char *filename)
170
- {
153
+ static off_t ram_length(FrtStore *store, const char *filename) {
171
154
  FrtRAMFile *rf = (FrtRAMFile *)frt_h_get(store->dir.ht, filename);
172
155
  if (rf != NULL) {
173
156
  return rf->len;
174
- }
175
- else {
157
+ } else {
176
158
  return 0;
177
159
  }
178
160
  }
179
161
 
180
- static void ramo_flush_i(FrtOutStream *os, const frt_uchar *src, int len)
181
- {
162
+ static void ramo_flush_i(FrtOutStream *os, const frt_uchar *src, int len) {
182
163
  if (len == 0) { return; }
183
164
  frt_uchar *buffer;
184
165
  FrtRAMFile *rf = os->file.rf;
@@ -212,26 +193,22 @@ static void ramo_flush_i(FrtOutStream *os, const frt_uchar *src, int len)
212
193
  }
213
194
  }
214
195
 
215
- static void ramo_seek_i(FrtOutStream *os, off_t pos)
216
- {
196
+ static void ramo_seek_i(FrtOutStream *os, off_t pos) {
217
197
  os->pointer = pos;
218
198
  }
219
199
 
220
- void frt_ramo_reset(FrtOutStream *os)
221
- {
200
+ void frt_ramo_reset(FrtOutStream *os) {
222
201
  frt_os_seek(os, 0);
223
202
  os->file.rf->len = 0;
224
203
  }
225
204
 
226
- static void ramo_close_i(FrtOutStream *os)
227
- {
205
+ static void ramo_close_i(FrtOutStream *os) {
228
206
  FrtRAMFile *rf = os->file.rf;
229
207
  FRT_DEREF(rf);
230
208
  rf_close(rf);
231
209
  }
232
210
 
233
- void frt_ramo_write_to(FrtOutStream *os, FrtOutStream *other_o)
234
- {
211
+ void frt_ramo_write_to(FrtOutStream *os, FrtOutStream *other_o) {
235
212
  int i, len;
236
213
  FrtRAMFile *rf = os->file.rf;
237
214
  int last_buffer_number;
@@ -252,8 +229,7 @@ static const struct FrtOutStreamMethods RAM_OUT_STREAM_METHODS = {
252
229
  ramo_close_i
253
230
  };
254
231
 
255
- FrtOutStream *frt_ram_new_buffer()
256
- {
232
+ FrtOutStream *frt_ram_new_buffer(void) {
257
233
  FrtRAMFile *rf = rf_new("");
258
234
  FrtOutStream *os = frt_os_new();
259
235
 
@@ -264,14 +240,12 @@ FrtOutStream *frt_ram_new_buffer()
264
240
  return os;
265
241
  }
266
242
 
267
- void frt_ram_destroy_buffer(FrtOutStream *os)
268
- {
243
+ void frt_ram_destroy_buffer(FrtOutStream *os) {
269
244
  rf_close(os->file.rf);
270
245
  free(os);
271
246
  }
272
247
 
273
- static FrtOutStream *ram_new_output(FrtStore *store, const char *filename)
274
- {
248
+ static FrtOutStream *ram_new_output(FrtStore *store, const char *filename) {
275
249
  FrtRAMFile *rf = (FrtRAMFile *)frt_h_get(store->dir.ht, filename);
276
250
  FrtOutStream *os = frt_os_new();
277
251
 
@@ -286,8 +260,7 @@ static FrtOutStream *ram_new_output(FrtStore *store, const char *filename)
286
260
  return os;
287
261
  }
288
262
 
289
- static void rami_read_i(FrtInStream *is, frt_uchar *b, int len)
290
- {
263
+ static void rami_read_i(FrtInStream *is, frt_uchar *b, int len) {
291
264
  FrtRAMFile *rf = is->file.rf;
292
265
 
293
266
  int offset = 0;
@@ -303,8 +276,7 @@ static void rami_read_i(FrtInStream *is, frt_uchar *b, int len)
303
276
 
304
277
  if (bytes_in_buffer >= remainder) {
305
278
  bytes_to_copy = remainder;
306
- }
307
- else {
279
+ } else {
308
280
  bytes_to_copy = bytes_in_buffer;
309
281
  }
310
282
  buffer = rf->buffers[buffer_number];
@@ -317,18 +289,15 @@ static void rami_read_i(FrtInStream *is, frt_uchar *b, int len)
317
289
  is->d.pointer += len;
318
290
  }
319
291
 
320
- static off_t rami_length_i(FrtInStream *is)
321
- {
292
+ static off_t rami_length_i(FrtInStream *is) {
322
293
  return is->file.rf->len;
323
294
  }
324
295
 
325
- static void rami_seek_i(FrtInStream *is, off_t pos)
326
- {
296
+ static void rami_seek_i(FrtInStream *is, off_t pos) {
327
297
  is->d.pointer = pos;
328
298
  }
329
299
 
330
- static void rami_close_i(FrtInStream *is)
331
- {
300
+ static void rami_close_i(FrtInStream *is) {
332
301
  FrtRAMFile *rf = is->file.rf;
333
302
  FRT_DEREF(rf);
334
303
  rf_close(rf);
@@ -341,8 +310,7 @@ static const struct FrtInStreamMethods RAM_IN_STREAM_METHODS = {
341
310
  rami_close_i
342
311
  };
343
312
 
344
- static FrtInStream *ram_open_input(FrtStore *store, const char *filename)
345
- {
313
+ static FrtInStream *ram_open_input(FrtStore *store, const char *filename) {
346
314
  FrtRAMFile *rf = (FrtRAMFile *)frt_h_get(store->dir.ht, filename);
347
315
  FrtInStream *is = NULL;
348
316
 
@@ -360,8 +328,7 @@ static FrtInStream *ram_open_input(FrtStore *store, const char *filename)
360
328
 
361
329
  #define LOCK_OBTAIN_TIMEOUT 5
362
330
 
363
- static int ram_lock_obtain(FrtLock *lock)
364
- {
331
+ static int ram_lock_obtain(FrtLock *lock) {
365
332
  int ret = true;
366
333
  if (ram_exists(lock->store, lock->name)) {
367
334
  ret = false;
@@ -370,18 +337,15 @@ static int ram_lock_obtain(FrtLock *lock)
370
337
  return ret;
371
338
  }
372
339
 
373
- static int ram_lock_is_locked(FrtLock *lock)
374
- {
340
+ static int ram_lock_is_locked(FrtLock *lock) {
375
341
  return ram_exists(lock->store, lock->name);
376
342
  }
377
343
 
378
- static void ram_lock_release(FrtLock *lock)
379
- {
344
+ static void ram_lock_release(FrtLock *lock) {
380
345
  ram_remove(lock->store, lock->name);
381
346
  }
382
347
 
383
- static FrtLock *ram_open_lock_i(FrtStore *store, const char *lockname)
384
- {
348
+ static FrtLock *ram_open_lock_i(FrtStore *store, const char *lockname) {
385
349
  FrtLock *lock = FRT_ALLOC(FrtLock);
386
350
  char lname[100];
387
351
  snprintf(lname, 100, "%s%s.lck", FRT_LOCK_PREFIX, lockname);
@@ -390,19 +354,19 @@ static FrtLock *ram_open_lock_i(FrtStore *store, const char *lockname)
390
354
  lock->obtain = &ram_lock_obtain;
391
355
  lock->release = &ram_lock_release;
392
356
  lock->is_locked = &ram_lock_is_locked;
357
+ lock->rlock = Qnil;
393
358
  return lock;
394
359
  }
395
360
 
396
- static void ram_close_lock_i(FrtLock *lock)
397
- {
361
+ static void ram_close_lock_i(FrtLock *lock) {
398
362
  free(lock->name);
399
363
  free(lock);
400
364
  }
401
365
 
402
-
403
- FrtStore *frt_open_ram_store()
404
- {
405
- FrtStore *new_store = frt_store_new();
366
+ FrtStore *frt_open_ram_store(FrtStore *new_store) {
367
+ if (new_store == NULL)
368
+ new_store = frt_store_alloc();
369
+ frt_store_init(new_store);
406
370
 
407
371
  new_store->dir.ht = frt_h_new_str(NULL, rf_close);
408
372
  new_store->touch = &ram_touch;
@@ -423,13 +387,11 @@ FrtStore *frt_open_ram_store()
423
387
  return new_store;
424
388
  }
425
389
 
426
- struct CopyFileArg
427
- {
390
+ struct CopyFileArg {
428
391
  FrtStore *to_store, *from_store;
429
392
  };
430
393
 
431
- static void copy_files(const char *fname, void *arg)
432
- {
394
+ static void copy_files(const char *fname, void *arg) {
433
395
  struct CopyFileArg *cfa = (struct CopyFileArg *)arg;
434
396
  FrtOutStream *os = cfa->to_store->new_output(cfa->to_store, fname);
435
397
  FrtInStream *is = cfa->from_store->open_input(cfa->from_store, fname);
@@ -444,9 +406,8 @@ static void copy_files(const char *fname, void *arg)
444
406
  free(buffer);
445
407
  }
446
408
 
447
- FrtStore *frt_open_ram_store_and_copy(FrtStore *from_store, bool close_dir)
448
- {
449
- FrtStore *store = frt_open_ram_store();
409
+ FrtStore *frt_open_ram_store_and_copy(FrtStore *store, FrtStore *from_store, bool close_dir) {
410
+ store = frt_open_ram_store(store);
450
411
  struct CopyFileArg cfa;
451
412
  cfa.to_store = store;
452
413
  cfa.from_store = from_store;