isomorfeus-ferret 0.12.7 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -3,6 +3,9 @@
3
3
  #include "frt_search.h"
4
4
  #include "frt_helper.h"
5
5
 
6
+ #undef close
7
+ #undef read
8
+
6
9
  #define MTQ(query) ((FrtMultiTermQuery *)(query))
7
10
 
8
11
  /***************************************************************************
@@ -15,14 +18,12 @@
15
18
  * BoostedTerm
16
19
  ***************************************************************************/
17
20
 
18
- typedef struct BoostedTerm
19
- {
20
- char *term;
21
+ typedef struct BoostedTerm {
22
+ char *term;
21
23
  float boost;
22
24
  } BoostedTerm;
23
25
 
24
- static bool boosted_term_less_than(const BoostedTerm *bt1, const BoostedTerm *bt2)
25
- {
26
+ static bool boosted_term_less_than(const BoostedTerm *bt1, const BoostedTerm *bt2) {
26
27
  // if (bt1->boost == bt2->boost) { return (strcmp(bt1->term, bt2->term) < 0); }
27
28
  // return (bt1->boost < bt2->boost);
28
29
  if (bt1->boost < bt2->boost) {
@@ -34,14 +35,12 @@ static bool boosted_term_less_than(const BoostedTerm *bt1, const BoostedTerm *bt
34
35
  return (strcmp(bt1->term, bt2->term) < 0);
35
36
  }
36
37
 
37
- static void boosted_term_destroy(BoostedTerm *self)
38
- {
38
+ static void boosted_term_destroy(BoostedTerm *self) {
39
39
  free(self->term);
40
40
  free(self);
41
41
  }
42
42
 
43
- static BoostedTerm *boosted_term_new(const char *term, float boost)
44
- {
43
+ static BoostedTerm *boosted_term_new(const char *term, float boost) {
45
44
  BoostedTerm *self = FRT_ALLOC(BoostedTerm);
46
45
  self->term = frt_estrdup(term);
47
46
  self->boost = boost;
@@ -54,9 +53,8 @@ static BoostedTerm *boosted_term_new(const char *term, float boost)
54
53
 
55
54
  #define TDE_READ_SIZE 16
56
55
 
57
- typedef struct TermDocEnumWrapper
58
- {
59
- const char *term;
56
+ typedef struct TermDocEnumWrapper {
57
+ const char *term;
60
58
  FrtTermDocEnum *tde;
61
59
  float boost;
62
60
  int doc;
@@ -67,14 +65,11 @@ typedef struct TermDocEnumWrapper
67
65
  int pointer_max;
68
66
  } TermDocEnumWrapper;
69
67
 
70
- static bool tdew_less_than(const TermDocEnumWrapper *tdew1,
71
- const TermDocEnumWrapper *tdew2)
72
- {
68
+ static bool tdew_less_than(const TermDocEnumWrapper *tdew1, const TermDocEnumWrapper *tdew2) {
73
69
  return (tdew1->doc < tdew2->doc);
74
70
  }
75
71
 
76
- static bool tdew_next(TermDocEnumWrapper *self)
77
- {
72
+ static bool tdew_next(TermDocEnumWrapper *self) {
78
73
  self->pointer++;
79
74
  if (self->pointer >= self->pointer_max) {
80
75
  /* refill buffer */
@@ -91,8 +86,7 @@ static bool tdew_next(TermDocEnumWrapper *self)
91
86
  return true;
92
87
  }
93
88
 
94
- static bool tdew_skip_to(TermDocEnumWrapper *self, int doc_num)
95
- {
89
+ static bool tdew_skip_to(TermDocEnumWrapper *self, int doc_num) {
96
90
  FrtTermDocEnum *tde = self->tde;
97
91
 
98
92
  while (++(self->pointer) < self->pointer_max) {
@@ -115,15 +109,12 @@ static bool tdew_skip_to(TermDocEnumWrapper *self, int doc_num)
115
109
  }
116
110
  }
117
111
 
118
- static void tdew_destroy(TermDocEnumWrapper *self)
119
- {
112
+ static void tdew_destroy(TermDocEnumWrapper *self) {
120
113
  self->tde->close(self->tde);
121
114
  free(self);
122
115
  }
123
116
 
124
- static TermDocEnumWrapper *tdew_new(const char *term, FrtTermDocEnum *tde,
125
- float boost)
126
- {
117
+ static TermDocEnumWrapper *tdew_new(const char *term, FrtTermDocEnum *tde, float boost) {
127
118
  TermDocEnumWrapper *self = FRT_ALLOC_AND_ZERO(TermDocEnumWrapper);
128
119
  self->term = term;
129
120
  self->tde = tde;
@@ -139,28 +130,25 @@ static TermDocEnumWrapper *tdew_new(const char *term, FrtTermDocEnum *tde,
139
130
  #define SCORE_CACHE_SIZE 32
140
131
  #define MTSc(scorer) ((MultiTermScorer *)(scorer))
141
132
 
142
- typedef struct MultiTermScorer
143
- {
144
- FrtScorer super;
145
- FrtSymbol field;
146
- frt_uchar *norms;
147
- FrtWeight *weight;
148
- TermDocEnumWrapper **tdew_a;
149
- int tdew_cnt;
150
- FrtPriorityQueue *tdew_pq;
151
- float weight_value;
152
- float score_cache[SCORE_CACHE_SIZE];
153
- float total_score;
133
+ typedef struct MultiTermScorer {
134
+ FrtScorer super;
135
+ ID field;
136
+ frt_uchar *norms;
137
+ FrtWeight *weight;
138
+ TermDocEnumWrapper **tdew_a;
139
+ int tdew_cnt;
140
+ FrtPriorityQueue *tdew_pq;
141
+ float weight_value;
142
+ float score_cache[SCORE_CACHE_SIZE];
143
+ float total_score;
154
144
  } MultiTermScorer;
155
145
 
156
- static float multi_tsc_score(FrtScorer *self)
157
- {
146
+ static float multi_tsc_score(FrtScorer *self) {
158
147
  return MTSc(self)->total_score * MTSc(self)->weight_value
159
148
  * frt_sim_decode_norm(self->similarity, MTSc(self)->norms[self->doc]);
160
149
  }
161
150
 
162
- static bool multi_tsc_next(FrtScorer *self)
163
- {
151
+ static bool multi_tsc_next(FrtScorer *self) {
164
152
  int curr_doc;
165
153
  float total_score = 0.0f;
166
154
  TermDocEnumWrapper *tdew;
@@ -188,15 +176,13 @@ static bool multi_tsc_next(FrtScorer *self)
188
176
  int freq = tdew->freq;
189
177
  if (freq < SCORE_CACHE_SIZE) {
190
178
  total_score += mtsc->score_cache[freq] * tdew->boost;
191
- }
192
- else {
179
+ } else {
193
180
  total_score += frt_sim_tf(self->similarity, (float)freq) * tdew->boost;
194
181
  }
195
182
 
196
183
  if (tdew_next(tdew)) {
197
184
  frt_pq_down(tdew_pq);
198
- }
199
- else {
185
+ } else {
200
186
  frt_pq_pop(tdew_pq);
201
187
  }
202
188
 
@@ -206,8 +192,7 @@ static bool multi_tsc_next(FrtScorer *self)
206
192
  return true;
207
193
  }
208
194
 
209
- static bool multi_tsc_advance_to(FrtScorer *self, int target_doc_num)
210
- {
195
+ static bool multi_tsc_advance_to(FrtScorer *self, int target_doc_num) {
211
196
  FrtPriorityQueue *tdew_pq = MTSc(self)->tdew_pq;
212
197
  TermDocEnumWrapper *tdew;
213
198
  if (tdew_pq == NULL) {
@@ -230,8 +215,7 @@ static bool multi_tsc_advance_to(FrtScorer *self, int target_doc_num)
230
215
  && (target_doc_num > tdew->doc)) {
231
216
  if (tdew_skip_to(tdew, target_doc_num)) {
232
217
  frt_pq_down(tdew_pq);
233
- }
234
- else {
218
+ } else {
235
219
  frt_pq_pop(tdew_pq);
236
220
  }
237
221
  }
@@ -239,13 +223,11 @@ static bool multi_tsc_advance_to(FrtScorer *self, int target_doc_num)
239
223
  return (frt_pq_top(tdew_pq) == NULL) ? false : true;
240
224
  }
241
225
 
242
- static bool multi_tsc_skip_to(FrtScorer *self, int target_doc_num)
243
- {
226
+ static bool multi_tsc_skip_to(FrtScorer *self, int target_doc_num) {
244
227
  return multi_tsc_advance_to(self, target_doc_num) && multi_tsc_next(self);
245
228
  }
246
229
 
247
- static FrtExplanation *multi_tsc_explain(FrtScorer *self, int doc_num)
248
- {
230
+ static FrtExplanation *multi_tsc_explain(FrtScorer *self, int doc_num) {
249
231
  MultiTermScorer *mtsc = MTSc(self);
250
232
  TermDocEnumWrapper *tdew;
251
233
 
@@ -270,8 +252,7 @@ static FrtExplanation *multi_tsc_explain(FrtScorer *self, int doc_num)
270
252
  * again */
271
253
  if (tdew_next(tdew)) {
272
254
  frt_pq_down(tdew_pq);
273
- }
274
- else {
255
+ } else {
275
256
  frt_pq_pop(tdew_pq);
276
257
  }
277
258
 
@@ -279,14 +260,12 @@ static FrtExplanation *multi_tsc_explain(FrtScorer *self, int doc_num)
279
260
  && tdew->doc == curr_doc);
280
261
  expl->value = total_score;
281
262
  return expl;
282
- }
283
- else {
263
+ } else {
284
264
  return frt_expl_new(0.0f, "None of the required terms exist in the index");
285
265
  }
286
266
  }
287
267
 
288
- static void multi_tsc_destroy(FrtScorer *self)
289
- {
268
+ static void multi_tsc_destroy(FrtScorer *self) {
290
269
  int i;
291
270
  TermDocEnumWrapper **tdew_a = MTSc(self)->tdew_a;
292
271
  for (i = MTSc(self)->tdew_cnt - 1; i >= 0; i--) {
@@ -297,10 +276,7 @@ static void multi_tsc_destroy(FrtScorer *self)
297
276
  frt_scorer_destroy_i(self);
298
277
  }
299
278
 
300
- static FrtScorer *multi_tsc_new(FrtWeight *weight, FrtSymbol field,
301
- TermDocEnumWrapper **tdew_a, int tdew_cnt,
302
- frt_uchar *norms)
303
- {
279
+ static FrtScorer *multi_tsc_new(FrtWeight *weight, ID field, TermDocEnumWrapper **tdew_a, int tdew_cnt, frt_uchar *norms) {
304
280
  int i;
305
281
  FrtScorer *self = frt_scorer_new(MultiTermScorer, weight->similarity);
306
282
 
@@ -328,13 +304,11 @@ static FrtScorer *multi_tsc_new(FrtWeight *weight, FrtSymbol field,
328
304
  * MultiTermWeight
329
305
  ***************************************************************************/
330
306
 
331
- static char *multi_tw_to_s(FrtWeight *self)
332
- {
307
+ static char *multi_tw_to_s(FrtWeight *self) {
333
308
  return frt_strfmt("MultiTermWeight(%f)", self->value);
334
309
  }
335
310
 
336
- static FrtScorer *multi_tw_scorer(FrtWeight *self, FrtIndexReader *ir)
337
- {
311
+ static FrtScorer *multi_tw_scorer(FrtWeight *self, FrtIndexReader *ir) {
338
312
  FrtScorer *multi_tsc = NULL;
339
313
  FrtPriorityQueue *boosted_terms = MTQ(self->query)->boosted_terms;
340
314
  const int field_num = frt_fis_get_field_num(ir->fis, MTQ(self->query)->field);
@@ -360,16 +334,14 @@ static FrtScorer *multi_tw_scorer(FrtWeight *self, FrtIndexReader *ir)
360
334
  if (tdew_cnt) {
361
335
  multi_tsc = multi_tsc_new(self, MTQ(self->query)->field, tdew_a,
362
336
  tdew_cnt, frt_ir_get_norms_i(ir, field_num));
363
- }
364
- else {
337
+ } else {
365
338
  free(tdew_a);
366
339
  }
367
340
  }
368
341
  return multi_tsc;
369
342
  }
370
343
 
371
- static FrtExplanation *multi_tw_explain(FrtWeight *self, FrtIndexReader *ir, int doc_num)
372
- {
344
+ static FrtExplanation *multi_tw_explain(FrtWeight *self, FrtIndexReader *ir, int doc_num) {
373
345
  FrtExplanation *expl;
374
346
  FrtExplanation *idf_expl1;
375
347
  FrtExplanation *idf_expl2;
@@ -397,7 +369,7 @@ static FrtExplanation *multi_tw_explain(FrtWeight *self, FrtIndexReader *ir, int
397
369
  field_name);
398
370
  }
399
371
 
400
- query_str = self->query->to_s(self->query, (FrtSymbol)NULL);
372
+ query_str = self->query->to_s(self->query, (ID)NULL);
401
373
 
402
374
  expl = frt_expl_new(0.0f, "weight(%s in %d), product of:", query_str, doc_num);
403
375
 
@@ -442,8 +414,7 @@ static FrtExplanation *multi_tw_explain(FrtWeight *self, FrtIndexReader *ir, int
442
414
  if ((scorer = self->scorer(self, ir)) != NULL) {
443
415
  tf_expl = scorer->explain(scorer, doc_num);
444
416
  scorer->destroy(scorer);
445
- }
446
- else {
417
+ } else {
447
418
  tf_expl = frt_expl_new(0.0f, "no terms were found");
448
419
  }
449
420
  frt_expl_add_detail(field_expl, tf_expl);
@@ -464,16 +435,14 @@ static FrtExplanation *multi_tw_explain(FrtWeight *self, FrtIndexReader *ir, int
464
435
  if (query_expl->value == 1.0f) {
465
436
  frt_expl_destroy(expl);
466
437
  return field_expl;
467
- }
468
- else {
438
+ } else {
469
439
  expl->value = (query_expl->value * field_expl->value);
470
440
  frt_expl_add_detail(expl, field_expl);
471
441
  return expl;
472
442
  }
473
443
  }
474
444
 
475
- static FrtWeight *multi_tw_new(FrtQuery *query, FrtSearcher *searcher)
476
- {
445
+ static FrtWeight *multi_tw_new(FrtQuery *query, FrtSearcher *searcher) {
477
446
  int i;
478
447
  int doc_freq = 0;
479
448
  FrtWeight *self = w_new(FrtWeight, query);
@@ -502,8 +471,7 @@ static FrtWeight *multi_tw_new(FrtQuery *query, FrtSearcher *searcher)
502
471
  * MultiTermQuery
503
472
  ***************************************************************************/
504
473
 
505
- static char *multi_tq_to_s(FrtQuery *self, FrtSymbol default_field)
506
- {
474
+ static char *multi_tq_to_s(FrtQuery *self, ID default_field) {
507
475
  int i;
508
476
  FrtPriorityQueue *boosted_terms = MTQ(self)->boosted_terms, *bt_pq_clone;
509
477
  BoostedTerm *bt;
@@ -551,14 +519,12 @@ static char *multi_tq_to_s(FrtQuery *self, FrtSymbol default_field)
551
519
  return buffer;
552
520
  }
553
521
 
554
- static void multi_tq_destroy_i(FrtQuery *self)
555
- {
522
+ static void multi_tq_destroy_i(FrtQuery *self) {
556
523
  frt_pq_destroy(MTQ(self)->boosted_terms);
557
524
  frt_q_destroy_i(self);
558
525
  }
559
526
 
560
- static void multi_tq_extract_terms(FrtQuery *self, FrtHashSet *terms)
561
- {
527
+ static void multi_tq_extract_terms(FrtQuery *self, FrtHashSet *terms) {
562
528
  int i;
563
529
  FrtPriorityQueue *boosted_terms = MTQ(self)->boosted_terms;
564
530
  for (i = boosted_terms->size; i > 0; i--) {
@@ -567,8 +533,7 @@ static void multi_tq_extract_terms(FrtQuery *self, FrtHashSet *terms)
567
533
  }
568
534
  }
569
535
 
570
- static unsigned long long multi_tq_hash(FrtQuery *self)
571
- {
536
+ static unsigned long long multi_tq_hash(FrtQuery *self) {
572
537
  int i;
573
538
  unsigned long long hash = frt_str_hash(rb_id2name(MTQ(self)->field));
574
539
  FrtPriorityQueue *boosted_terms = MTQ(self)->boosted_terms;
@@ -579,8 +544,7 @@ static unsigned long long multi_tq_hash(FrtQuery *self)
579
544
  return hash;
580
545
  }
581
546
 
582
- static int multi_tq_eq(FrtQuery *self, FrtQuery *o)
583
- {
547
+ static int multi_tq_eq(FrtQuery *self, FrtQuery *o) {
584
548
  int i;
585
549
  FrtPriorityQueue *boosted_terms1 = MTQ(self)->boosted_terms;
586
550
  FrtPriorityQueue *boosted_terms2 = MTQ(o)->boosted_terms;
@@ -599,9 +563,7 @@ static int multi_tq_eq(FrtQuery *self, FrtQuery *o)
599
563
  return true;
600
564
  }
601
565
 
602
- static FrtMatchVector *multi_tq_get_matchv_i(FrtQuery *self, FrtMatchVector *mv,
603
- FrtTermVector *tv)
604
- {
566
+ static FrtMatchVector *multi_tq_get_matchv_i(FrtQuery *self, FrtMatchVector *mv, FrtTermVector *tv) {
605
567
  if (tv->field == MTQ(self)->field) {
606
568
  int i;
607
569
  FrtPriorityQueue *boosted_terms = MTQ(self)->boosted_terms;
@@ -620,17 +582,16 @@ static FrtMatchVector *multi_tq_get_matchv_i(FrtQuery *self, FrtMatchVector *mv,
620
582
  return mv;
621
583
  }
622
584
 
623
- FrtQuery *frt_multi_tq_new_conf(FrtSymbol field, int max_terms, float min_boost)
624
- {
625
- FrtQuery *self;
585
+ FrtQuery *frt_multi_tq_alloc(void) {
586
+ return frt_q_new(FrtMultiTermQuery);
587
+ }
626
588
 
589
+ FrtQuery *frt_multi_tq_init_conf(FrtQuery *self, ID field, int max_terms, float min_boost) {
627
590
  if (max_terms <= 0) {
628
- FRT_RAISE(FRT_ARG_ERROR, ":max_terms must be greater than or equal to zero. "
629
- "%d < 0. ", max_terms);
591
+ FRT_RAISE(FRT_ARG_ERROR, ":max_terms must be greater than or equal to zero. %d < 0. ", max_terms);
592
+ free(self);
630
593
  }
631
594
 
632
- self = frt_q_new(FrtMultiTermQuery);
633
-
634
595
  MTQ(self)->field = field;
635
596
  MTQ(self)->boosted_terms = frt_pq_new(max_terms,
636
597
  (frt_lt_ft)&boosted_term_less_than,
@@ -649,13 +610,16 @@ FrtQuery *frt_multi_tq_new_conf(FrtSymbol field, int max_terms, float min_boost)
649
610
  return self;
650
611
  }
651
612
 
652
- FrtQuery *frt_multi_tq_new(FrtSymbol field)
653
- {
613
+ FrtQuery *frt_multi_tq_new_conf(ID field, int max_terms, float min_boost) {
614
+ FrtQuery *self = frt_multi_tq_alloc();
615
+ return frt_multi_tq_init_conf(self, field, max_terms, min_boost);
616
+ }
617
+
618
+ FrtQuery *frt_multi_tq_new(ID field) {
654
619
  return frt_multi_tq_new_conf(field, MULTI_TERM_QUERY_MAX_TERMS, 0.0f);
655
620
  }
656
621
 
657
- void frt_multi_tq_add_term_boost(FrtQuery *self, const char *term, float boost)
658
- {
622
+ void frt_multi_tq_add_term_boost(FrtQuery *self, const char *term, float boost) {
659
623
  if (boost > MTQ(self)->min_boost && term && term[0]) {
660
624
  BoostedTerm *bt = boosted_term_new(term, boost);
661
625
  FrtPriorityQueue *bt_pq = MTQ(self)->boosted_terms;
@@ -666,7 +630,6 @@ void frt_multi_tq_add_term_boost(FrtQuery *self, const char *term, float boost)
666
630
  }
667
631
  }
668
632
 
669
- void frt_multi_tq_add_term(FrtQuery *self, const char *term)
670
- {
633
+ void frt_multi_tq_add_term(FrtQuery *self, const char *term) {
671
634
  frt_multi_tq_add_term_boost(self, term, 1.0f);
672
635
  }