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
@@ -2,7 +2,9 @@
2
2
  #include "frt_array.h"
3
3
  #include "frt_search.h"
4
4
  #include "isomorfeus_ferret.h"
5
- #include <ruby/st.h>
5
+ #include <ruby.h>
6
+
7
+ #undef close
6
8
 
7
9
  VALUE mSearch;
8
10
 
@@ -125,11 +127,10 @@ static VALUE sym_pre_tag;
125
127
  static VALUE sym_post_tag;
126
128
  static VALUE sym_ellipsis;
127
129
 
128
- static FrtSymbol fsym_id;
130
+ static ID fsym_id;
129
131
 
130
132
  extern VALUE cIndexReader;
131
- extern void frb_ir_free(void *p);
132
- extern void frb_ir_mark(void *p);
133
+ extern const rb_data_type_t frb_index_reader_t;
133
134
 
134
135
  extern void frb_set_term(VALUE rterm, FrtTerm *t);
135
136
  extern VALUE frb_get_analyzer(FrtAnalyzer *a);
@@ -143,13 +144,8 @@ extern VALUE frb_get_lazy_doc(FrtLazyDoc *lazy_doc);
143
144
  *
144
145
  ****************************************************************************/
145
146
 
146
- static VALUE
147
- frb_get_hit(FrtHit *hit)
148
- {
149
- return rb_struct_new(cHit,
150
- INT2FIX(hit->doc),
151
- rb_float_new((double)hit->score),
152
- NULL);
147
+ static VALUE frb_get_hit(FrtHit *hit) {
148
+ return rb_struct_new(cHit, INT2FIX(hit->doc), rb_float_new((double)hit->score), NULL);
153
149
  }
154
150
 
155
151
  /****************************************************************************
@@ -158,9 +154,7 @@ frb_get_hit(FrtHit *hit)
158
154
  *
159
155
  ****************************************************************************/
160
156
 
161
- static VALUE
162
- frb_get_td(FrtTopDocs *td, VALUE rsearcher)
163
- {
157
+ static VALUE frb_get_td(FrtTopDocs *td, VALUE rsearcher) {
164
158
  int i;
165
159
  VALUE rtop_docs;
166
160
  VALUE hit_ary = rb_ary_new2(td->size);
@@ -169,12 +163,8 @@ frb_get_td(FrtTopDocs *td, VALUE rsearcher)
169
163
  rb_ary_store(hit_ary, i, frb_get_hit(td->hits[i]));
170
164
  }
171
165
 
172
- rtop_docs = rb_struct_new(cTopDocs,
173
- INT2FIX(td->total_hits),
174
- hit_ary,
175
- rb_float_new((double)td->max_score),
176
- rsearcher,
177
- NULL);
166
+ rtop_docs = rb_struct_new(cTopDocs, INT2FIX(td->total_hits), hit_ary,
167
+ rb_float_new((double)td->max_score), rsearcher, NULL);
178
168
  frt_td_destroy(td);
179
169
  return rtop_docs;
180
170
  }
@@ -185,9 +175,7 @@ frb_get_td(FrtTopDocs *td, VALUE rsearcher)
185
175
  *
186
176
  * Returns a string representation of the top_doc in readable format.
187
177
  */
188
- static VALUE
189
- frb_td_to_s(int argc, VALUE *argv, VALUE self)
190
- {
178
+ static VALUE frb_td_to_s(int argc, VALUE *argv, VALUE self) {
191
179
  int i;
192
180
  VALUE rhits = rb_funcall(self, id_hits, 0);
193
181
  FrtSearcher *sea = (FrtSearcher *)DATA_PTR(rb_funcall(self, id_searcher, 0));
@@ -195,7 +183,7 @@ frb_td_to_s(int argc, VALUE *argv, VALUE self)
195
183
  unsigned int capa = len * 64 + 100;
196
184
  int p = 0;
197
185
  char *str = FRT_ALLOC_N(char, len * 64 + 100);
198
- FrtSymbol field = fsym_id;
186
+ ID field = fsym_id;
199
187
  VALUE rstr;
200
188
 
201
189
  if (argc) {
@@ -235,9 +223,7 @@ frb_td_to_s(int argc, VALUE *argv, VALUE self)
235
223
  return rstr;
236
224
  }
237
225
 
238
- static char *
239
- frb_lzd_load_to_json(FrtLazyDoc *lzd, char **str, char *s, int *slen)
240
- {
226
+ static char *frb_lzd_load_to_json(FrtLazyDoc *lzd, char **str, char *s, int *slen) {
241
227
  int i, j;
242
228
  int diff = s - *str;
243
229
  int len = diff, l;
@@ -285,9 +271,7 @@ frb_lzd_load_to_json(FrtLazyDoc *lzd, char **str, char *s, int *slen)
285
271
  *
286
272
  * Returns a json representation of the top_doc.
287
273
  */
288
- static VALUE
289
- frb_td_to_json(VALUE self)
290
- {
274
+ static VALUE frb_td_to_json(VALUE self) {
291
275
  int i;
292
276
  VALUE rhits = rb_funcall(self, id_hits, 0);
293
277
  VALUE rhit;
@@ -333,9 +317,7 @@ frb_td_to_json(VALUE self)
333
317
  *
334
318
  * Returns a string representation of the explanation in readable format.
335
319
  */
336
- static VALUE
337
- frb_expl_to_s(VALUE self)
338
- {
320
+ static VALUE frb_expl_to_s(VALUE self) {
339
321
  GET_EXPL();
340
322
  char *str = frt_expl_to_s(expl);
341
323
  VALUE rstr = rb_str_new2(str);
@@ -349,9 +331,7 @@ frb_expl_to_s(VALUE self)
349
331
  *
350
332
  * Returns an html representation of the explanation in readable format.
351
333
  */
352
- static VALUE
353
- frb_expl_to_html(VALUE self)
354
- {
334
+ static VALUE frb_expl_to_html(VALUE self) {
355
335
  GET_EXPL();
356
336
  char *str = frt_expl_to_html(expl);
357
337
  VALUE rstr = rb_str_new2(str);
@@ -367,9 +347,7 @@ frb_expl_to_html(VALUE self)
367
347
  * purposes mainly to check that the score returned by the explanation
368
348
  * matches that of the score for the document in the original query.
369
349
  */
370
- static VALUE
371
- frb_expl_score(VALUE self)
372
- {
350
+ static VALUE frb_expl_score(VALUE self) {
373
351
  GET_EXPL();
374
352
  return rb_float_new((double)expl->value);
375
353
  }
@@ -380,15 +358,10 @@ frb_expl_score(VALUE self)
380
358
  *
381
359
  ****************************************************************************/
382
360
 
383
- static void
384
- frb_q_free(void *p)
385
- {
386
- object_del(p);
361
+ static void frb_q_free(void *p) {
387
362
  frt_q_deref((FrtQuery *)p);
388
363
  }
389
364
 
390
- #define GET_Q() FrtQuery *q = (FrtQuery *)DATA_PTR(self)
391
-
392
365
  /*
393
366
  * call-seq:
394
367
  * query.to_s -> string
@@ -397,13 +370,11 @@ frb_q_free(void *p)
397
370
  * this string through the Query parser will give you the exact Query you
398
371
  * began with. This can be a good way to explore how the QueryParser works.
399
372
  */
400
- static VALUE
401
- frb_q_to_s(int argc, VALUE *argv, VALUE self)
402
- {
403
- GET_Q();
373
+ static VALUE frb_q_to_s(int argc, VALUE *argv, VALUE self) {
374
+ FrtQuery *q = (FrtQuery *)DATA_PTR(self);
404
375
  VALUE rstr, rfield;
405
376
  char *str;
406
- FrtSymbol field = (FrtSymbol)NULL;
377
+ ID field = (ID)NULL;
407
378
  if (rb_scan_args(argc, argv, "01", &rfield)) {
408
379
  field = frb_field(rfield);
409
380
  }
@@ -420,10 +391,8 @@ frb_q_to_s(int argc, VALUE *argv, VALUE self)
420
391
  * Returns the queries boost value. See the Query description for more
421
392
  * information on Query boosts.
422
393
  */
423
- static VALUE
424
- frb_q_get_boost(VALUE self)
425
- {
426
- GET_Q();
394
+ static VALUE frb_q_get_boost(VALUE self) {
395
+ FrtQuery *q = (FrtQuery *)DATA_PTR(self);
427
396
  return rb_float_new((double)q->boost);
428
397
  }
429
398
 
@@ -434,10 +403,8 @@ frb_q_get_boost(VALUE self)
434
403
  * Set the boost for a query. See the Query description for more information
435
404
  * on Query boosts.
436
405
  */
437
- static VALUE
438
- frb_q_set_boost(VALUE self, VALUE rboost)
439
- {
440
- GET_Q();
406
+ static VALUE frb_q_set_boost(VALUE self, VALUE rboost) {
407
+ FrtQuery *q = (FrtQuery *)DATA_PTR(self);
441
408
  q->boost = (float)NUM2DBL(rboost);
442
409
  return rboost;
443
410
  }
@@ -449,10 +416,8 @@ frb_q_set_boost(VALUE self, VALUE rboost)
449
416
  * Return a hash value for the query. This is used for caching query results
450
417
  * in a hash object.
451
418
  */
452
- static VALUE
453
- frb_q_hash(VALUE self)
454
- {
455
- GET_Q();
419
+ static VALUE frb_q_hash(VALUE self) {
420
+ FrtQuery *q = (FrtQuery *)DATA_PTR(self);
456
421
  return INT2FIX(q->hash(q));
457
422
  }
458
423
 
@@ -469,12 +434,10 @@ frb_q_hash(VALUE self)
469
434
  * although their result sets will be identical. Most queries should match as
470
435
  * expected however.
471
436
  */
472
- static VALUE
473
- frb_q_eql(VALUE self, VALUE other)
474
- {
475
- GET_Q();
437
+ static VALUE frb_q_eql(VALUE self, VALUE other) {
438
+ FrtQuery *q = (FrtQuery *)DATA_PTR(self);
476
439
  FrtQuery *oq;
477
- Data_Get_Struct(other, FrtQuery, oq);
440
+ oq = DATA_PTR(other);
478
441
  return q->eq(q, oq) ? Qtrue : Qfalse;
479
442
  }
480
443
 
@@ -487,15 +450,13 @@ frb_q_eql(VALUE self, VALUE other)
487
450
  * searcher so that the query can be rewritten and optimized like it would be
488
451
  * in a real search.
489
452
  */
490
- static VALUE
491
- frb_q_get_terms(VALUE self, VALUE searcher)
492
- {
453
+ static VALUE frb_q_get_terms(VALUE self, VALUE searcher) {
493
454
  VALUE rterms = rb_ary_new();
494
455
  FrtHashSet *terms = frt_hs_new((frt_hash_ft)&frt_term_hash,
495
456
  (frt_eq_ft)&frt_term_eq,
496
457
  (frt_free_ft)frt_term_destroy);
497
458
  FrtHashSetEntry *hse;
498
- GET_Q();
459
+ FrtQuery *q = (FrtQuery *)DATA_PTR(self);
499
460
  FrtSearcher *sea = (FrtSearcher *)DATA_PTR(searcher);
500
461
  FrtQuery *rq = sea->rewrite(sea, q);
501
462
  rq->extract_terms(rq, terms);
@@ -509,86 +470,59 @@ frb_q_get_terms(VALUE self, VALUE searcher)
509
470
  return rterms;
510
471
  }
511
472
 
512
- #define MK_QUERY(klass, q) Data_Wrap_Struct(klass, NULL, &frb_q_free, q)
513
- VALUE
514
- frb_get_q(FrtQuery *q)
515
- {
516
- VALUE self = object_get(q);
517
-
518
- if (self == Qnil) {
519
- switch (q->type) {
520
- case TERM_QUERY:
521
- self = MK_QUERY(cTermQuery, q);
522
- break;
523
- case MULTI_TERM_QUERY:
524
- self = MK_QUERY(cMultiTermQuery, q);
525
- break;
526
- case BOOLEAN_QUERY:
527
- self = MK_QUERY(cBooleanQuery, q);
528
- break;
529
- case PHRASE_QUERY:
530
- self = MK_QUERY(cPhraseQuery, q);
531
- break;
532
- case CONSTANT_QUERY:
533
- self = MK_QUERY(cConstantScoreQuery, q);
534
- break;
535
- case FILTERED_QUERY:
536
- self = MK_QUERY(cFilteredQuery, q);
537
- break;
538
- case MATCH_ALL_QUERY:
539
- self = MK_QUERY(cMatchAllQuery, q);
540
- break;
541
- case RANGE_QUERY:
542
- self = MK_QUERY(cRangeQuery, q);
543
- break;
544
- case TYPED_RANGE_QUERY:
545
- self = MK_QUERY(cTypedRangeQuery, q);
546
- break;
547
- case WILD_CARD_QUERY:
548
- self = MK_QUERY(cWildcardQuery, q);
549
- break;
550
- case FUZZY_QUERY:
551
- self = MK_QUERY(cFuzzyQuery, q);
552
- break;
553
- case PREFIX_QUERY:
554
- self = MK_QUERY(cPrefixQuery, q);
555
- break;
556
- case SPAN_TERM_QUERY:
557
- self = MK_QUERY(cSpanMultiTermQuery, q);
558
- break;
559
- case SPAN_MULTI_TERM_QUERY:
560
- self = MK_QUERY(cSpanPrefixQuery, q);
561
- break;
562
- case SPAN_PREFIX_QUERY:
563
- self = MK_QUERY(cSpanTermQuery, q);
564
- break;
565
- case SPAN_FIRST_QUERY:
566
- self = MK_QUERY(cSpanFirstQuery, q);
567
- break;
568
- case SPAN_OR_QUERY:
569
- self = MK_QUERY(cSpanOrQuery, q);
570
- break;
571
- case SPAN_NOT_QUERY:
572
- self = MK_QUERY(cSpanNotQuery, q);
573
- break;
574
- case SPAN_NEAR_QUERY:
575
- self = MK_QUERY(cSpanNearQuery, q);
576
- break;
577
- default:
578
- rb_raise(rb_eArgError, "Unknown query type");
579
- break;
580
- }
581
- object_add(q, self);
582
- }
583
- return self;
584
- }
585
-
586
473
  /****************************************************************************
587
- *
588
474
  * TermQuery Methods
589
- *
590
475
  ****************************************************************************/
591
476
 
477
+ static size_t frb_term_query_size(const void *p) {
478
+ return sizeof(FrtTermQuery);
479
+ (void)p;
480
+ }
481
+
482
+ const rb_data_type_t frb_term_query_t = {
483
+ .wrap_struct_name = "FrbTermQuery",
484
+ .function = {
485
+ .dmark = NULL,
486
+ .dfree = frb_q_free,
487
+ .dsize = frb_term_query_size,
488
+ .dcompact = NULL,
489
+ .reserved = {0},
490
+ },
491
+ .parent = NULL,
492
+ .data = NULL,
493
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
494
+ };
495
+
496
+ static VALUE frb_tq_alloc(VALUE rclass) {
497
+ FrtQuery *tq = frt_tq_alloc();
498
+ return TypedData_Wrap_Struct(rclass, &frb_term_query_t, tq);
499
+ }
500
+
501
+ typedef struct frb_tq_args {
502
+ VALUE self;
503
+ VALUE rfield;
504
+ VALUE rterm;
505
+ char *term;
506
+ ID field;
507
+ } frb_tq_args;
508
+
509
+ VALUE frb_tq_init_2(VALUE args) {
510
+ frb_tq_args *a = (frb_tq_args *)args;
511
+ a->field = frb_field(a->rfield);
512
+ a->term = rs2s(rb_obj_as_string(a->rterm));
513
+ return Qnil;
514
+ }
515
+
516
+ VALUE frb_q_init_r(VALUE args, VALUE exception) {
517
+ frb_tq_args *a = (frb_tq_args *)args;
518
+ free(((struct RData *)(a->self))->data);
519
+ ((struct RData *)(a->self))->data = NULL;
520
+ ((struct RData *)(a->self))->dmark = NULL;
521
+ ((struct RData *)(a->self))->dfree = NULL;
522
+ rb_exc_raise(exception);
523
+ return Qnil;
524
+ }
525
+
592
526
  /*
593
527
  * call-seq:
594
528
  * TermQuery.new(field, term) -> term_query
@@ -598,14 +532,13 @@ frb_get_q(FrtQuery *q)
598
532
  *
599
533
  * Note: As usual, field should be a symbol
600
534
  */
601
- static VALUE
602
- frb_tq_init(VALUE self, VALUE rfield, VALUE rterm)
603
- {
604
- FrtSymbol field = frb_field(rfield);
605
- char *term = rs2s(rb_obj_as_string(rterm));
606
- FrtQuery *q = frt_tq_new(field, term);
607
- Frt_Wrap_Struct(self, NULL, &frb_q_free, q);
608
- object_add(q, self);
535
+ static VALUE frb_tq_init(VALUE self, VALUE rfield, VALUE rterm) {
536
+ frb_tq_args args = { .self = self, .rfield = rfield, .rterm = rterm, .field = 0, .term = NULL };
537
+ rb_rescue(frb_tq_init_2, (VALUE)&args, frb_q_init_r, (VALUE)&args);
538
+ FrtQuery *q;
539
+ TypedData_Get_Struct(self, FrtQuery, &frb_term_query_t, q);
540
+ frt_tq_init(q, args.field, args.term);
541
+ q->rquery = self;
609
542
  return self;
610
543
  }
611
544
 
@@ -615,6 +548,30 @@ frb_tq_init(VALUE self, VALUE rfield, VALUE rterm)
615
548
  *
616
549
  ****************************************************************************/
617
550
 
551
+ static size_t frb_multi_term_query_size(const void *p) {
552
+ return sizeof(FrtMultiTermQuery);
553
+ (void)p;
554
+ }
555
+
556
+ const rb_data_type_t frb_multi_term_query_t = {
557
+ .wrap_struct_name = "FrbTermQuery",
558
+ .function = {
559
+ .dmark = NULL,
560
+ .dfree = frb_q_free,
561
+ .dsize = frb_multi_term_query_size,
562
+ .dcompact = NULL,
563
+ .reserved = {0},
564
+ },
565
+ .parent = NULL,
566
+ .data = NULL,
567
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
568
+ };
569
+
570
+ static VALUE frb_mtq_alloc(VALUE rclass) {
571
+ FrtQuery *tq = frt_multi_tq_alloc();
572
+ return TypedData_Wrap_Struct(rclass, &frb_multi_term_query_t, tq);
573
+ }
574
+
618
575
  /*
619
576
  * call-seq:
620
577
  * MultiTermQuery.default_max_terms -> number
@@ -622,9 +579,7 @@ frb_tq_init(VALUE self, VALUE rfield, VALUE rterm)
622
579
  * Get the default value for +:max_terms+ in a MultiTermQuery. This value is
623
580
  * also used by PrefixQuery, FuzzyQuery and WildcardQuery.
624
581
  */
625
- static VALUE
626
- frb_mtq_get_dmt(VALUE self)
627
- {
582
+ static VALUE frb_mtq_get_dmt(VALUE self) {
628
583
  return rb_cvar_get(cMultiTermQuery, id_default_max_terms);
629
584
  }
630
585
 
@@ -635,18 +590,42 @@ frb_mtq_get_dmt(VALUE self)
635
590
  * Set the default value for +:max_terms+ in a MultiTermQuery. This value is
636
591
  * also used by PrefixQuery, FuzzyQuery and WildcardQuery.
637
592
  */
638
- static VALUE
639
- frb_mtq_set_dmt(VALUE self, VALUE rnum_terms)
640
- {
593
+ static VALUE frb_mtq_set_dmt(VALUE self, VALUE rnum_terms) {
641
594
  int max_terms = FIX2INT(rnum_terms);
642
595
  if (max_terms <= 0) {
643
- rb_raise(rb_eArgError,
644
- "%d <= 0. @@max_terms must be > 0", max_terms);
596
+ rb_raise(rb_eArgError, "%d <= 0. @@max_terms must be > 0", max_terms);
645
597
  }
646
598
  rb_cvar_set(cMultiTermQuery, id_default_max_terms, rnum_terms);
647
599
  return rnum_terms;
648
600
  }
649
601
 
602
+ typedef struct frb_mtq_args {
603
+ VALUE self;
604
+ VALUE argc;
605
+ VALUE *argv;
606
+ float min_score;
607
+ int max_terms;
608
+ ID field;
609
+ } frb_mtq_args;
610
+
611
+ VALUE frb_mtq_init_2(VALUE args) {
612
+ frb_mtq_args *a = (frb_mtq_args *)args;
613
+ VALUE rfield, roptions;
614
+ a->min_score = 0.0f;
615
+ a->max_terms = FIX2INT(frb_mtq_get_dmt(a->self));
616
+ if (rb_scan_args(a->argc, a->argv, "11", &rfield, &roptions) == 2) {
617
+ VALUE v;
618
+ if (Qnil != (v = rb_hash_aref(roptions, sym_max_terms))) {
619
+ a->max_terms = FIX2INT(v);
620
+ }
621
+ if (Qnil != (v = rb_hash_aref(roptions, sym_min_score))) {
622
+ a->min_score = (float)NUM2DBL(v);
623
+ }
624
+ }
625
+ a->field = frb_field(rfield);
626
+ return Qnil;
627
+ }
628
+
650
629
  /*
651
630
  * call-seq:
652
631
  * MultiTermQuery.new(field, options = {}) -> multi_term_query
@@ -671,26 +650,13 @@ frb_mtq_set_dmt(VALUE self, VALUE rnum_terms)
671
650
  * added to the query you could set a lower limit to this score.
672
651
  * FuzzyQuery in particular makes use of this parameter.
673
652
  */
674
- static VALUE
675
- frb_mtq_init(int argc, VALUE *argv, VALUE self)
676
- {
677
- VALUE rfield, roptions;
678
- float min_score = 0.0f;
679
- int max_terms = FIX2INT(frb_mtq_get_dmt(self));
653
+ static VALUE frb_mtq_init(int argc, VALUE *argv, VALUE self) {
654
+ frb_mtq_args args = { .self = self, .argc = argc, .argv = argv, .field = 0 };
655
+ rb_rescue(frb_mtq_init_2, (VALUE)&args, frb_q_init_r, (VALUE)&args);
680
656
  FrtQuery *q;
681
-
682
- if (rb_scan_args(argc, argv, "11", &rfield, &roptions) == 2) {
683
- VALUE v;
684
- if (Qnil != (v = rb_hash_aref(roptions, sym_max_terms))) {
685
- max_terms = FIX2INT(v);
686
- }
687
- if (Qnil != (v = rb_hash_aref(roptions, sym_min_score))) {
688
- min_score = (float)NUM2DBL(v);
689
- }
690
- }
691
- q = frt_multi_tq_new_conf(frb_field(rfield), max_terms, min_score);
692
- Frt_Wrap_Struct(self, NULL, &frb_q_free, q);
693
- object_add(q, self);
657
+ TypedData_Get_Struct(self, FrtQuery, &frb_multi_term_query_t, q);
658
+ frt_multi_tq_init_conf(q, args.field, args.max_terms, args.min_score);
659
+ q->rquery = self;
694
660
  return self;
695
661
  }
696
662
 
@@ -702,10 +668,8 @@ frb_mtq_init(int argc, VALUE *argv, VALUE self)
702
668
  * Add a term to the MultiTermQuery with the score 1.0 unless specified
703
669
  * otherwise.
704
670
  */
705
- static VALUE
706
- frb_mtq_add_term(int argc, VALUE *argv, VALUE self)
707
- {
708
- GET_Q();
671
+ static VALUE frb_mtq_add_term(int argc, VALUE *argv, VALUE self) {
672
+ FrtQuery *q = (FrtQuery *)DATA_PTR(self);
709
673
  VALUE rterm, rboost;
710
674
  float boost = 1.0f;
711
675
  char *term = NULL;
@@ -718,11 +682,9 @@ frb_mtq_add_term(int argc, VALUE *argv, VALUE self)
718
682
  return self;
719
683
  }
720
684
 
721
- typedef FrtQuery *(*mtq_maker_ft)(FrtSymbol field, const char *term);
685
+ typedef FrtQuery *(*mtq_maker_ft)(ID field, const char *term);
722
686
 
723
- static int
724
- get_max_terms(VALUE rmax_terms, int max_terms)
725
- {
687
+ static int get_max_terms(VALUE rmax_terms, int max_terms) {
726
688
  VALUE v;
727
689
  switch (TYPE(rmax_terms)) {
728
690
  case T_HASH:
@@ -739,56 +701,53 @@ get_max_terms(VALUE rmax_terms, int max_terms)
739
701
  return max_terms;
740
702
  }
741
703
 
742
- static VALUE
743
- frb_mtq_init_specific(int argc, VALUE *argv, VALUE self, mtq_maker_ft mm)
744
- {
745
- VALUE rfield, rterm, rmax_terms;
746
- int max_terms =
747
- FIX2INT(rb_cvar_get(cMultiTermQuery, id_default_max_terms));
748
- FrtQuery *q;
749
-
750
- if (rb_scan_args(argc, argv, "21", &rfield, &rterm, &rmax_terms) == 3) {
751
- max_terms = get_max_terms(rmax_terms, max_terms);
752
- }
753
-
754
- q = (*mm)(frb_field(rfield), StringValuePtr(rterm));
755
- FrtMTQMaxTerms(q) = max_terms;
756
- Frt_Wrap_Struct(self, NULL, &frb_q_free, q);
757
- object_add(q, self);
758
- return self;
759
- }
760
-
761
704
  /****************************************************************************
762
705
  *
763
706
  * BooleanClause Methods
764
707
  *
765
708
  ****************************************************************************/
766
709
 
767
- static void
768
- frb_bc_mark(void *p)
769
- {
770
- frb_gc_mark(((FrtBooleanClause *)p)->query);
710
+ static size_t frb_boolean_clause_t_size(const void *p) {
711
+ return sizeof(FrtBooleanClause);
712
+ (void)p;
771
713
  }
772
714
 
773
- static void
774
- frb_bc_free(void *p)
775
- {
776
- object_del(p);
715
+ static void frb_bc_mark(void *p) {
716
+ if (((FrtBooleanClause *)p)->query->rquery)
717
+ rb_gc_mark(((FrtBooleanClause *)p)->query->rquery);
718
+ }
719
+
720
+ static void frb_bc_free(void *p) {
777
721
  frt_bc_deref((FrtBooleanClause *)p);
778
722
  }
779
723
 
780
- static VALUE
781
- frb_bc_wrap(FrtBooleanClause *bc)
782
- {
783
- VALUE self = Data_Wrap_Struct(cBooleanClause, &frb_bc_mark, &frb_bc_free, bc);
724
+ const rb_data_type_t frb_boolean_clause_t = {
725
+ .wrap_struct_name = "FrbBooleanClause",
726
+ .function = {
727
+ .dmark = frb_bc_mark,
728
+ .dfree = frb_bc_free,
729
+ .dsize = frb_boolean_clause_t_size,
730
+ .dcompact = NULL,
731
+ .reserved = {0},
732
+ },
733
+ .parent = NULL,
734
+ .data = NULL,
735
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
736
+ };
737
+
738
+ static VALUE frb_bc_alloc(VALUE rclass) {
739
+ FrtBooleanClause *bc = frt_bc_alloc();
740
+ return TypedData_Wrap_Struct(rclass, &frb_boolean_clause_t, bc);
741
+ }
742
+
743
+ static VALUE frb_bc_wrap(FrtBooleanClause *bc) {
744
+ VALUE self = TypedData_Wrap_Struct(cBooleanClause, &frb_boolean_clause_t, bc);
745
+ bc->rbc = self;
784
746
  FRT_REF(bc);
785
- object_add(bc, self);
786
747
  return self;
787
748
  }
788
749
 
789
- static FrtBCType
790
- frb_get_occur(VALUE roccur)
791
- {
750
+ static FrtBCType frb_get_occur(VALUE roccur) {
792
751
  FrtBCType occur = FRT_BC_SHOULD;
793
752
 
794
753
  if (roccur == sym_should) {
@@ -798,8 +757,7 @@ frb_get_occur(VALUE roccur)
798
757
  } else if (roccur == sym_must_not) {
799
758
  occur = FRT_BC_MUST_NOT;
800
759
  } else {
801
- rb_raise(rb_eArgError, "occur argument must be one of [:must, "
802
- ":should, :must_not]");
760
+ rb_raise(rb_eArgError, "occur argument must be one of [:must, :should, :must_not]");
803
761
  }
804
762
  return occur;
805
763
  }
@@ -811,36 +769,33 @@ frb_get_occur(VALUE roccur)
811
769
  * Create a new BooleanClause object, wrapping the query +query+. +occur+
812
770
  * must be one of +:must+, +:should+ or +:must_not+.
813
771
  */
814
- static VALUE
815
- frb_bc_init(int argc, VALUE *argv, VALUE self)
816
- {
772
+ static VALUE frb_bc_init(int argc, VALUE *argv, VALUE self) {
817
773
  FrtBooleanClause *bc;
774
+ TypedData_Get_Struct(self, FrtBooleanClause, &frb_boolean_clause_t, bc);
818
775
  VALUE rquery, roccur;
819
776
  unsigned int occur = FRT_BC_SHOULD;
820
777
  FrtQuery *sub_q;
821
778
  if (rb_scan_args(argc, argv, "11", &rquery, &roccur) == 2) {
822
779
  occur = frb_get_occur(roccur);
823
780
  }
824
- Data_Get_Struct(rquery, FrtQuery, sub_q);
781
+ sub_q = DATA_PTR(rquery);
825
782
  FRT_REF(sub_q);
826
- bc = frt_bc_new(sub_q, occur);
827
- Frt_Wrap_Struct(self, &frb_bc_mark, &frb_bc_free, bc);
828
- object_add(bc, self);
783
+ frt_bc_init(bc, sub_q, occur);
784
+ bc->rbc = self;
829
785
  return self;
830
786
  }
831
787
 
832
- #define GET_BC() FrtBooleanClause *bc = (FrtBooleanClause *)DATA_PTR(self)
833
788
  /*
834
789
  * call-seq:
835
790
  * clause.query -> query
836
791
  *
837
792
  * Return the query object wrapped by this BooleanClause.
838
793
  */
839
- static VALUE
840
- frb_bc_get_query(VALUE self)
841
- {
842
- GET_BC();
843
- return object_get(bc->query);
794
+ static VALUE frb_bc_get_query(VALUE self) {
795
+ FrtBooleanClause *bc = (FrtBooleanClause *)DATA_PTR(self);
796
+ if (bc->query->rquery)
797
+ return bc->query->rquery;
798
+ return Qnil;
844
799
  }
845
800
 
846
801
  /*
@@ -849,11 +804,9 @@ frb_bc_get_query(VALUE self)
849
804
  *
850
805
  * Set the query wrapped by this BooleanClause.
851
806
  */
852
- static VALUE
853
- frb_bc_set_query(VALUE self, VALUE rquery)
854
- {
855
- GET_BC();
856
- Data_Get_Struct(rquery, FrtQuery, bc->query);
807
+ static VALUE frb_bc_set_query(VALUE self, VALUE rquery) {
808
+ FrtBooleanClause *bc = (FrtBooleanClause *)DATA_PTR(self);
809
+ bc->query = DATA_PTR(rquery);
857
810
  return rquery;
858
811
  }
859
812
 
@@ -864,10 +817,8 @@ frb_bc_set_query(VALUE self, VALUE rquery)
864
817
  * Return true if this clause is required. ie, this will be true if occur was
865
818
  * equal to +:must+.
866
819
  */
867
- static VALUE
868
- frb_bc_is_required(VALUE self)
869
- {
870
- GET_BC();
820
+ static VALUE frb_bc_is_required(VALUE self) {
821
+ FrtBooleanClause *bc = (FrtBooleanClause *)DATA_PTR(self);
871
822
  return bc->is_required ? Qtrue : Qfalse;
872
823
  }
873
824
 
@@ -878,10 +829,8 @@ frb_bc_is_required(VALUE self)
878
829
  * Return true if this clause is prohibited. ie, this will be true if occur was
879
830
  * equal to +:must_not+.
880
831
  */
881
- static VALUE
882
- frb_bc_is_prohibited(VALUE self)
883
- {
884
- GET_BC();
832
+ static VALUE frb_bc_is_prohibited(VALUE self) {
833
+ FrtBooleanClause *bc = (FrtBooleanClause *)DATA_PTR(self);
885
834
  return bc->is_prohibited ? Qtrue : Qfalse;
886
835
  }
887
836
 
@@ -892,10 +841,8 @@ frb_bc_is_prohibited(VALUE self)
892
841
  * Set the +occur+ value for this BooleanClause. +occur+ must be one of
893
842
  * +:must+, +:should+ or +:must_not+.
894
843
  */
895
- static VALUE
896
- frb_bc_set_occur(VALUE self, VALUE roccur)
897
- {
898
- GET_BC();
844
+ static VALUE frb_bc_set_occur(VALUE self, VALUE roccur) {
845
+ FrtBooleanClause *bc = (FrtBooleanClause *)DATA_PTR(self);
899
846
  FrtBCType occur = frb_get_occur(roccur);
900
847
  frt_bc_set_occur(bc, occur);
901
848
 
@@ -910,15 +857,13 @@ frb_bc_set_occur(VALUE self, VALUE roccur)
910
857
  * BooleanQuery#to_s. It is only used by BooleanClause#to_s and will specify
911
858
  * whether the clause is +:must+, +:should+ or +:must_not+.
912
859
  */
913
- static VALUE
914
- frb_bc_to_s(VALUE self)
915
- {
860
+ static VALUE frb_bc_to_s(VALUE self) {
916
861
  VALUE rstr;
917
862
  char *qstr, *str;
918
863
  const char *ostr = "";
919
864
  int len;
920
- GET_BC();
921
- qstr = bc->query->to_s(bc->query, (FrtSymbol)NULL);
865
+ FrtBooleanClause *bc = (FrtBooleanClause *)DATA_PTR(self);
866
+ qstr = bc->query->to_s(bc->query, (ID)NULL);
922
867
  switch (bc->occur) {
923
868
  case FRT_BC_SHOULD:
924
869
  ostr = "Should";
@@ -945,15 +890,55 @@ frb_bc_to_s(VALUE self)
945
890
  *
946
891
  ****************************************************************************/
947
892
 
948
- static void
949
- frb_bq_mark(void *p)
950
- {
893
+ static size_t frb_boolean_query_size(const void *p) {
894
+ return sizeof(FrtBooleanQuery);
895
+ (void)p;
896
+ }
897
+
898
+ static void frb_bq_mark(void *p) {
951
899
  int i;
952
900
  FrtQuery *q = (FrtQuery *)p;
953
901
  FrtBooleanQuery *bq = (FrtBooleanQuery *)q;
954
902
  for (i = 0; i < bq->clause_cnt; i++) {
955
- frb_gc_mark(bq->clauses[i]);
903
+ if (bq->clauses[i]->rbc)
904
+ rb_gc_mark(bq->clauses[i]->rbc);
905
+ }
906
+ }
907
+
908
+ const rb_data_type_t frb_boolean_query_t = {
909
+ .wrap_struct_name = "FrbBooleanQuery",
910
+ .function = {
911
+ .dmark = frb_bq_mark,
912
+ .dfree = frb_q_free,
913
+ .dsize = frb_boolean_query_size,
914
+ .dcompact = NULL,
915
+ .reserved = {0},
916
+ },
917
+ .parent = NULL,
918
+ .data = NULL,
919
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
920
+ };
921
+
922
+ static VALUE frb_bq_alloc(VALUE rclass) {
923
+ FrtQuery *bq = frt_bq_alloc();
924
+ return TypedData_Wrap_Struct(rclass, &frb_boolean_query_t, bq);
925
+ }
926
+
927
+ typedef struct frb_bq_args {
928
+ VALUE self;
929
+ VALUE argc;
930
+ VALUE *argv;
931
+ bool coord_disabled;
932
+ } frb_bq_args;
933
+
934
+ VALUE frb_bq_init_2(VALUE args) {
935
+ frb_bq_args *a = (frb_bq_args *)args;
936
+ VALUE rcoord_disabled;
937
+ a->coord_disabled = false;
938
+ if (rb_scan_args(a->argc, a->argv, "01", &rcoord_disabled)) {
939
+ a->coord_disabled = RTEST(rcoord_disabled);
956
940
  }
941
+ return Qnil;
957
942
  }
958
943
 
959
944
  /*
@@ -966,18 +951,13 @@ frb_bq_mark(void *p)
966
951
  * score. This will slightly improve performance for the query. Usually you
967
952
  * should leave this parameter as is.
968
953
  */
969
- static VALUE
970
- frb_bq_init(int argc, VALUE *argv, VALUE self)
971
- {
972
- VALUE rcoord_disabled;
973
- bool coord_disabled = false;
954
+ static VALUE frb_bq_init(int argc, VALUE *argv, VALUE self) {
955
+ frb_bq_args args = { .self = self, .argc = argc, .argv = argv };
956
+ rb_rescue(frb_bq_init_2, (VALUE)&args, frb_q_init_r, (VALUE)&args);
974
957
  FrtQuery *q;
975
- if (rb_scan_args(argc, argv, "01", &rcoord_disabled)) {
976
- coord_disabled = RTEST(rcoord_disabled);
977
- }
978
- q = frt_bq_new(coord_disabled);
979
- Frt_Wrap_Struct(self, &frb_bq_mark, &frb_q_free, q);
980
- object_add(q, self);
958
+ TypedData_Get_Struct(self, FrtQuery, &frb_boolean_query_t, q);
959
+ frt_bq_init(q, args.coord_disabled);
960
+ q->rquery = self;
981
961
  return self;
982
962
  }
983
963
 
@@ -1002,10 +982,8 @@ frb_bq_init(int argc, VALUE *argv, VALUE self)
1002
982
  * [:must, :should, :must_not]
1003
983
  * returns:: BooleanClause which was added
1004
984
  */
1005
- static VALUE
1006
- frb_bq_add_query(int argc, VALUE *argv, VALUE self)
1007
- {
1008
- GET_Q();
985
+ static VALUE frb_bq_add_query(int argc, VALUE *argv, VALUE self) {
986
+ FrtQuery *q = (FrtQuery *)DATA_PTR(self);
1009
987
  VALUE rquery, roccur;
1010
988
  FrtBCType occur = FRT_BC_SHOULD;
1011
989
  FrtQuery *sub_q;
@@ -1018,17 +996,15 @@ frb_bq_add_query(int argc, VALUE *argv, VALUE self)
1018
996
  if (klass == cBooleanClause) {
1019
997
  FrtBooleanClause *bc = (FrtBooleanClause *)DATA_PTR(rquery);
1020
998
  if (argc > 1) {
1021
- rb_warning("Second argument to BooleanQuery#add is ignored "
1022
- "when adding BooleanClause");
999
+ rb_warning("Second argument to BooleanQuery#add is ignored when adding BooleanClause");
1023
1000
  }
1024
1001
  frt_bq_add_clause(q, bc);
1025
1002
  return rquery;
1026
1003
  } else if (TYPE(rquery) == T_DATA) {
1027
- Data_Get_Struct(rquery, FrtQuery, sub_q);
1004
+ sub_q = DATA_PTR(rquery);
1028
1005
  return frb_bc_wrap(frt_bq_add_query(q, sub_q, occur));
1029
1006
  } else {
1030
- rb_raise(rb_eArgError, "Cannot add %s to a BooleanQuery",
1031
- rb_class2name(klass));
1007
+ rb_raise(rb_eArgError, "Cannot add %s to a BooleanQuery", rb_class2name(klass));
1032
1008
  }
1033
1009
  return self;
1034
1010
  }
@@ -1039,62 +1015,94 @@ frb_bq_add_query(int argc, VALUE *argv, VALUE self)
1039
1015
  *
1040
1016
  ****************************************************************************/
1041
1017
 
1042
- static void
1043
- get_range_params(VALUE roptions, char **lterm, char **uterm,
1044
- bool *include_lower, bool *include_upper)
1045
- {
1018
+ static size_t frb_range_query_size(const void *p) {
1019
+ return sizeof(FrtRangeQuery);
1020
+ (void)p;
1021
+ }
1022
+
1023
+ const rb_data_type_t frb_range_query_t = {
1024
+ .wrap_struct_name = "FrbRangeQuery",
1025
+ .function = {
1026
+ .dmark = NULL,
1027
+ .dfree = frb_q_free,
1028
+ .dsize = frb_range_query_size,
1029
+ .dcompact = NULL,
1030
+ .reserved = {0},
1031
+ },
1032
+ .parent = NULL,
1033
+ .data = NULL,
1034
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
1035
+ };
1036
+
1037
+ static VALUE frb_rq_alloc(VALUE rclass) {
1038
+ FrtQuery *rq = frt_rq_alloc();
1039
+ return TypedData_Wrap_Struct(rclass, &frb_range_query_t, rq);
1040
+ }
1041
+
1042
+ typedef struct frb_rq_args {
1043
+ VALUE self;
1044
+ VALUE rfield;
1045
+ VALUE roptions;
1046
+ ID field;
1047
+ char *lterm;
1048
+ char *uterm;
1049
+ bool include_lower;
1050
+ bool include_upper;
1051
+ } frb_rq_args;
1052
+
1053
+ VALUE frb_rq_init_2(VALUE args) {
1054
+ frb_rq_args *a = (frb_rq_args *)args;
1046
1055
  VALUE v;
1047
- Check_Type(roptions, T_HASH);
1048
- if (Qnil != (v = rb_hash_aref(roptions, sym_lower))) {
1049
- *lterm = rs2s(rb_obj_as_string(v));
1050
- *include_lower = true;
1056
+ Check_Type(a->roptions, T_HASH);
1057
+ if (Qnil != (v = rb_hash_aref(a->roptions, sym_lower))) {
1058
+ a->lterm = rs2s(rb_obj_as_string(v));
1059
+ a->include_lower = true;
1051
1060
  }
1052
- if (Qnil != (v = rb_hash_aref(roptions, sym_upper))) {
1053
- *uterm = rs2s(rb_obj_as_string(v));
1054
- *include_upper = true;
1061
+ if (Qnil != (v = rb_hash_aref(a->roptions, sym_upper))) {
1062
+ a->uterm = rs2s(rb_obj_as_string(v));
1063
+ a->include_upper = true;
1055
1064
  }
1056
- if (Qnil != (v = rb_hash_aref(roptions, sym_lower_exclusive))) {
1057
- *lterm = rs2s(rb_obj_as_string(v));
1058
- *include_lower = false;
1065
+ if (Qnil != (v = rb_hash_aref(a->roptions, sym_lower_exclusive))) {
1066
+ a->lterm = rs2s(rb_obj_as_string(v));
1067
+ a->include_lower = false;
1059
1068
  }
1060
- if (Qnil != (v = rb_hash_aref(roptions, sym_upper_exclusive))) {
1061
- *uterm = rs2s(rb_obj_as_string(v));
1062
- *include_upper = false;
1069
+ if (Qnil != (v = rb_hash_aref(a->roptions, sym_upper_exclusive))) {
1070
+ a->uterm = rs2s(rb_obj_as_string(v));
1071
+ a->include_upper = false;
1063
1072
  }
1064
- if (Qnil != (v = rb_hash_aref(roptions, sym_include_lower))) {
1065
- *include_lower = RTEST(v);
1073
+ if (Qnil != (v = rb_hash_aref(a->roptions, sym_include_lower))) {
1074
+ a->include_lower = RTEST(v);
1066
1075
  }
1067
- if (Qnil != (v = rb_hash_aref(roptions, sym_include_upper))) {
1068
- *include_upper = RTEST(v);
1076
+ if (Qnil != (v = rb_hash_aref(a->roptions, sym_include_upper))) {
1077
+ a->include_upper = RTEST(v);
1069
1078
  }
1070
- if (Qnil != (v = rb_hash_aref(roptions, sym_greater_than))) {
1071
- *lterm = rs2s(rb_obj_as_string(v));
1072
- *include_lower = false;
1079
+ if (Qnil != (v = rb_hash_aref(a->roptions, sym_greater_than))) {
1080
+ a->lterm = rs2s(rb_obj_as_string(v));
1081
+ a->include_lower = false;
1073
1082
  }
1074
- if (Qnil != (v = rb_hash_aref(roptions, sym_greater_than_or_equal_to))) {
1075
- *lterm = rs2s(rb_obj_as_string(v));
1076
- *include_lower = true;
1083
+ if (Qnil != (v = rb_hash_aref(a->roptions, sym_greater_than_or_equal_to))) {
1084
+ a->lterm = rs2s(rb_obj_as_string(v));
1085
+ a->include_lower = true;
1077
1086
  }
1078
- if (Qnil != (v = rb_hash_aref(roptions, sym_less_than))) {
1079
- *uterm = rs2s(rb_obj_as_string(v));
1080
- *include_upper = false;
1087
+ if (Qnil != (v = rb_hash_aref(a->roptions, sym_less_than))) {
1088
+ a->uterm = rs2s(rb_obj_as_string(v));
1089
+ a->include_upper = false;
1081
1090
  }
1082
- if (Qnil != (v = rb_hash_aref(roptions, sym_less_than_or_equal_to))) {
1083
- *uterm = rs2s(rb_obj_as_string(v));
1084
- *include_upper = true;
1091
+ if (Qnil != (v = rb_hash_aref(a->roptions, sym_less_than_or_equal_to))) {
1092
+ a->uterm = rs2s(rb_obj_as_string(v));
1093
+ a->include_upper = true;
1085
1094
  }
1086
- if (!*lterm && !*uterm) {
1087
- rb_raise(rb_eArgError,
1088
- "The bounds of a range should not both be nil");
1095
+ if (!a->lterm && !a->uterm) {
1096
+ rb_raise(rb_eArgError, "The bounds of a range should not both be nil");
1089
1097
  }
1090
- if (*include_lower && !*lterm) {
1091
- rb_raise(rb_eArgError,
1092
- "The lower bound should not be nil if it is inclusive");
1098
+ if (a->include_lower && !a->lterm) {
1099
+ rb_raise(rb_eArgError, "The lower bound should not be nil if it is inclusive");
1093
1100
  }
1094
- if (*include_upper && !*uterm) {
1095
- rb_raise(rb_eArgError,
1096
- "The upper bound should not be nil if it is inclusive");
1101
+ if (a->include_upper && !a->uterm) {
1102
+ rb_raise(rb_eArgError, "The upper bound should not be nil if it is inclusive");
1097
1103
  }
1104
+ a->field = frb_field(a->rfield);
1105
+ return Qnil;
1098
1106
  }
1099
1107
 
1100
1108
  /*
@@ -1120,21 +1128,13 @@ get_range_params(VALUE roptions, char **lterm, char **uterm,
1120
1128
  * q = RangeQuery.new(:date, :>= => "200501", :<= => 200502)
1121
1129
  *
1122
1130
  */
1123
- static VALUE
1124
- frb_rq_init(VALUE self, VALUE rfield, VALUE roptions)
1125
- {
1131
+ static VALUE frb_rq_init(VALUE self, VALUE rfield, VALUE roptions) {
1132
+ frb_rq_args a = { .self = self, .rfield = rfield, .roptions = roptions };
1133
+ rb_rescue(frb_rq_init_2, (VALUE)&a, frb_q_init_r, (VALUE)&a);
1126
1134
  FrtQuery *q;
1127
- char *lterm = NULL;
1128
- char *uterm = NULL;
1129
- bool include_lower = false;
1130
- bool include_upper = false;
1131
-
1132
- get_range_params(roptions, &lterm, &uterm, &include_lower, &include_upper);
1133
- q = frt_rq_new(frb_field(rfield),
1134
- lterm, uterm,
1135
- include_lower, include_upper);
1136
- Frt_Wrap_Struct(self, NULL, &frb_q_free, q);
1137
- object_add(q, self);
1135
+ TypedData_Get_Struct(self, FrtQuery, &frb_range_query_t, q);
1136
+ frt_rq_init(q, a.field, a.lterm, a.uterm, a.include_lower, a.include_upper);
1137
+ q->rquery = self;
1138
1138
  return self;
1139
1139
  }
1140
1140
 
@@ -1144,6 +1144,30 @@ frb_rq_init(VALUE self, VALUE rfield, VALUE roptions)
1144
1144
  *
1145
1145
  ****************************************************************************/
1146
1146
 
1147
+ static size_t frb_typed_range_query_size(const void *p) {
1148
+ return sizeof(FrtRangeQuery);
1149
+ (void)p;
1150
+ }
1151
+
1152
+ const rb_data_type_t frb_typed_range_query_t = {
1153
+ .wrap_struct_name = "FrbTypedRangeQuery",
1154
+ .function = {
1155
+ .dmark = NULL,
1156
+ .dfree = frb_q_free,
1157
+ .dsize = frb_typed_range_query_size,
1158
+ .dcompact = NULL,
1159
+ .reserved = {0},
1160
+ },
1161
+ .parent = NULL,
1162
+ .data = NULL,
1163
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
1164
+ };
1165
+
1166
+ static VALUE frb_trq_alloc(VALUE rclass) {
1167
+ FrtQuery *trq = frt_trq_alloc();
1168
+ return TypedData_Wrap_Struct(rclass, &frb_typed_range_query_t, trq);
1169
+ }
1170
+
1147
1171
  /*
1148
1172
  * call-seq:
1149
1173
  * TypedRangeQuery.new(field, options = {}) -> range_query
@@ -1172,21 +1196,13 @@ frb_rq_init(VALUE self, VALUE rfield, VALUE roptions)
1172
1196
  * # is equivalent to
1173
1197
  * q = TypedRangeQuery.new(:date, :>= => "-12.32", :<= => 0.21)
1174
1198
  */
1175
- static VALUE
1176
- frb_trq_init(VALUE self, VALUE rfield, VALUE roptions)
1177
- {
1199
+ static VALUE frb_trq_init(VALUE self, VALUE rfield, VALUE roptions) {
1200
+ frb_rq_args a = { .self = self, .rfield = rfield, .roptions = roptions };
1201
+ rb_rescue(frb_rq_init_2, (VALUE)&a, frb_q_init_r, (VALUE)&a);
1178
1202
  FrtQuery *q;
1179
- char *lterm = NULL;
1180
- char *uterm = NULL;
1181
- bool include_lower = false;
1182
- bool include_upper = false;
1183
-
1184
- get_range_params(roptions, &lterm, &uterm, &include_lower, &include_upper);
1185
- q = frt_trq_new(frb_field(rfield),
1186
- lterm, uterm,
1187
- include_lower, include_upper);
1188
- Frt_Wrap_Struct(self, NULL, &frb_q_free, q);
1189
- object_add(q, self);
1203
+ TypedData_Get_Struct(self, FrtQuery, &frb_typed_range_query_t, q);
1204
+ q = frt_trq_init(q, a.field, a.lterm, a.uterm, a.include_lower, a.include_upper);
1205
+ q->rquery = self;
1190
1206
  return self;
1191
1207
  }
1192
1208
 
@@ -1196,6 +1212,49 @@ frb_trq_init(VALUE self, VALUE rfield, VALUE roptions)
1196
1212
  *
1197
1213
  ****************************************************************************/
1198
1214
 
1215
+ static size_t frb_phrase_query_size(const void *p) {
1216
+ return sizeof(FrtPhraseQuery);
1217
+ (void)p;
1218
+ }
1219
+
1220
+ const rb_data_type_t frb_phrase_query_t = {
1221
+ .wrap_struct_name = "FrbPhraseQuery",
1222
+ .function = {
1223
+ .dmark = NULL,
1224
+ .dfree = frb_q_free,
1225
+ .dsize = frb_phrase_query_size,
1226
+ .dcompact = NULL,
1227
+ .reserved = {0},
1228
+ },
1229
+ .parent = NULL,
1230
+ .data = NULL,
1231
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
1232
+ };
1233
+
1234
+ static VALUE frb_phq_alloc(VALUE rclass) {
1235
+ FrtQuery *phq = frt_phq_alloc();
1236
+ return TypedData_Wrap_Struct(rclass, &frb_phrase_query_t, phq);
1237
+ }
1238
+
1239
+ typedef struct frb_phq_args {
1240
+ VALUE self;
1241
+ VALUE argc;
1242
+ VALUE *argv;
1243
+ ID field;
1244
+ int slop;
1245
+ } frb_phq_args;
1246
+
1247
+ VALUE frb_phq_init_2(VALUE args) {
1248
+ frb_phq_args *a = (frb_phq_args *)args;
1249
+ VALUE rfield, rslop;
1250
+ rb_scan_args(a->argc, a->argv, "11", &rfield, &rslop);
1251
+ a->field = frb_field(rfield);
1252
+ if (rslop != Qnil) {
1253
+ a->slop = FIX2INT(rslop);
1254
+ }
1255
+ return Qnil;
1256
+ }
1257
+
1199
1258
  /*
1200
1259
  * call-seq:
1201
1260
  * PhraseQuery.new(field, slop = 0) -> phrase_query
@@ -1203,18 +1262,16 @@ frb_trq_init(VALUE self, VALUE rfield, VALUE roptions)
1203
1262
  * Create a new PhraseQuery on the field +field+. You need to add terms to
1204
1263
  * the query it will do anything of value. See PhraseQuery#add_term.
1205
1264
  */
1206
- static VALUE
1207
- frb_phq_init(int argc, VALUE *argv, VALUE self)
1208
- {
1209
- VALUE rfield, rslop;
1265
+ static VALUE frb_phq_init(int argc, VALUE *argv, VALUE self) {
1266
+ frb_phq_args args = { .self = self, .argc = argc, .argv = argv };
1267
+ rb_rescue(frb_phq_init_2, (VALUE)&args, frb_q_init_r, (VALUE)&args);
1210
1268
  FrtQuery *q;
1211
- rb_scan_args(argc, argv, "11", &rfield, &rslop);
1212
- q = frt_phq_new(frb_field(rfield));
1269
+ TypedData_Get_Struct(self, FrtQuery, &frb_phrase_query_t, q);
1270
+ frt_phq_init(q, args.field);
1213
1271
  if (argc == 2) {
1214
- ((FrtPhraseQuery *)q)->slop = FIX2INT(rslop);
1272
+ ((FrtPhraseQuery *)q)->slop = args.slop;
1215
1273
  }
1216
- Frt_Wrap_Struct(self, NULL, &frb_q_free, q);
1217
- object_add(q, self);
1274
+ q->rquery = self;
1218
1275
  return self;
1219
1276
  }
1220
1277
 
@@ -1239,7 +1296,7 @@ frb_phq_add(int argc, VALUE *argv, VALUE self)
1239
1296
  {
1240
1297
  VALUE rterm, rpos_inc;
1241
1298
  int pos_inc = 1;
1242
- GET_Q();
1299
+ FrtQuery *q = (FrtQuery *)DATA_PTR(self);
1243
1300
  if (rb_scan_args(argc, argv, "11", &rterm, &rpos_inc) == 2) {
1244
1301
  pos_inc = FIX2INT(rpos_inc);
1245
1302
  }
@@ -1282,9 +1339,8 @@ frb_phq_add(int argc, VALUE *argv, VALUE self)
1282
1339
  * description for more information on slop
1283
1340
  */
1284
1341
  static VALUE
1285
- frb_phq_get_slop(VALUE self)
1286
- {
1287
- GET_Q();
1342
+ frb_phq_get_slop(VALUE self) {
1343
+ FrtQuery *q = (FrtQuery *)DATA_PTR(self);
1288
1344
  return INT2FIX(((FrtPhraseQuery *)q)->slop);
1289
1345
  }
1290
1346
 
@@ -1296,9 +1352,8 @@ frb_phq_get_slop(VALUE self)
1296
1352
  * for more information on slop
1297
1353
  */
1298
1354
  static VALUE
1299
- frb_phq_set_slop(VALUE self, VALUE rslop)
1300
- {
1301
- GET_Q();
1355
+ frb_phq_set_slop(VALUE self, VALUE rslop) {
1356
+ FrtQuery *q = (FrtQuery *)DATA_PTR(self);
1302
1357
  ((FrtPhraseQuery *)q)->slop = FIX2INT(rslop);
1303
1358
  return self;
1304
1359
  }
@@ -1309,6 +1364,51 @@ frb_phq_set_slop(VALUE self, VALUE rslop)
1309
1364
  *
1310
1365
  ****************************************************************************/
1311
1366
 
1367
+ static size_t frb_prefix_query_size(const void *p) {
1368
+ return sizeof(FrtPrefixQuery);
1369
+ (void)p;
1370
+ }
1371
+
1372
+ const rb_data_type_t frb_prefix_query_t = {
1373
+ .wrap_struct_name = "FrbPrefixQuery",
1374
+ .function = {
1375
+ .dmark = NULL,
1376
+ .dfree = frb_q_free,
1377
+ .dsize = frb_prefix_query_size,
1378
+ .dcompact = NULL,
1379
+ .reserved = {0},
1380
+ },
1381
+ .parent = NULL,
1382
+ .data = NULL,
1383
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
1384
+ };
1385
+
1386
+ static VALUE frb_prq_alloc(VALUE rclass) {
1387
+ FrtQuery *pq = frt_prefixq_alloc();
1388
+ return TypedData_Wrap_Struct(rclass, &frb_prefix_query_t, pq);
1389
+ }
1390
+
1391
+ typedef struct frb_prq_args {
1392
+ VALUE self;
1393
+ VALUE argc;
1394
+ VALUE *argv;
1395
+ ID field;
1396
+ char *term;
1397
+ int max_terms;
1398
+ } frb_prq_args;
1399
+
1400
+ VALUE frb_prq_init_2(VALUE args) {
1401
+ frb_prq_args *a = (frb_prq_args *)args;
1402
+ VALUE rfield, rterm, rmax_terms;
1403
+ a->max_terms = FIX2INT(rb_cvar_get(cMultiTermQuery, id_default_max_terms));
1404
+ if (rb_scan_args(a->argc, a->argv, "21", &rfield, &rterm, &rmax_terms) == 3) {
1405
+ a->max_terms = get_max_terms(rmax_terms, a->max_terms);
1406
+ }
1407
+ a->field = frb_field(rfield);
1408
+ a->term = StringValuePtr(rterm);
1409
+ return Qnil;
1410
+ }
1411
+
1312
1412
  /*
1313
1413
  * call-seq:
1314
1414
  * PrefixQuery.new(field, prefix, options = {}) -> prefix-query
@@ -1325,10 +1425,15 @@ frb_phq_set_slop(VALUE self, VALUE rslop)
1325
1425
  * +:max_terms+ which limits the number of terms that get added to the query.
1326
1426
  * By default it is set to 512.
1327
1427
  */
1328
- static VALUE
1329
- frb_prq_init(int argc, VALUE *argv, VALUE self)
1330
- {
1331
- return frb_mtq_init_specific(argc, argv, self, &frt_prefixq_new);
1428
+ static VALUE frb_prq_init(int argc, VALUE *argv, VALUE self) {
1429
+ frb_prq_args args = { .self = self, .argc = argc, .argv = argv };
1430
+ rb_rescue(frb_prq_init_2, (VALUE)&args, frb_q_init_r, (VALUE)&args);
1431
+ FrtQuery *q;
1432
+ TypedData_Get_Struct(self, FrtQuery, &frb_prefix_query_t, q);
1433
+ frt_prefixq_init(q, args.field, args.term);
1434
+ FrtMTQMaxTerms(q) = args.max_terms;
1435
+ q->rquery = self;
1436
+ return self;
1332
1437
  }
1333
1438
 
1334
1439
  /****************************************************************************
@@ -1337,6 +1442,51 @@ frb_prq_init(int argc, VALUE *argv, VALUE self)
1337
1442
  *
1338
1443
  ****************************************************************************/
1339
1444
 
1445
+ static size_t frb_wildcard_query_size(const void *p) {
1446
+ return sizeof(FrtWildCardQuery);
1447
+ (void)p;
1448
+ }
1449
+
1450
+ const rb_data_type_t frb_wilcard_query_t = {
1451
+ .wrap_struct_name = "FrbWildcardQuery",
1452
+ .function = {
1453
+ .dmark = NULL,
1454
+ .dfree = frb_q_free,
1455
+ .dsize = frb_wildcard_query_size,
1456
+ .dcompact = NULL,
1457
+ .reserved = {0},
1458
+ },
1459
+ .parent = NULL,
1460
+ .data = NULL,
1461
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
1462
+ };
1463
+
1464
+ static VALUE frb_wcq_alloc(VALUE rclass) {
1465
+ FrtQuery *wq = frt_wcq_alloc();
1466
+ return TypedData_Wrap_Struct(rclass, &frb_wilcard_query_t, wq);
1467
+ }
1468
+
1469
+ typedef struct frb_wcq_args {
1470
+ VALUE self;
1471
+ VALUE argc;
1472
+ VALUE *argv;
1473
+ ID field;
1474
+ char *term;
1475
+ int max_terms;
1476
+ } frb_wcq_args;
1477
+
1478
+ VALUE frb_wcq_init_2(VALUE args) {
1479
+ frb_wcq_args *a = (frb_wcq_args *)args;
1480
+ VALUE rfield, rterm, rmax_terms;
1481
+ a->max_terms = FIX2INT(rb_cvar_get(cMultiTermQuery, id_default_max_terms));
1482
+ if (rb_scan_args(a->argc, a->argv, "21", &rfield, &rterm, &rmax_terms) == 3) {
1483
+ a->max_terms = get_max_terms(rmax_terms, a->max_terms);
1484
+ }
1485
+ a->field = frb_field(rfield);
1486
+ a->term = StringValuePtr(rterm);
1487
+ return Qnil;
1488
+ }
1489
+
1340
1490
  /*
1341
1491
  * call-seq:
1342
1492
  * WildcardQuery.new(field, pattern, options = {}) -> wild-card-query
@@ -1355,10 +1505,15 @@ frb_prq_init(int argc, VALUE *argv, VALUE self)
1355
1505
  * set +:max_terms+ which limits the number of terms that get added to the
1356
1506
  * query. By default it is set to 512.
1357
1507
  */
1358
- static VALUE
1359
- frb_wcq_init(int argc, VALUE *argv, VALUE self)
1360
- {
1361
- return frb_mtq_init_specific(argc, argv, self, &frt_wcq_new);
1508
+ static VALUE frb_wcq_init(int argc, VALUE *argv, VALUE self) {
1509
+ frb_wcq_args args = { .self = self, .argc = argc, .argv = argv };
1510
+ rb_rescue(frb_wcq_init_2, (VALUE)&args, frb_q_init_r, (VALUE)&args);
1511
+ FrtQuery *q;
1512
+ TypedData_Get_Struct(self, FrtQuery, &frb_wilcard_query_t, q);
1513
+ frt_wcq_init(q, args.field, args.term);
1514
+ FrtMTQMaxTerms(q) = args.max_terms;
1515
+ q->rquery = self;
1516
+ return self;
1362
1517
  }
1363
1518
 
1364
1519
  /****************************************************************************
@@ -1367,6 +1522,79 @@ frb_wcq_init(int argc, VALUE *argv, VALUE self)
1367
1522
  *
1368
1523
  ****************************************************************************/
1369
1524
 
1525
+ static size_t frb_fuzzy_query_size(const void *p) {
1526
+ return sizeof(FrtFuzzyQuery);
1527
+ (void)p;
1528
+ }
1529
+
1530
+ const rb_data_type_t frb_fuzzy_query_t = {
1531
+ .wrap_struct_name = "FrbFuzzyQuery",
1532
+ .function = {
1533
+ .dmark = NULL,
1534
+ .dfree = frb_q_free,
1535
+ .dsize = frb_fuzzy_query_size,
1536
+ .dcompact = NULL,
1537
+ .reserved = {0},
1538
+ },
1539
+ .parent = NULL,
1540
+ .data = NULL,
1541
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
1542
+ };
1543
+
1544
+ static VALUE frb_fq_alloc(VALUE rclass) {
1545
+ FrtQuery *fq = frt_fuzq_alloc();
1546
+ return TypedData_Wrap_Struct(rclass, &frb_fuzzy_query_t, fq);
1547
+ }
1548
+
1549
+ typedef struct frb_fq_args {
1550
+ VALUE self;
1551
+ VALUE argc;
1552
+ VALUE *argv;
1553
+ ID field;
1554
+ char *term;
1555
+ float min_sim;
1556
+ int max_terms;
1557
+ int pre_len;
1558
+ } frb_fq_args;
1559
+
1560
+ VALUE frb_fq_init_2(VALUE args) {
1561
+ frb_fq_args *a = (frb_fq_args *)args;
1562
+ VALUE rfield, rterm, roptions;
1563
+ a->min_sim = (float)NUM2DBL(rb_cvar_get(cFuzzyQuery, id_default_min_similarity));
1564
+ a->pre_len = FIX2INT(rb_cvar_get(cFuzzyQuery, id_default_prefix_length));
1565
+ a->max_terms = FIX2INT(rb_cvar_get(cMultiTermQuery, id_default_max_terms));
1566
+
1567
+ if (rb_scan_args(a->argc, a->argv, "21", &rfield, &rterm, &roptions) >= 3) {
1568
+ VALUE v;
1569
+ Check_Type(roptions, T_HASH);
1570
+ if (Qnil != (v = rb_hash_aref(roptions, sym_prefix_length))) {
1571
+ a->pre_len = FIX2INT(v);
1572
+ }
1573
+ if (Qnil != (v = rb_hash_aref(roptions, sym_min_similarity))) {
1574
+ a->min_sim = (float)NUM2DBL(v);
1575
+ }
1576
+ if (Qnil != (v = rb_hash_aref(roptions, sym_max_terms))) {
1577
+ a->max_terms = FIX2INT(v);
1578
+ }
1579
+ }
1580
+
1581
+ if (a->min_sim >= 1.0f) {
1582
+ rb_raise(rb_eArgError, "%f >= 1.0. :min_similarity must be < 1.0", a->min_sim);
1583
+ } else if (a->min_sim < 0.0f) {
1584
+ rb_raise(rb_eArgError, "%f < 0.0. :min_similarity must be > 0.0", a->min_sim);
1585
+ }
1586
+ if (a->pre_len < 0) {
1587
+ rb_raise(rb_eArgError, "%d < 0. :prefix_length must be >= 0", a->pre_len);
1588
+ }
1589
+ if (a->max_terms < 0) {
1590
+ rb_raise(rb_eArgError, "%d < 0. :max_terms must be >= 0", a->max_terms);
1591
+ }
1592
+
1593
+ a->field = frb_field(rfield);
1594
+ a->term = StringValuePtr(rterm);
1595
+ return Qnil;
1596
+ }
1597
+
1370
1598
  /*
1371
1599
  * call-seq:
1372
1600
  * FuzzyQuery.new(field, term, options = {}) -> fuzzy-query
@@ -1407,53 +1635,13 @@ frb_wcq_init(int argc, VALUE *argv, VALUE self)
1407
1635
  * not usually a problem with FuzzyQueries unless you set
1408
1636
  * +:min_similarity+ to a very low value.
1409
1637
  */
1410
- static VALUE
1411
- frb_fq_init(int argc, VALUE *argv, VALUE self)
1412
- {
1638
+ static VALUE frb_fq_init(int argc, VALUE *argv, VALUE self) {
1639
+ frb_fq_args args = { .self = self, .argc = argc, .argv = argv };
1640
+ rb_rescue(frb_fq_init_2, (VALUE)&args, frb_q_init_r, (VALUE)&args);
1413
1641
  FrtQuery *q;
1414
- VALUE rfield, rterm, roptions;
1415
- float min_sim =
1416
- (float)NUM2DBL(rb_cvar_get(cFuzzyQuery, id_default_min_similarity));
1417
- int pre_len =
1418
- FIX2INT(rb_cvar_get(cFuzzyQuery, id_default_prefix_length));
1419
- int max_terms =
1420
- FIX2INT(rb_cvar_get(cMultiTermQuery, id_default_max_terms));
1421
-
1422
-
1423
- if (rb_scan_args(argc, argv, "21", &rfield, &rterm, &roptions) >= 3) {
1424
- VALUE v;
1425
- Check_Type(roptions, T_HASH);
1426
- if (Qnil != (v = rb_hash_aref(roptions, sym_prefix_length))) {
1427
- pre_len = FIX2INT(v);
1428
- }
1429
- if (Qnil != (v = rb_hash_aref(roptions, sym_min_similarity))) {
1430
- min_sim = (float)NUM2DBL(v);
1431
- }
1432
- if (Qnil != (v = rb_hash_aref(roptions, sym_max_terms))) {
1433
- max_terms = FIX2INT(v);
1434
- }
1435
- }
1436
-
1437
- if (min_sim >= 1.0f) {
1438
- rb_raise(rb_eArgError,
1439
- "%f >= 1.0. :min_similarity must be < 1.0", min_sim);
1440
- } else if (min_sim < 0.0f) {
1441
- rb_raise(rb_eArgError,
1442
- "%f < 0.0. :min_similarity must be > 0.0", min_sim);
1443
- }
1444
- if (pre_len < 0) {
1445
- rb_raise(rb_eArgError,
1446
- "%d < 0. :prefix_length must be >= 0", pre_len);
1447
- }
1448
- if (max_terms < 0) {
1449
- rb_raise(rb_eArgError,
1450
- "%d < 0. :max_terms must be >= 0", max_terms);
1451
- }
1452
-
1453
- q = frt_fuzq_new_conf(frb_field(rfield), StringValuePtr(rterm),
1454
- min_sim, pre_len, max_terms);
1455
- Frt_Wrap_Struct(self, NULL, &frb_q_free, q);
1456
- object_add(q, self);
1642
+ TypedData_Get_Struct(self, FrtQuery, &frb_fuzzy_query_t, q);
1643
+ frt_fuzq_init_conf(q, args.field, args.term, args.min_sim, args.pre_len, args.max_terms);
1644
+ q->rquery = self;
1457
1645
  return self;
1458
1646
  }
1459
1647
 
@@ -1464,9 +1652,8 @@ frb_fq_init(int argc, VALUE *argv, VALUE self)
1464
1652
  * Get the +:prefix_length+ for the query.
1465
1653
  */
1466
1654
  static VALUE
1467
- frb_fq_pre_len(VALUE self)
1468
- {
1469
- GET_Q();
1655
+ frb_fq_pre_len(VALUE self) {
1656
+ FrtQuery *q = (FrtQuery *)DATA_PTR(self);
1470
1657
  return INT2FIX(((FrtFuzzyQuery *)q)->pre_len);
1471
1658
  }
1472
1659
 
@@ -1477,9 +1664,8 @@ frb_fq_pre_len(VALUE self)
1477
1664
  * Get the +:min_similarity+ for the query.
1478
1665
  */
1479
1666
  static VALUE
1480
- frb_fq_min_sim(VALUE self)
1481
- {
1482
- GET_Q();
1667
+ frb_fq_min_sim(VALUE self) {
1668
+ FrtQuery *q = (FrtQuery *)DATA_PTR(self);
1483
1669
  return rb_float_new((double)((FrtFuzzyQuery *)q)->min_sim);
1484
1670
  }
1485
1671
 
@@ -1490,8 +1676,7 @@ frb_fq_min_sim(VALUE self)
1490
1676
  * Get the default value for +:min_similarity+
1491
1677
  */
1492
1678
  static VALUE
1493
- frb_fq_get_dms(VALUE self)
1494
- {
1679
+ frb_fq_get_dms(VALUE self) {
1495
1680
  return rb_cvar_get(cFuzzyQuery, id_default_min_similarity);
1496
1681
  }
1497
1682
 
@@ -1557,13 +1742,28 @@ frb_fq_set_dpl(VALUE self, VALUE val)
1557
1742
  *
1558
1743
  ****************************************************************************/
1559
1744
 
1560
- static VALUE
1561
- frb_maq_alloc(VALUE klass)
1562
- {
1745
+ static size_t frb_match_all_query_size(const void *p) {
1746
+ return sizeof(FrtQuery);
1747
+ (void)p;
1748
+ }
1749
+
1750
+ const rb_data_type_t frb_match_all_query_t = {
1751
+ .wrap_struct_name = "FrbMatchAllQuery",
1752
+ .function = {
1753
+ .dmark = NULL,
1754
+ .dfree = frb_q_free,
1755
+ .dsize = frb_match_all_query_size,
1756
+ .dcompact = NULL,
1757
+ .reserved = {0},
1758
+ },
1759
+ .parent = NULL,
1760
+ .data = NULL,
1761
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
1762
+ };
1763
+
1764
+ static VALUE frb_maq_alloc(VALUE rclass) {
1563
1765
  FrtQuery *q = frt_maq_new();
1564
- VALUE self = Data_Wrap_Struct(klass, NULL, &frb_q_free, q);
1565
- object_add(q, self);
1566
- return self;
1766
+ return TypedData_Wrap_Struct(rclass, &frb_match_all_query_t, q);
1567
1767
  }
1568
1768
 
1569
1769
  /*
@@ -1572,9 +1772,10 @@ frb_maq_alloc(VALUE klass)
1572
1772
  *
1573
1773
  * Create a query which matches all documents.
1574
1774
  */
1575
- static VALUE
1576
- frb_maq_init(VALUE self)
1577
- {
1775
+ static VALUE frb_maq_init(VALUE self) {
1776
+ FrtQuery *q;
1777
+ TypedData_Get_Struct(self, FrtQuery, &frb_match_all_query_t, q);
1778
+ q->rquery = self;
1578
1779
  return self;
1579
1780
  }
1580
1781
 
@@ -1584,6 +1785,30 @@ frb_maq_init(VALUE self)
1584
1785
  *
1585
1786
  ****************************************************************************/
1586
1787
 
1788
+ static size_t frb_constant_score_query_size(const void *p) {
1789
+ return sizeof(FrtConstantScoreQuery);
1790
+ (void)p;
1791
+ }
1792
+
1793
+ const rb_data_type_t frb_constant_score_query_t = {
1794
+ .wrap_struct_name = "FrbConstantScoreQuery",
1795
+ .function = {
1796
+ .dmark = NULL,
1797
+ .dfree = frb_q_free,
1798
+ .dsize = frb_constant_score_query_size,
1799
+ .dcompact = NULL,
1800
+ .reserved = {0},
1801
+ },
1802
+ .parent = NULL,
1803
+ .data = NULL,
1804
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
1805
+ };
1806
+
1807
+ static VALUE frb_csq_alloc(VALUE rclass) {
1808
+ FrtQuery *csq = frt_csq_alloc();
1809
+ return TypedData_Wrap_Struct(rclass, &frb_constant_score_query_t, csq);
1810
+ }
1811
+
1587
1812
  /*
1588
1813
  * call-seq:
1589
1814
  * ConstantScoreQuery.new(filter) -> query
@@ -1591,16 +1816,12 @@ frb_maq_init(VALUE self)
1591
1816
  * Create a ConstantScoreQuery which uses +filter+ to match documents giving
1592
1817
  * each document a constant score.
1593
1818
  */
1594
- static VALUE
1595
- frb_csq_init(VALUE self, VALUE rfilter)
1596
- {
1819
+ static VALUE frb_csq_init(VALUE self, VALUE rfilter) {
1597
1820
  FrtQuery *q;
1598
- FrtFilter *filter;
1599
- Data_Get_Struct(rfilter, FrtFilter, filter);
1600
- q = frt_csq_new(filter);
1601
-
1602
- Frt_Wrap_Struct(self, NULL, &frb_q_free, q);
1603
- object_add(q, self);
1821
+ FrtFilter *filter = DATA_PTR(rfilter);
1822
+ TypedData_Get_Struct(self, FrtQuery, &frb_constant_score_query_t, q);
1823
+ frt_csq_init(q, filter);
1824
+ q->rquery = self;
1604
1825
  return self;
1605
1826
  }
1606
1827
 
@@ -1610,12 +1831,36 @@ frb_csq_init(VALUE self, VALUE rfilter)
1610
1831
  *
1611
1832
  ****************************************************************************/
1612
1833
 
1613
- static void
1614
- frb_fqq_mark(void *p)
1615
- {
1834
+ static size_t frb_filtered_query_size(const void *p) {
1835
+ return sizeof(FrtFilteredQuery);
1836
+ (void)p;
1837
+ }
1838
+
1839
+ static void frb_fqq_mark(void *p) {
1616
1840
  FrtFilteredQuery *fq = (FrtFilteredQuery *)p;
1617
- frb_gc_mark(fq->query);
1618
- frb_gc_mark(fq->filter);
1841
+ if (fq->query->rquery)
1842
+ rb_gc_mark(fq->query->rquery);
1843
+ if (fq->filter->rfilter)
1844
+ rb_gc_mark(fq->filter->rfilter);
1845
+ }
1846
+
1847
+ const rb_data_type_t frb_filtered_query_t = {
1848
+ .wrap_struct_name = "FrbFilteredQuery",
1849
+ .function = {
1850
+ .dmark = frb_fqq_mark,
1851
+ .dfree = frb_q_free,
1852
+ .dsize = frb_filtered_query_size,
1853
+ .dcompact = NULL,
1854
+ .reserved = {0},
1855
+ },
1856
+ .parent = NULL,
1857
+ .data = NULL,
1858
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
1859
+ };
1860
+
1861
+ static VALUE frb_fqq_alloc(VALUE rclass) {
1862
+ FrtQuery *fqq = frt_fq_alloc();
1863
+ return TypedData_Wrap_Struct(rclass, &frb_filtered_query_t, fqq);
1619
1864
  }
1620
1865
 
1621
1866
  /*
@@ -1624,18 +1869,15 @@ frb_fqq_mark(void *p)
1624
1869
  *
1625
1870
  * Create a new FilteredQuery which filters +query+ with +filter+.
1626
1871
  */
1627
- static VALUE
1628
- frb_fqq_init(VALUE self, VALUE rquery, VALUE rfilter)
1629
- {
1630
- FrtQuery *sq, *q;
1631
- FrtFilter *f;
1632
- Data_Get_Struct(rquery, FrtQuery, sq);
1633
- Data_Get_Struct(rfilter, FrtFilter, f);
1634
- q = frt_fq_new(sq, f);
1872
+ static VALUE frb_fqq_init(VALUE self, VALUE rquery, VALUE rfilter) {
1873
+ FrtQuery *q;
1874
+ FrtFilter *f = DATA_PTR(rfilter);
1875
+ FrtQuery *sq = DATA_PTR(rquery);
1876
+ TypedData_Get_Struct(self, FrtQuery, &frb_filtered_query_t, q);
1877
+ frt_fq_init(q, sq, f);
1635
1878
  FRT_REF(sq);
1636
1879
  FRT_REF(f);
1637
- Frt_Wrap_Struct(self, &frb_fqq_mark, &frb_q_free, q);
1638
- object_add(q, self);
1880
+ q->rquery = self;
1639
1881
  return self;
1640
1882
  }
1641
1883
 
@@ -1645,6 +1887,45 @@ frb_fqq_init(VALUE self, VALUE rquery, VALUE rfilter)
1645
1887
  *
1646
1888
  ****************************************************************************/
1647
1889
 
1890
+ static size_t frb_span_term_query_size(const void *p) {
1891
+ return sizeof(FrtSpanTermQuery);
1892
+ (void)p;
1893
+ }
1894
+
1895
+ const rb_data_type_t frb_span_term_query_t = {
1896
+ .wrap_struct_name = "FrbSpanTermQuery",
1897
+ .function = {
1898
+ .dmark = NULL,
1899
+ .dfree = frb_q_free,
1900
+ .dsize = frb_span_term_query_size,
1901
+ .dcompact = NULL,
1902
+ .reserved = {0},
1903
+ },
1904
+ .parent = NULL,
1905
+ .data = NULL,
1906
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
1907
+ };
1908
+
1909
+ static VALUE frb_spantq_alloc(VALUE rclass) {
1910
+ FrtQuery *stq = frt_spantq_alloc();
1911
+ return TypedData_Wrap_Struct(rclass, &frb_span_term_query_t, stq);
1912
+ }
1913
+
1914
+ typedef struct frb_spantq_args {
1915
+ VALUE self;
1916
+ VALUE rfield;
1917
+ VALUE rterm;
1918
+ ID field;
1919
+ char *term;
1920
+ } frb_spantq_args;
1921
+
1922
+ VALUE frb_spantq_init_2(VALUE args) {
1923
+ frb_spantq_args *a = (frb_spantq_args *)args;
1924
+ a->field = frb_field(a->rfield);
1925
+ a->term = StringValuePtr(a->rterm);
1926
+ return Qnil;
1927
+ }
1928
+
1648
1929
  /*
1649
1930
  * call-seq:
1650
1931
  * SpanTermQuery.new(field, term) -> query
@@ -1652,12 +1933,13 @@ frb_fqq_init(VALUE self, VALUE rquery, VALUE rfilter)
1652
1933
  * Create a new SpanTermQuery which matches all documents with the term
1653
1934
  * +term+ in the field +field+.
1654
1935
  */
1655
- static VALUE
1656
- frb_spantq_init(VALUE self, VALUE rfield, VALUE rterm)
1657
- {
1658
- FrtQuery *q = frt_spantq_new(frb_field(rfield), StringValuePtr(rterm));
1659
- Frt_Wrap_Struct(self, NULL, &frb_q_free, q);
1660
- object_add(q, self);
1936
+ static VALUE frb_spantq_init(VALUE self, VALUE rfield, VALUE rterm) {
1937
+ frb_spantq_args args = { .self = self, .rfield = rfield, .rterm = rterm };
1938
+ rb_rescue(frb_spantq_init_2, (VALUE)&args, frb_q_init_r, (VALUE)&args);
1939
+ FrtQuery *q;
1940
+ TypedData_Get_Struct(self, FrtQuery, &frb_span_term_query_t, q);
1941
+ frt_spantq_init(q, args.field, args.term);
1942
+ q->rquery = self;
1661
1943
  return self;
1662
1944
  }
1663
1945
 
@@ -1667,6 +1949,42 @@ frb_spantq_init(VALUE self, VALUE rfield, VALUE rterm)
1667
1949
  *
1668
1950
  ****************************************************************************/
1669
1951
 
1952
+ static size_t frb_span_multi_term_query_size(const void *p) {
1953
+ return sizeof(FrtSpanMultiTermQuery);
1954
+ (void)p;
1955
+ }
1956
+
1957
+ const rb_data_type_t frb_span_multi_term_query_t = {
1958
+ .wrap_struct_name = "FrbSpanMultiTermQuery",
1959
+ .function = {
1960
+ .dmark = NULL,
1961
+ .dfree = frb_q_free,
1962
+ .dsize = frb_span_multi_term_query_size,
1963
+ .dcompact = NULL,
1964
+ .reserved = {0},
1965
+ },
1966
+ .parent = NULL,
1967
+ .data = NULL,
1968
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
1969
+ };
1970
+
1971
+ static VALUE frb_spanmtq_alloc(VALUE rclass) {
1972
+ FrtQuery *smtq = frt_spanmtq_alloc();
1973
+ return TypedData_Wrap_Struct(rclass, &frb_span_multi_term_query_t, smtq);
1974
+ }
1975
+
1976
+ typedef struct frb_spanmtq_args {
1977
+ VALUE self;
1978
+ VALUE rfield;
1979
+ ID field;
1980
+ } frb_spanmtq_args;
1981
+
1982
+ VALUE frb_spanmtq_init_2(VALUE args) {
1983
+ frb_spanmtq_args *a = (frb_spanmtq_args *)args;
1984
+ a->field = frb_field(a->rfield);
1985
+ return Qnil;
1986
+ }
1987
+
1670
1988
  /*
1671
1989
  * call-seq:
1672
1990
  * SpanMultiTermQuery.new(field, terms) -> query
@@ -1674,16 +1992,17 @@ frb_spantq_init(VALUE self, VALUE rfield, VALUE rterm)
1674
1992
  * Create a new SpanMultiTermQuery which matches all documents with the terms
1675
1993
  * +terms+ in the field +field+. +terms+ should be an array of Strings.
1676
1994
  */
1677
- static VALUE
1678
- frb_spanmtq_init(VALUE self, VALUE rfield, VALUE rterms)
1679
- {
1680
- FrtQuery *q = frt_spanmtq_new(frb_field(rfield));
1995
+ static VALUE frb_spanmtq_init(VALUE self, VALUE rfield, VALUE rterms) {
1996
+ frb_spanmtq_args args = { .self = self, .rfield = rfield };
1997
+ rb_rescue(frb_spanmtq_init_2, (VALUE)&args, frb_q_init_r, (VALUE)&args);
1998
+ FrtQuery *q;
1999
+ TypedData_Get_Struct(self, FrtQuery, &frb_span_multi_term_query_t, q);
2000
+ frt_spanmtq_init(q, args.field);
1681
2001
  int i;
1682
2002
  for (i = RARRAY_LEN(rterms) - 1; i >= 0; i--) {
1683
2003
  frt_spanmtq_add_term(q, StringValuePtr(RARRAY_PTR(rterms)[i]));
1684
2004
  }
1685
- Frt_Wrap_Struct(self, NULL, &frb_q_free, q);
1686
- object_add(q, self);
2005
+ q->rquery = self;
1687
2006
  return self;
1688
2007
  }
1689
2008
 
@@ -1693,6 +2012,51 @@ frb_spanmtq_init(VALUE self, VALUE rfield, VALUE rterms)
1693
2012
  *
1694
2013
  ****************************************************************************/
1695
2014
 
2015
+ static size_t frb_span_prefix_query_size(const void *p) {
2016
+ return sizeof(FrtSpanPrefixQuery);
2017
+ (void)p;
2018
+ }
2019
+
2020
+ const rb_data_type_t frb_span_prefix_query_t = {
2021
+ .wrap_struct_name = "FrbSpanPrefixQuery",
2022
+ .function = {
2023
+ .dmark = NULL,
2024
+ .dfree = frb_q_free,
2025
+ .dsize = frb_span_prefix_query_size,
2026
+ .dcompact = NULL,
2027
+ .reserved = {0},
2028
+ },
2029
+ .parent = NULL,
2030
+ .data = NULL,
2031
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
2032
+ };
2033
+
2034
+ static VALUE frb_spanprq_alloc(VALUE rclass) {
2035
+ FrtQuery *spq = frt_spanprq_alloc();
2036
+ return TypedData_Wrap_Struct(rclass, &frb_span_prefix_query_t, spq);
2037
+ }
2038
+
2039
+ typedef struct frb_spanprq_args {
2040
+ VALUE self;
2041
+ VALUE argc;
2042
+ VALUE *argv;
2043
+ ID field;
2044
+ char *prefix;
2045
+ int max_terms;
2046
+ } frb_spanprq_args;
2047
+
2048
+ VALUE frb_spanprq_init_2(VALUE args) {
2049
+ frb_spanprq_args *a = (frb_spanprq_args *)args;
2050
+ VALUE rfield, rprefix, rmax_terms;
2051
+ a->max_terms = FRT_SPAN_PREFIX_QUERY_MAX_TERMS;
2052
+ if (rb_scan_args(a->argc, a->argv, "21", &rfield, &rprefix, &rmax_terms) == 3) {
2053
+ a->max_terms = FIX2INT(rmax_terms);
2054
+ }
2055
+ a->field = frb_field(rfield);
2056
+ a->prefix = StringValuePtr(rprefix);
2057
+ return Qnil;
2058
+ }
2059
+
1696
2060
  /*
1697
2061
  * call-seq:
1698
2062
  * SpanPrefixQuery.new(field, prefix, max_terms = 256) -> query
@@ -1700,19 +2064,14 @@ frb_spanmtq_init(VALUE self, VALUE rfield, VALUE rterms)
1700
2064
  * Create a new SpanPrefixQuery which matches all documents with the prefix
1701
2065
  * +prefix+ in the field +field+.
1702
2066
  */
1703
- static VALUE
1704
- frb_spanprq_init(int argc, VALUE *argv, VALUE self)
1705
- {
1706
- VALUE rfield, rprefix, rmax_terms;
1707
- int max_terms = FRT_SPAN_PREFIX_QUERY_MAX_TERMS;
2067
+ static VALUE frb_spanprq_init(int argc, VALUE *argv, VALUE self) {
2068
+ frb_spanprq_args args = { .self = self, .argc = argc, .argv = argv };
2069
+ rb_rescue(frb_spanprq_init_2, (VALUE)&args, frb_q_init_r, (VALUE)&args);
1708
2070
  FrtQuery *q;
1709
- if (rb_scan_args(argc, argv, "21", &rfield, &rprefix, &rmax_terms) == 3) {
1710
- max_terms = FIX2INT(rmax_terms);
1711
- }
1712
- q = frt_spanprq_new(frb_field(rfield), StringValuePtr(rprefix));
1713
- ((FrtSpanPrefixQuery *)q)->max_terms = max_terms;
1714
- Frt_Wrap_Struct(self, NULL, &frb_q_free, q);
1715
- object_add(q, self);
2071
+ TypedData_Get_Struct(self, FrtQuery, &frb_span_prefix_query_t, q);
2072
+ frt_spanprq_init(q, args.field, args.prefix);
2073
+ ((FrtSpanPrefixQuery *)q)->max_terms = args.max_terms;
2074
+ q->rquery = self;
1716
2075
  return self;
1717
2076
  }
1718
2077
 
@@ -1722,6 +2081,42 @@ frb_spanprq_init(int argc, VALUE *argv, VALUE self)
1722
2081
  *
1723
2082
  ****************************************************************************/
1724
2083
 
2084
+ static size_t frb_span_first_query_size(const void *p) {
2085
+ return sizeof(FrtSpanFirstQuery);
2086
+ (void)p;
2087
+ }
2088
+
2089
+ const rb_data_type_t frb_span_first_query_t = {
2090
+ .wrap_struct_name = "FrbSpanFirstQuery",
2091
+ .function = {
2092
+ .dmark = NULL,
2093
+ .dfree = frb_q_free,
2094
+ .dsize = frb_span_first_query_size,
2095
+ .dcompact = NULL,
2096
+ .reserved = {0},
2097
+ },
2098
+ .parent = NULL,
2099
+ .data = NULL,
2100
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
2101
+ };
2102
+
2103
+ static VALUE frb_spanfq_alloc(VALUE rclass) {
2104
+ FrtQuery *sfq = frt_spanfq_alloc();
2105
+ return TypedData_Wrap_Struct(rclass, &frb_span_first_query_t, sfq);
2106
+ }
2107
+
2108
+ typedef struct frb_spanfq_args {
2109
+ VALUE self;
2110
+ VALUE rend;
2111
+ int end;
2112
+ } frb_spanfq_args;
2113
+
2114
+ VALUE frb_spanfq_init_2(VALUE args) {
2115
+ frb_spanfq_args *a = (frb_spanfq_args *)args;
2116
+ a->end = FIX2INT(a->rend);
2117
+ return Qnil;
2118
+ }
2119
+
1725
2120
  /*
1726
2121
  * call-seq:
1727
2122
  * SpanFirstQuery.new(span_query, end) -> query
@@ -1730,15 +2125,14 @@ frb_spanprq_init(int argc, VALUE *argv, VALUE self)
1730
2125
  * matches before +end+ where +end+ is a byte-offset from the start of the
1731
2126
  * field
1732
2127
  */
1733
- static VALUE
1734
- frb_spanfq_init(VALUE self, VALUE rmatch, VALUE rend)
1735
- {
2128
+ static VALUE frb_spanfq_init(VALUE self, VALUE rmatch, VALUE rend) {
2129
+ frb_spanfq_args args = { .self = self, .rend = rend };
2130
+ rb_rescue(frb_spanfq_init_2, (VALUE)&args, frb_q_init_r, (VALUE)&args);
1736
2131
  FrtQuery *q;
1737
- FrtQuery *match;
1738
- Data_Get_Struct(rmatch, FrtQuery, match);
1739
- q = frt_spanfq_new(match, FIX2INT(rend));
1740
- Frt_Wrap_Struct(self, NULL, &frb_q_free, q);
1741
- object_add(q, self);
2132
+ FrtQuery *match = DATA_PTR(rmatch);
2133
+ TypedData_Get_Struct(self, FrtQuery, &frb_span_first_query_t, q);
2134
+ frt_spanfq_init(q, match, args.end);
2135
+ q->rquery = self;
1742
2136
  return self;
1743
2137
  }
1744
2138
 
@@ -1748,14 +2142,62 @@ frb_spanfq_init(VALUE self, VALUE rmatch, VALUE rend)
1748
2142
  *
1749
2143
  ****************************************************************************/
1750
2144
 
1751
- static void
1752
- frb_spannq_mark(void *p)
1753
- {
2145
+ static size_t frb_span_near_query_size(const void *p) {
2146
+ return sizeof(FrtSpanNearQuery);
2147
+ (void)p;
2148
+ }
2149
+
2150
+ static void frb_spannq_mark(void *p) {
1754
2151
  int i;
1755
2152
  FrtSpanNearQuery *snq = (FrtSpanNearQuery *)p;
1756
2153
  for (i = 0; i < snq->c_cnt; i++) {
1757
- frb_gc_mark(snq->clauses[i]);
2154
+ if (snq->clauses[i]->rquery)
2155
+ rb_gc_mark(snq->clauses[i]->rquery);
2156
+ }
2157
+ }
2158
+
2159
+ const rb_data_type_t frb_span_near_query_t = {
2160
+ .wrap_struct_name = "FrbSpanNearQuery",
2161
+ .function = {
2162
+ .dmark = frb_spannq_mark,
2163
+ .dfree = frb_q_free,
2164
+ .dsize = frb_span_near_query_size,
2165
+ .dcompact = NULL,
2166
+ .reserved = {0},
2167
+ },
2168
+ .parent = NULL,
2169
+ .data = NULL,
2170
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
2171
+ };
2172
+
2173
+ static VALUE frb_spannq_alloc(VALUE rclass) {
2174
+ FrtQuery *snq = frt_spannq_alloc();
2175
+ return TypedData_Wrap_Struct(rclass, &frb_span_near_query_t, snq);
2176
+ }
2177
+
2178
+ typedef struct frb_spannq_args {
2179
+ VALUE self;
2180
+ VALUE argc;
2181
+ VALUE *argv;
2182
+ int slop;
2183
+ bool in_order;
2184
+ } frb_spannq_args;
2185
+
2186
+ VALUE frb_spannq_init_2(VALUE args) {
2187
+ frb_spannq_args *a = (frb_spannq_args *)args;
2188
+ VALUE roptions = Qnil;
2189
+ a->slop = 0;
2190
+ a->in_order = false;
2191
+ if (rb_scan_args(a->argc, a->argv, "01", &roptions) > 0) {
2192
+ VALUE v;
2193
+ if (Qnil != (v = rb_hash_aref(roptions, sym_slop))) {
2194
+ a->slop = FIX2INT(v);
2195
+ }
2196
+ if (Qnil != (v = rb_hash_aref(roptions, sym_in_order))) {
2197
+ a->in_order = RTEST(v);
2198
+ }
1758
2199
  }
2200
+ return roptions;
1759
2201
  }
1760
2202
 
1761
2203
  /*
@@ -1780,24 +2222,12 @@ frb_spannq_mark(void *p)
1780
2222
  * occur in the order they were added to the query. When slop is
1781
2223
  * set to 0, this parameter will make no difference.
1782
2224
  */
1783
- static VALUE
1784
- frb_spannq_init(int argc, VALUE *argv, VALUE self)
1785
- {
2225
+ static VALUE frb_spannq_init(int argc, VALUE *argv, VALUE self) {
2226
+ frb_spannq_args args = { .self = self, .argc = argc, .argv = argv };
2227
+ VALUE roptions = rb_rescue(frb_spannq_init_2, (VALUE)&args, frb_q_init_r, (VALUE)&args);
1786
2228
  FrtQuery *q;
1787
- VALUE roptions;
1788
- int slop = 0;
1789
- bool in_order = false;
1790
-
1791
- if (rb_scan_args(argc, argv, "01", &roptions) > 0) {
1792
- VALUE v;
1793
- if (Qnil != (v = rb_hash_aref(roptions, sym_slop))) {
1794
- slop = FIX2INT(v);
1795
- }
1796
- if (Qnil != (v = rb_hash_aref(roptions, sym_in_order))) {
1797
- in_order = RTEST(v);
1798
- }
1799
- }
1800
- q = frt_spannq_new(slop, in_order);
2229
+ TypedData_Get_Struct(self, FrtQuery, &frb_span_near_query_t, q);
2230
+ frt_spannq_init(q, args.slop, args.in_order);
1801
2231
  if (argc > 0) {
1802
2232
  VALUE v;
1803
2233
  if (Qnil != (v = rb_hash_aref(roptions, sym_clauses))) {
@@ -1805,14 +2235,12 @@ frb_spannq_init(int argc, VALUE *argv, VALUE self)
1805
2235
  FrtQuery *clause;
1806
2236
  Check_Type(v, T_ARRAY);
1807
2237
  for (i = 0; i < RARRAY_LEN(v); i++) {
1808
- Data_Get_Struct(RARRAY_PTR(v)[i], FrtQuery, clause);
2238
+ clause = DATA_PTR(RARRAY_PTR(v)[i]);
1809
2239
  frt_spannq_add_clause(q, clause);
1810
2240
  }
1811
2241
  }
1812
2242
  }
1813
-
1814
- Frt_Wrap_Struct(self, &frb_spannq_mark, &frb_q_free, q);
1815
- object_add(q, self);
2243
+ q->rquery = self;
1816
2244
  return self;
1817
2245
  }
1818
2246
 
@@ -1825,12 +2253,9 @@ frb_spannq_init(int argc, VALUE *argv, VALUE self)
1825
2253
  * are added to the query which is important for matching. Note that clauses
1826
2254
  * must be SpanQueries, not other types of query.
1827
2255
  */
1828
- static VALUE
1829
- frb_spannq_add(VALUE self, VALUE rclause)
1830
- {
1831
- GET_Q();
1832
- FrtQuery *clause;
1833
- Data_Get_Struct(rclause, FrtQuery, clause);
2256
+ static VALUE frb_spannq_add(VALUE self, VALUE rclause) {
2257
+ FrtQuery *q = (FrtQuery *)DATA_PTR(self);
2258
+ FrtQuery *clause = DATA_PTR(rclause);
1834
2259
  frt_spannq_add_clause(q, clause);
1835
2260
  return self;
1836
2261
  }
@@ -1841,16 +2266,39 @@ frb_spannq_add(VALUE self, VALUE rclause)
1841
2266
  *
1842
2267
  ****************************************************************************/
1843
2268
 
1844
- static void
1845
- frb_spanoq_mark(void *p)
1846
- {
2269
+ static size_t frb_span_or_query_size(const void *p) {
2270
+ return sizeof(FrtSpanOrQuery);
2271
+ (void)p;
2272
+ }
2273
+
2274
+ static void frb_spanoq_mark(void *p) {
1847
2275
  int i;
1848
2276
  FrtSpanOrQuery *soq = (FrtSpanOrQuery *)p;
1849
2277
  for (i = 0; i < soq->c_cnt; i++) {
1850
- frb_gc_mark(soq->clauses[i]);
2278
+ if (soq->clauses[i]->rquery)
2279
+ rb_gc_mark(soq->clauses[i]->rquery);
1851
2280
  }
1852
2281
  }
1853
2282
 
2283
+ const rb_data_type_t frb_span_or_query_t = {
2284
+ .wrap_struct_name = "FrbSpanOrQuery",
2285
+ .function = {
2286
+ .dmark = frb_spanoq_mark,
2287
+ .dfree = frb_q_free,
2288
+ .dsize = frb_span_or_query_size,
2289
+ .dcompact = NULL,
2290
+ .reserved = {0},
2291
+ },
2292
+ .parent = NULL,
2293
+ .data = NULL,
2294
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
2295
+ };
2296
+
2297
+ static VALUE frb_spanoq_alloc(VALUE rclass) {
2298
+ FrtQuery *soq = frt_spanoq_new();
2299
+ return TypedData_Wrap_Struct(rclass, &frb_span_or_query_t, soq);
2300
+ }
2301
+
1854
2302
  /*
1855
2303
  * call-seq:
1856
2304
  * SpanOrQuery.new(options = {}) -> query
@@ -1859,24 +2307,20 @@ frb_spanoq_mark(void *p)
1859
2307
  * clauses with the occur value of :should. The difference is that it can be
1860
2308
  * passed to other SpanQuerys like SpanNearQuery.
1861
2309
  */
1862
- static VALUE
1863
- frb_spanoq_init(int argc, VALUE *argv, VALUE self)
1864
- {
2310
+ static VALUE frb_spanoq_init(int argc, VALUE *argv, VALUE self) {
1865
2311
  FrtQuery *q;
1866
2312
  VALUE rclauses;
1867
-
1868
- q = frt_spanoq_new();
2313
+ TypedData_Get_Struct(self, FrtQuery, &frb_span_or_query_t, q);
1869
2314
  if (rb_scan_args(argc, argv, "01", &rclauses) > 0) {
1870
2315
  int i;
1871
2316
  FrtQuery *clause;
1872
2317
  Check_Type(rclauses, T_ARRAY);
1873
2318
  for (i = 0; i < RARRAY_LEN(rclauses); i++) {
1874
- Data_Get_Struct(RARRAY_PTR(rclauses)[i], FrtQuery, clause);
2319
+ clause = DATA_PTR(RARRAY_PTR(rclauses)[i]);
1875
2320
  frt_spanoq_add_clause(q, clause);
1876
2321
  }
1877
2322
  }
1878
- Frt_Wrap_Struct(self, &frb_spanoq_mark, &frb_q_free, q);
1879
- object_add(q, self);
2323
+ q->rquery = self;
1880
2324
  return self;
1881
2325
  }
1882
2326
 
@@ -1888,12 +2332,9 @@ frb_spanoq_init(int argc, VALUE *argv, VALUE self)
1888
2332
  * Add a clause to the SpanOrQuery. Note that clauses must be SpanQueries,
1889
2333
  * not other types of query.
1890
2334
  */
1891
- static VALUE
1892
- frb_spanoq_add(VALUE self, VALUE rclause)
1893
- {
1894
- GET_Q();
1895
- FrtQuery *clause;
1896
- Data_Get_Struct(rclause, FrtQuery, clause);
2335
+ static VALUE frb_spanoq_add(VALUE self, VALUE rclause) {
2336
+ FrtQuery *q = (FrtQuery *)DATA_PTR(self);
2337
+ FrtQuery *clause = DATA_PTR(rclause);
1897
2338
  frt_spanoq_add_clause(q, clause);
1898
2339
  return self;
1899
2340
  }
@@ -1904,12 +2345,36 @@ frb_spanoq_add(VALUE self, VALUE rclause)
1904
2345
  *
1905
2346
  ****************************************************************************/
1906
2347
 
1907
- static void
1908
- frb_spanxq_mark(void *p)
1909
- {
2348
+ static size_t frb_span_not_query_size(const void *p) {
2349
+ return sizeof(FrtSpanNotQuery);
2350
+ (void)p;
2351
+ }
2352
+
2353
+ static void frb_spanxq_mark(void *p) {
1910
2354
  FrtSpanNotQuery *sxq = (FrtSpanNotQuery *)p;
1911
- frb_gc_mark(sxq->inc);
1912
- frb_gc_mark(sxq->exc);
2355
+ if (sxq->inc->rquery)
2356
+ rb_gc_mark(sxq->inc->rquery);
2357
+ if (sxq->exc->rquery)
2358
+ rb_gc_mark(sxq->exc->rquery);
2359
+ }
2360
+
2361
+ const rb_data_type_t frb_span_not_query_t = {
2362
+ .wrap_struct_name = "FrbSpanNotQuery",
2363
+ .function = {
2364
+ .dmark = frb_spanxq_mark,
2365
+ .dfree = frb_q_free,
2366
+ .dsize = frb_span_not_query_size,
2367
+ .dcompact = NULL,
2368
+ .reserved = {0},
2369
+ },
2370
+ .parent = NULL,
2371
+ .data = NULL,
2372
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
2373
+ };
2374
+
2375
+ static VALUE frb_spanxq_alloc(VALUE rclass) {
2376
+ FrtQuery *snq = frt_spanxq_alloc();
2377
+ return TypedData_Wrap_Struct(rclass, &frb_span_not_query_t, snq);
1913
2378
  }
1914
2379
 
1915
2380
  /*
@@ -1919,15 +2384,13 @@ frb_spanxq_mark(void *p)
1919
2384
  * Create a new SpanNotQuery which matches all documents which match
1920
2385
  * +include_query+ and don't match +exclude_query+.
1921
2386
  */
1922
- static VALUE
1923
- frb_spanxq_init(VALUE self, VALUE rinc, VALUE rexc)
1924
- {
2387
+ static VALUE frb_spanxq_init(VALUE self, VALUE rinc, VALUE rexc) {
1925
2388
  FrtQuery *q;
1926
- Check_Type(rinc, T_DATA);
1927
- Check_Type(rexc, T_DATA);
1928
- q = frt_spanxq_new(DATA_PTR(rinc), DATA_PTR(rexc));
1929
- Frt_Wrap_Struct(self, &frb_spanxq_mark, &frb_q_free, q);
1930
- object_add(q, self);
2389
+ //Check_Type(rinc, T_DATA);
2390
+ //Check_Type(rexc, T_DATA);
2391
+ TypedData_Get_Struct(self, FrtQuery, &frb_span_not_query_t, q);
2392
+ frt_spanxq_init(q, DATA_PTR(rinc), DATA_PTR(rexc));
2393
+ q->rquery = self;
1931
2394
  return self;
1932
2395
  }
1933
2396
 
@@ -1937,10 +2400,7 @@ frb_spanxq_init(VALUE self, VALUE rinc, VALUE rexc)
1937
2400
  *
1938
2401
  ****************************************************************************/
1939
2402
 
1940
- static void
1941
- frb_f_free(void *p)
1942
- {
1943
- object_del(p);
2403
+ static void frb_f_free(void *p) {
1944
2404
  frt_filt_deref((FrtFilter *)p);
1945
2405
  }
1946
2406
 
@@ -1953,9 +2413,7 @@ frb_f_free(void *p)
1953
2413
  * Return a human readable string representing the Filter object that the
1954
2414
  * method was called on.
1955
2415
  */
1956
- static VALUE
1957
- frb_f_to_s(VALUE self)
1958
- {
2416
+ static VALUE frb_f_to_s(VALUE self) {
1959
2417
  VALUE rstr;
1960
2418
  char *str;
1961
2419
  GET_F();
@@ -1974,13 +2432,11 @@ extern VALUE frb_get_bv(FrtBitVector *bv);
1974
2432
  * Get the bit_vector used by this filter. This method will usually be used
1975
2433
  * to group filters or apply filters to other filters.
1976
2434
  */
1977
- static VALUE
1978
- frb_f_get_bits(VALUE self, VALUE rindex_reader)
1979
- {
2435
+ static VALUE frb_f_get_bits(VALUE self, VALUE rindex_reader) {
1980
2436
  FrtBitVector *bv;
1981
2437
  FrtIndexReader *ir;
1982
2438
  GET_F();
1983
- Data_Get_Struct(rindex_reader, FrtIndexReader, ir);
2439
+ TypedData_Get_Struct(rindex_reader, FrtIndexReader, &frb_index_reader_t, ir);
1984
2440
  bv = frt_filt_get_bv(f, ir);
1985
2441
  return frb_get_bv(bv);
1986
2442
  }
@@ -1991,6 +2447,29 @@ frb_f_get_bits(VALUE self, VALUE rindex_reader)
1991
2447
  *
1992
2448
  ****************************************************************************/
1993
2449
 
2450
+ static size_t frb_range_filter_size(const void *p) {
2451
+ return sizeof(FrtRangeFilter);
2452
+ (void)p;
2453
+ }
2454
+
2455
+ const rb_data_type_t frb_range_filter_t = {
2456
+ .wrap_struct_name = "FrbRangeFilter",
2457
+ .function = {
2458
+ .dmark = NULL,
2459
+ .dfree = frb_f_free,
2460
+ .dsize = frb_range_filter_size,
2461
+ .dcompact = NULL,
2462
+ .reserved = {0},
2463
+ },
2464
+ .parent = NULL,
2465
+ .data = NULL,
2466
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
2467
+ };
2468
+
2469
+ static VALUE frb_rf_alloc(VALUE rclass) {
2470
+ FrtFilter *rf = frt_rfilt_alloc();
2471
+ return TypedData_Wrap_Struct(rclass, &frb_range_filter_t, rf);
2472
+ }
1994
2473
 
1995
2474
  /*
1996
2475
  * call-seq:
@@ -2014,21 +2493,21 @@ frb_f_get_bits(VALUE self, VALUE rindex_reader)
2014
2493
  * # is equivalent to
2015
2494
  * f = RangeFilter.new(:date, :>= => "200501", :<= => 200502)
2016
2495
  */
2017
- static VALUE
2018
- frb_rf_init(VALUE self, VALUE rfield, VALUE roptions)
2019
- {
2020
- FrtFilter *f;
2021
- char *lterm = NULL;
2022
- char *uterm = NULL;
2023
- bool include_lower = false;
2024
- bool include_upper = false;
2496
+ static VALUE frb_rf_init(VALUE self, VALUE rfield, VALUE roptions) {
2025
2497
  int ex_code = 0;
2026
2498
  const char *msg = NULL;
2027
- get_range_params(roptions, &lterm, &uterm, &include_lower, &include_upper);
2499
+ frb_rq_args a = { .self = self, .rfield = rfield, .roptions = roptions };
2500
+ rb_rescue(frb_rq_init_2, (VALUE)&a, frb_q_init_r, (VALUE)&a);
2501
+ FrtFilter *f;
2502
+ TypedData_Get_Struct(self, FrtFilter, &frb_range_filter_t, f);
2028
2503
  FRT_TRY
2029
- f = frt_rfilt_new(frb_field(rfield), lterm, uterm, include_lower, include_upper);
2030
- break;
2031
- default:
2504
+ frt_rfilt_init(f, a.field, a.lterm, a.uterm, a.include_lower, a.include_upper);
2505
+ f->rfilter = self;
2506
+ FRT_XCATCHALL
2507
+ ((struct RData *)(self))->data = NULL;
2508
+ ((struct RData *)(self))->dmark = NULL;
2509
+ ((struct RData *)(self))->dfree = NULL;
2510
+ free(f);
2032
2511
  ex_code = xcontext.excode;
2033
2512
  msg = xcontext.msg;
2034
2513
  FRT_HANDLED();
@@ -2036,8 +2515,6 @@ frb_rf_init(VALUE self, VALUE rfield, VALUE roptions)
2036
2515
 
2037
2516
  if (ex_code && msg) { frb_raise(ex_code, msg); }
2038
2517
 
2039
- Frt_Wrap_Struct(self, NULL, &frb_f_free, f);
2040
- object_add(f, self);
2041
2518
  return self;
2042
2519
  }
2043
2520
 
@@ -2047,6 +2524,29 @@ frb_rf_init(VALUE self, VALUE rfield, VALUE roptions)
2047
2524
  *
2048
2525
  ****************************************************************************/
2049
2526
 
2527
+ static size_t frb_typed_range_filter_size(const void *p) {
2528
+ return sizeof(FrtRangeFilter);
2529
+ (void)p;
2530
+ }
2531
+
2532
+ const rb_data_type_t frb_typed_range_filter_t = {
2533
+ .wrap_struct_name = "FrbTypedRangeFilter",
2534
+ .function = {
2535
+ .dmark = NULL,
2536
+ .dfree = frb_f_free,
2537
+ .dsize = frb_typed_range_filter_size,
2538
+ .dcompact = NULL,
2539
+ .reserved = {0},
2540
+ },
2541
+ .parent = NULL,
2542
+ .data = NULL,
2543
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
2544
+ };
2545
+
2546
+ static VALUE frb_trf_alloc(VALUE rclass) {
2547
+ FrtFilter *f = frt_trfilt_alloc();
2548
+ return TypedData_Wrap_Struct(rclass, &frb_typed_range_filter_t, f);
2549
+ }
2050
2550
 
2051
2551
  /*
2052
2552
  * call-seq:
@@ -2071,20 +2571,28 @@ frb_rf_init(VALUE self, VALUE rfield, VALUE roptions)
2071
2571
  * # is equivalent to
2072
2572
  * f = TypedRangeFilter.new(:date, :>= => "-132.2", :<= => -1.4)
2073
2573
  */
2074
- static VALUE
2075
- frb_trf_init(VALUE self, VALUE rfield, VALUE roptions)
2076
- {
2574
+ static VALUE frb_trf_init(VALUE self, VALUE rfield, VALUE roptions) {
2575
+ int ex_code = 0;
2576
+ const char *msg = NULL;
2577
+ frb_rq_args a = { .self = self, .rfield = rfield, .roptions = roptions };
2578
+ rb_rescue(frb_rq_init_2, (VALUE)&a, frb_q_init_r, (VALUE)&a);
2077
2579
  FrtFilter *f;
2078
- char *lterm = NULL;
2079
- char *uterm = NULL;
2080
- bool include_lower = false;
2081
- bool include_upper = false;
2082
-
2083
- get_range_params(roptions, &lterm, &uterm, &include_lower, &include_upper);
2084
- f = frt_trfilt_new(frb_field(rfield), lterm, uterm,
2085
- include_lower, include_upper);
2086
- Frt_Wrap_Struct(self, NULL, &frb_f_free, f);
2087
- object_add(f, self);
2580
+ TypedData_Get_Struct(self, FrtFilter, &frb_typed_range_filter_t, f);
2581
+ FRT_TRY
2582
+ frt_trfilt_init(f, a.field, a.lterm, a.uterm, a.include_lower, a.include_upper);
2583
+ f->rfilter = self;
2584
+ FRT_XCATCHALL
2585
+ ((struct RData *)(self))->data = NULL;
2586
+ ((struct RData *)(self))->dmark = NULL;
2587
+ ((struct RData *)(self))->dfree = NULL;
2588
+ free(f);
2589
+ ex_code = xcontext.excode;
2590
+ msg = xcontext.msg;
2591
+ FRT_HANDLED();
2592
+ FRT_XENDTRY
2593
+
2594
+ if (ex_code && msg) { frb_raise(ex_code, msg); }
2595
+
2088
2596
  return self;
2089
2597
  }
2090
2598
 
@@ -2094,21 +2602,42 @@ frb_trf_init(VALUE self, VALUE rfield, VALUE roptions)
2094
2602
  *
2095
2603
  ****************************************************************************/
2096
2604
 
2605
+ static size_t frb_query_filter_size(const void *p) {
2606
+ return sizeof(FrtQueryFilter);
2607
+ (void)p;
2608
+ }
2609
+
2610
+ const rb_data_type_t frb_query_filter_t = {
2611
+ .wrap_struct_name = "FrbQueryFilter",
2612
+ .function = {
2613
+ .dmark = NULL,
2614
+ .dfree = frb_f_free,
2615
+ .dsize = frb_query_filter_size,
2616
+ .dcompact = NULL,
2617
+ .reserved = {0},
2618
+ },
2619
+ .parent = NULL,
2620
+ .data = NULL,
2621
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
2622
+ };
2623
+
2624
+ static VALUE frb_qf_alloc(VALUE rclass) {
2625
+ FrtFilter *qf = frt_qfilt_alloc();
2626
+ return TypedData_Wrap_Struct(rclass, &frb_query_filter_t, qf);
2627
+ }
2628
+
2097
2629
  /*
2098
2630
  * call-seq:
2099
2631
  * QueryFilter.new(query) -> filter
2100
2632
  *
2101
2633
  * Create a new QueryFilter which applies the query +query+.
2102
2634
  */
2103
- static VALUE
2104
- frb_qf_init(VALUE self, VALUE rquery)
2105
- {
2106
- FrtQuery *q;
2635
+ static VALUE frb_qf_init(VALUE self, VALUE rquery) {
2636
+ FrtQuery *q = DATA_PTR(rquery);
2107
2637
  FrtFilter *f;
2108
- Data_Get_Struct(rquery, FrtQuery, q);
2109
- f = frt_qfilt_new(q);
2110
- Frt_Wrap_Struct(self, NULL, &frb_f_free, f);
2111
- object_add(f, self);
2638
+ TypedData_Get_Struct(self, FrtFilter, &frb_query_filter_t, f);
2639
+ frt_qfilt_init(f, q);
2640
+ f->rfilter = self;
2112
2641
  return self;
2113
2642
  }
2114
2643
 
@@ -2118,27 +2647,42 @@ frb_qf_init(VALUE self, VALUE rquery)
2118
2647
  *
2119
2648
  ****************************************************************************/
2120
2649
 
2121
- static void
2122
- frb_sf_free(void *p)
2123
- {
2124
- object_del(p);
2650
+ static size_t frb_sort_field_size(const void *p) {
2651
+ return sizeof(FrtSortField);
2652
+ (void)p;
2653
+ }
2654
+
2655
+ static void frb_sf_free(void *p) {
2125
2656
  frt_sort_field_destroy((FrtSortField *)p);
2126
2657
  }
2127
2658
 
2128
- static VALUE
2129
- frb_get_sf(FrtSortField *sf)
2130
- {
2131
- VALUE self = object_get(sf);
2132
- if (self == Qnil) {
2133
- self = Data_Wrap_Struct(cSortField, NULL, &frb_sf_free, sf);
2134
- object_add(sf, self);
2659
+ const rb_data_type_t frb_sort_field_t = {
2660
+ .wrap_struct_name = "FrbSortField",
2661
+ .function = {
2662
+ .dmark = NULL,
2663
+ .dfree = frb_sf_free,
2664
+ .dsize = frb_sort_field_size,
2665
+ .dcompact = NULL,
2666
+ .reserved = {0},
2667
+ },
2668
+ .parent = NULL,
2669
+ .data = NULL,
2670
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
2671
+ };
2672
+
2673
+ static VALUE frb_sf_alloc(VALUE rclass) {
2674
+ FrtSortField *sf = frt_sort_field_alloc();
2675
+ return TypedData_Wrap_Struct(rclass, &frb_sort_field_t, sf);
2676
+ }
2677
+
2678
+ static VALUE frb_get_sf(FrtSortField *sf) {
2679
+ if (sf->rfield == 0 || sf->rfield == Qnil) {
2680
+ sf->rfield = TypedData_Wrap_Struct(cSortField, &frb_sort_field_t, sf);
2135
2681
  }
2136
- return self;
2682
+ return sf->rfield;
2137
2683
  }
2138
2684
 
2139
- static int
2140
- get_sort_type(VALUE rtype)
2141
- {
2685
+ static int get_sort_type(VALUE rtype) {
2142
2686
  Check_Type(rtype, T_SYMBOL);
2143
2687
  if (rtype == sym_byte) {
2144
2688
  return FRT_SORT_TYPE_BYTE;
@@ -2182,16 +2726,14 @@ get_sort_type(VALUE rtype)
2182
2726
  * :reverse Default: false. Set to true if you want to reverse the
2183
2727
  * sort.
2184
2728
  */
2185
- static VALUE
2186
- frb_sf_init(int argc, VALUE *argv, VALUE self)
2187
- {
2729
+ static VALUE frb_sf_init(int argc, VALUE *argv, VALUE self) {
2188
2730
  FrtSortField *sf;
2189
2731
  VALUE rfield, roptions;
2190
2732
  VALUE rval;
2191
2733
  int type = FRT_SORT_TYPE_AUTO;
2192
2734
  int is_reverse = false;
2193
- FrtSymbol field;
2194
-
2735
+ ID field;
2736
+ TypedData_Get_Struct(self, FrtSortField, &frb_sort_field_t, sf);
2195
2737
  if (rb_scan_args(argc, argv, "11", &rfield, &roptions) == 2) {
2196
2738
  if (Qnil != (rval = rb_hash_aref(roptions, sym_type))) {
2197
2739
  type = get_sort_type(rval);
@@ -2206,13 +2748,11 @@ frb_sf_init(int argc, VALUE *argv, VALUE self)
2206
2748
  if (NIL_P(rfield)) rb_raise(rb_eArgError, "must pass a valid field name");
2207
2749
  field = frb_field(rfield);
2208
2750
 
2209
- sf = frt_sort_field_new(field, type, is_reverse);
2210
- if (sf->field == (FrtSymbol)NULL) {
2751
+ frt_sort_field_init(sf, field, type, is_reverse);
2752
+ if (sf->field == (ID)NULL) {
2211
2753
  sf->field = field;
2212
2754
  }
2213
-
2214
- Frt_Wrap_Struct(self, NULL, &frb_sf_free, sf);
2215
- object_add(sf, self);
2755
+ sf->rfield = self;
2216
2756
  return self;
2217
2757
  }
2218
2758
 
@@ -2225,9 +2765,7 @@ frb_sf_init(int argc, VALUE *argv, VALUE self)
2225
2765
  * Return true if the field is to be reverse sorted. This attribute is set
2226
2766
  * when you create the sort_field.
2227
2767
  */
2228
- static VALUE
2229
- frb_sf_is_reverse(VALUE self)
2230
- {
2768
+ static VALUE frb_sf_is_reverse(VALUE self) {
2231
2769
  GET_SF();
2232
2770
  return sf->reverse ? Qtrue : Qfalse;
2233
2771
  }
@@ -2238,9 +2776,7 @@ frb_sf_is_reverse(VALUE self)
2238
2776
  *
2239
2777
  * Returns the name of the field to be sorted.
2240
2778
  */
2241
- static VALUE
2242
- frb_sf_get_name(VALUE self)
2243
- {
2779
+ static VALUE frb_sf_get_name(VALUE self) {
2244
2780
  GET_SF();
2245
2781
  return sf->field ? ID2SYM(sf->field) : Qnil;
2246
2782
  }
@@ -2252,9 +2788,7 @@ frb_sf_get_name(VALUE self)
2252
2788
  * Return the type of sort. Should be one of; +:auto+, +:integer+, +:float+,
2253
2789
  * +:string+, +:byte+, +:doc_id+ or +:score+.
2254
2790
  */
2255
- static VALUE
2256
- frb_sf_get_type(VALUE self)
2257
- {
2791
+ static VALUE frb_sf_get_type(VALUE self) {
2258
2792
  GET_SF();
2259
2793
  switch (sf->type) {
2260
2794
  case FRT_SORT_TYPE_BYTE: return sym_byte;
@@ -2274,9 +2808,7 @@ frb_sf_get_type(VALUE self)
2274
2808
  *
2275
2809
  * TODO: currently unsupported
2276
2810
  */
2277
- static VALUE
2278
- frb_sf_get_comparator(VALUE self)
2279
- {
2811
+ static VALUE frb_sf_get_comparator(VALUE self) {
2280
2812
  return Qnil;
2281
2813
  }
2282
2814
 
@@ -2286,9 +2818,7 @@ frb_sf_get_comparator(VALUE self)
2286
2818
  *
2287
2819
  * Return a human readable string describing this +sort_field+.
2288
2820
  */
2289
- static VALUE
2290
- frb_sf_to_s(VALUE self)
2291
- {
2821
+ static VALUE frb_sf_to_s(VALUE self) {
2292
2822
  GET_SF();
2293
2823
  char *str = frt_sort_field_to_s(sf);
2294
2824
  VALUE rstr = rb_str_new2(str);
@@ -2302,38 +2832,47 @@ frb_sf_to_s(VALUE self)
2302
2832
  *
2303
2833
  ****************************************************************************/
2304
2834
 
2305
- static void
2306
- frb_sort_free(void *p)
2307
- {
2308
- FrtSort *sort = (FrtSort *)p;
2309
- object_del(sort);
2310
- frt_sort_destroy(sort);
2835
+ static size_t frb_sort_size(const void *p) {
2836
+ return sizeof(FrtSort);
2837
+ (void)p;
2311
2838
  }
2312
2839
 
2313
- static void
2314
- frb_sort_mark(void *p)
2315
- {
2840
+ static void frb_sort_free(void *p) {
2841
+ frt_sort_destroy((FrtSort *)p);
2842
+ }
2843
+
2844
+ static void frb_sort_mark(void *p) {
2316
2845
  FrtSort *sort = (FrtSort *)p;
2317
2846
  int i;
2318
2847
  for (i = 0; i < sort->size; i++) {
2319
- frb_gc_mark(sort->sort_fields[i]);
2848
+ if (sort->sort_fields[i]->rfield)
2849
+ rb_gc_mark(sort->sort_fields[i]->rfield);
2320
2850
  }
2321
2851
  }
2322
2852
 
2323
- static VALUE
2324
- frb_sort_alloc(VALUE klass)
2325
- {
2853
+ const rb_data_type_t frb_sort_t = {
2854
+ .wrap_struct_name = "FrbSort",
2855
+ .function = {
2856
+ .dmark = frb_sort_mark,
2857
+ .dfree = frb_sort_free,
2858
+ .dsize = frb_sort_size,
2859
+ .dcompact = NULL,
2860
+ .reserved = {0},
2861
+ },
2862
+ .parent = NULL,
2863
+ .data = NULL,
2864
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
2865
+ };
2866
+
2867
+ static VALUE frb_sort_alloc(VALUE klass) {
2326
2868
  VALUE self;
2327
2869
  FrtSort *sort = frt_sort_new();
2328
2870
  sort->destroy_all = false;
2329
- self = Data_Wrap_Struct(klass, &frb_sort_mark, &frb_sort_free, sort);
2330
- object_add(sort, self);
2871
+ self = TypedData_Wrap_Struct(klass, &frb_sort_t, sort);
2331
2872
  return self;
2332
2873
  }
2333
2874
 
2334
- static void
2335
- frb_parse_sort_str(FrtSort *sort, char *xsort_str)
2336
- {
2875
+ static void frb_parse_sort_str(FrtSort *sort, char *xsort_str) {
2337
2876
  FrtSortField *sf;
2338
2877
  char *comma, *end, *e, *s;
2339
2878
  const int len = strlen(xsort_str);
@@ -2373,13 +2912,11 @@ frb_parse_sort_str(FrtSort *sort, char *xsort_str)
2373
2912
  free(sort_str);
2374
2913
  }
2375
2914
 
2376
- static void
2377
- frb_sort_add(FrtSort *sort, VALUE rsf, bool reverse)
2378
- {
2915
+ static void frb_sort_add(FrtSort *sort, VALUE rsf, bool reverse) {
2379
2916
  FrtSortField *sf;
2380
2917
  switch (TYPE(rsf)) {
2381
2918
  case T_DATA:
2382
- Data_Get_Struct(rsf, FrtSortField, sf);
2919
+ TypedData_Get_Struct(rsf, FrtSortField, &frb_sort_field_t, sf);
2383
2920
  if (reverse) sf->reverse = !sf->reverse;
2384
2921
  frt_sort_add_sort_field(sort, sf);
2385
2922
  break;
@@ -2408,9 +2945,7 @@ frb_sort_add(FrtSort *sort, VALUE rsf, bool reverse)
2408
2945
  * reversed so if any of them are already reversed the will be turned back
2409
2946
  * to their natural order again. By default
2410
2947
  */
2411
- static VALUE
2412
- frb_sort_init(int argc, VALUE *argv, VALUE self)
2413
- {
2948
+ static VALUE frb_sort_init(int argc, VALUE *argv, VALUE self) {
2414
2949
  int i;
2415
2950
  VALUE rfields, rreverse;
2416
2951
  bool reverse = false;
@@ -2428,15 +2963,15 @@ frb_sort_init(int argc, VALUE *argv, VALUE self)
2428
2963
  frb_sort_add(sort, rfields, reverse);
2429
2964
  }
2430
2965
  for (i = 0; i < sort->size; i++) {
2431
- if (sort->sort_fields[i] == &FRT_SORT_FIELD_DOC) has_sfd = true;
2966
+ if (sort->sort_fields[i] == FRT_SORT_FIELD_DOC) has_sfd = true;
2432
2967
  }
2433
2968
  if (!has_sfd) {
2434
- frt_sort_add_sort_field(sort, (FrtSortField *)&FRT_SORT_FIELD_DOC);
2969
+ frt_sort_add_sort_field(sort, FRT_SORT_FIELD_DOC);
2435
2970
  }
2436
2971
  break;
2437
2972
  case 0:
2438
- frt_sort_add_sort_field(sort, (FrtSortField *)&FRT_SORT_FIELD_SCORE);
2439
- frt_sort_add_sort_field(sort, (FrtSortField *)&FRT_SORT_FIELD_DOC);
2973
+ frt_sort_add_sort_field(sort, FRT_SORT_FIELD_SCORE);
2974
+ frt_sort_add_sort_field(sort, FRT_SORT_FIELD_DOC);
2440
2975
  }
2441
2976
 
2442
2977
  return self;
@@ -2448,28 +2983,23 @@ frb_sort_init(int argc, VALUE *argv, VALUE self)
2448
2983
  *
2449
2984
  * Returns an array of the SortFields held by the Sort object.
2450
2985
  */
2451
- static VALUE
2452
- frb_sort_get_fields(VALUE self)
2453
- {
2986
+ static VALUE frb_sort_get_fields(VALUE self) {
2454
2987
  GET_SORT();
2455
2988
  VALUE rfields = rb_ary_new2(sort->size);
2456
2989
  int i;
2457
2990
  for (i = 0; i < sort->size; i++) {
2458
- rb_ary_store(rfields, i, object_get(sort->sort_fields[i]));
2991
+ rb_ary_store(rfields, i, sort->sort_fields[i]->rfield);
2459
2992
  }
2460
2993
  return rfields;
2461
2994
  }
2462
2995
 
2463
-
2464
2996
  /*
2465
2997
  * call-seq:
2466
2998
  * sort.to_s -> string
2467
2999
  *
2468
3000
  * Returns a human readable string representing the sort object.
2469
3001
  */
2470
- static VALUE
2471
- frb_sort_to_s(VALUE self)
2472
- {
3002
+ static VALUE frb_sort_to_s(VALUE self) {
2473
3003
  GET_SORT();
2474
3004
  char *str = frt_sort_to_s(sort);
2475
3005
  VALUE rstr = rb_str_new2(str);
@@ -2483,11 +3013,8 @@ frb_sort_to_s(VALUE self)
2483
3013
  *
2484
3014
  ****************************************************************************/
2485
3015
 
2486
- static void
2487
- frb_sea_free(void *p)
2488
- {
3016
+ static void frb_sea_free(void *p) {
2489
3017
  FrtSearcher *sea = (FrtSearcher *)p;
2490
- object_del(sea);
2491
3018
  sea->close(sea);
2492
3019
  }
2493
3020
 
@@ -2500,12 +3027,11 @@ frb_sea_free(void *p)
2500
3027
  * Close the searcher. The garbage collector will do this for you or you can
2501
3028
  * call this method explicitly.
2502
3029
  */
2503
- static VALUE
2504
- frb_sea_close(VALUE self)
2505
- {
3030
+ static VALUE frb_sea_close(VALUE self) {
2506
3031
  GET_SEA();
2507
- Frt_Unwrap_Struct(self);
2508
- object_del(sea);
3032
+ ((struct RData *)(self))->data = NULL;
3033
+ ((struct RData *)(self))->dmark = NULL;
3034
+ ((struct RData *)(self))->dfree = NULL;
2509
3035
  sea->close(sea);
2510
3036
  return Qnil;
2511
3037
  }
@@ -2516,11 +3042,9 @@ frb_sea_close(VALUE self)
2516
3042
  *
2517
3043
  * Return the IndexReader wrapped by this searcher.
2518
3044
  */
2519
- static VALUE
2520
- frb_sea_get_reader(VALUE self)
2521
- {
3045
+ static VALUE frb_sea_get_reader(VALUE self) {
2522
3046
  GET_SEA();
2523
- return object_get(((FrtIndexSearcher *)sea)->ir);
3047
+ return ((FrtIndexSearcher *)sea)->ir->rir;
2524
3048
  }
2525
3049
 
2526
3050
  /*
@@ -2530,13 +3054,9 @@ frb_sea_get_reader(VALUE self)
2530
3054
  * Return the number of documents in which the term +term+ appears in the
2531
3055
  * field +field+.
2532
3056
  */
2533
- static VALUE
2534
- frb_sea_doc_freq(VALUE self, VALUE rfield, VALUE rterm)
2535
- {
3057
+ static VALUE frb_sea_doc_freq(VALUE self, VALUE rfield, VALUE rterm) {
2536
3058
  GET_SEA();
2537
- return INT2FIX(sea->doc_freq(sea,
2538
- frb_field(rfield),
2539
- StringValuePtr(rterm)));
3059
+ return INT2FIX(sea->doc_freq(sea, frb_field(rfield), StringValuePtr(rterm)));
2540
3060
  }
2541
3061
 
2542
3062
  /*
@@ -2548,9 +3068,7 @@ frb_sea_doc_freq(VALUE self, VALUE rfield, VALUE rterm)
2548
3068
  * document returned. Documents are referenced internally by document ids
2549
3069
  * which are returned by the Searchers search methods.
2550
3070
  */
2551
- static VALUE
2552
- frb_sea_doc(VALUE self, VALUE rdoc_id)
2553
- {
3071
+ static VALUE frb_sea_doc(VALUE self, VALUE rdoc_id) {
2554
3072
  GET_SEA();
2555
3073
  return frb_get_lazy_doc(sea->get_lazy_doc(sea, FIX2INT(rdoc_id)));
2556
3074
  }
@@ -2564,20 +3082,13 @@ frb_sea_doc(VALUE self, VALUE rdoc_id)
2564
3082
  * there are no deletions, this number also refers to the number of documents
2565
3083
  * in the index.
2566
3084
  */
2567
- static VALUE
2568
- frb_sea_max_doc(VALUE self)
2569
- {
3085
+ static VALUE frb_sea_max_doc(VALUE self) {
2570
3086
  GET_SEA();
2571
3087
  return INT2FIX(sea->max_doc(sea));
2572
3088
  }
2573
3089
 
2574
- static float
2575
- call_filter_proc(int doc_id, float score, FrtSearcher *self, void *arg)
2576
- {
2577
- VALUE val = rb_funcall((VALUE)arg, id_call, 3,
2578
- INT2FIX(doc_id),
2579
- rb_float_new((double)score),
2580
- object_get(self));
3090
+ static float call_filter_proc(int doc_id, float score, FrtSearcher *sea, void *arg) {
3091
+ VALUE val = rb_funcall((VALUE)arg, id_call, 3, INT2FIX(doc_id), rb_float_new((double)score), sea->rsea);
2581
3092
  switch (TYPE(val)) {
2582
3093
  case T_NIL:
2583
3094
  case T_FALSE:
@@ -2592,44 +3103,35 @@ call_filter_proc(int doc_id, float score, FrtSearcher *self, void *arg)
2592
3103
  }
2593
3104
  }
2594
3105
 
2595
- typedef struct CWrappedFilter
2596
- {
3106
+ typedef struct CWrappedFilter {
2597
3107
  FrtFilter super;
2598
3108
  VALUE rfilter;
2599
3109
  } CWrappedFilter;
3110
+
2600
3111
  #define CWF(filt) ((CWrappedFilter *)(filt))
2601
3112
 
2602
- static unsigned long long
2603
- cwfilt_hash(FrtFilter *filt)
2604
- {
3113
+ static unsigned long long cwfilt_hash(FrtFilter *filt) {
2605
3114
  return (unsigned long long)NUM2ULONG(rb_funcall(CWF(filt)->rfilter, id_hash, 0));
2606
3115
  }
2607
3116
 
2608
- static int
2609
- cwfilt_eq(FrtFilter *filt, FrtFilter *o)
2610
- {
3117
+ static int cwfilt_eq(FrtFilter *filt, FrtFilter *o) {
2611
3118
  return RTEST(rb_funcall(CWF(filt)->rfilter, id_eql, 1, CWF(o)->rfilter));
2612
3119
  }
2613
3120
 
2614
- static FrtBitVector *
2615
- cwfilt_get_bv_i(FrtFilter *filt, FrtIndexReader *ir)
2616
- {
2617
- VALUE rbv = rb_funcall(CWF(filt)->rfilter, id_bits, 1, object_get(ir));
3121
+ static FrtBitVector *cwfilt_get_bv_i(FrtFilter *filt, FrtIndexReader *ir) {
3122
+ VALUE rbv = rb_funcall(CWF(filt)->rfilter, id_bits, 1, ir->rir);
2618
3123
  FrtBitVector *bv;
2619
- Data_Get_Struct(rbv, FrtBitVector, bv);
3124
+ bv = DATA_PTR(rbv);
2620
3125
  FRT_REF(bv);
2621
3126
  return bv;
2622
3127
  }
2623
3128
 
2624
- FrtFilter *
2625
- frb_get_cwrapped_filter(VALUE rval)
2626
- {
3129
+ FrtFilter *frb_get_cwrapped_filter(VALUE rval) {
2627
3130
  FrtFilter *filter;
2628
3131
  if (frb_is_cclass(rval) && DATA_PTR(rval)) {
2629
- Data_Get_Struct(rval, FrtFilter, filter);
3132
+ filter = DATA_PTR(rval);
2630
3133
  FRT_REF(filter);
2631
- }
2632
- else {
3134
+ } else {
2633
3135
  filter = filt_new(CWrappedFilter);
2634
3136
  filter->hash = &cwfilt_hash;
2635
3137
  filter->eq = &cwfilt_eq;
@@ -2639,9 +3141,7 @@ frb_get_cwrapped_filter(VALUE rval)
2639
3141
  return filter;
2640
3142
  }
2641
3143
 
2642
- static FrtTopDocs *
2643
- frb_sea_search_internal(FrtQuery *query, VALUE roptions, FrtSearcher *sea)
2644
- {
3144
+ static FrtTopDocs *frb_sea_search_internal(FrtQuery *query, VALUE roptions, FrtSearcher *sea) {
2645
3145
  VALUE rval;
2646
3146
  int offset = 0, limit = 10;
2647
3147
  FrtFilter *filter = NULL;
@@ -2666,11 +3166,9 @@ frb_sea_search_internal(FrtQuery *query, VALUE roptions, FrtSearcher *sea)
2666
3166
  if (limit <= 0) {
2667
3167
  rb_raise(rb_eArgError, ":limit must be > 0");
2668
3168
  }
2669
- }
2670
- else if (rval == sym_all) {
3169
+ } else if (rval == sym_all) {
2671
3170
  limit = INT_MAX;
2672
- }
2673
- else {
3171
+ } else {
2674
3172
  rb_raise(rb_eArgError, "%s is not a sensible :limit value "
2675
3173
  "Please use a positive integer or :all",
2676
3174
  rs2s(rb_obj_as_string(rval)));
@@ -2700,14 +3198,14 @@ frb_sea_search_internal(FrtQuery *query, VALUE roptions, FrtSearcher *sea)
2700
3198
  if (TYPE(rval) != T_DATA || CLASS_OF(rval) == cSortField) {
2701
3199
  rval = frb_sort_init(1, &rval, frb_sort_alloc(cSort));
2702
3200
  }
2703
- Data_Get_Struct(rval, FrtSort, sort);
3201
+ TypedData_Get_Struct(rval, FrtSort, &frb_sort_t, sort);
2704
3202
  }
2705
3203
  }
2706
3204
 
2707
3205
  FRT_TRY
2708
3206
  td = sea->search(sea, query, offset, limit, filter, sort, post_filter, 0);
2709
3207
  if (filter) frt_filt_deref(filter);
2710
- default:
3208
+ FRT_XCATCHALL
2711
3209
  ex_code = xcontext.excode;
2712
3210
  msg = xcontext.msg;
2713
3211
  FRT_HANDLED();
@@ -2756,14 +3254,11 @@ frb_sea_search_internal(FrtQuery *query, VALUE roptions, FrtSearcher *sea)
2756
3254
  * object. This can be used, for example, to weight the score
2757
3255
  * of a matched document by it's age.
2758
3256
  */
2759
- static VALUE
2760
- frb_sea_search(int argc, VALUE *argv, VALUE self)
2761
- {
3257
+ static VALUE frb_sea_search(int argc, VALUE *argv, VALUE self) {
2762
3258
  GET_SEA();
2763
3259
  VALUE rquery, roptions;
2764
- FrtQuery *query;
2765
3260
  rb_scan_args(argc, argv, "11", &rquery, &roptions);
2766
- Data_Get_Struct(rquery, FrtQuery, query);
3261
+ FrtQuery *query = DATA_PTR(rquery);
2767
3262
  FrtTopDocs *td = frb_sea_search_internal(query, roptions, sea);
2768
3263
  return frb_get_td(td, self);
2769
3264
  }
@@ -2809,27 +3304,23 @@ frb_sea_search(int argc, VALUE *argv, VALUE self)
2809
3304
  * Boolean value specifying whether the result should be
2810
3305
  * included in the result set.
2811
3306
  */
2812
- static VALUE
2813
- frb_sea_search_each(int argc, VALUE *argv, VALUE self)
2814
- {
3307
+ static VALUE frb_sea_search_each(int argc, VALUE *argv, VALUE self) {
2815
3308
  int i;
2816
- FrtQuery *q;
2817
3309
  float max_score;
2818
3310
  FrtTopDocs *td;
2819
3311
  VALUE rquery, roptions, rtotal_hits;
2820
3312
  GET_SEA();
2821
3313
 
2822
3314
  rb_scan_args(argc, argv, "11", &rquery, &roptions);
3315
+ FrtQuery *q = DATA_PTR(rquery);
2823
3316
 
2824
- Data_Get_Struct(rquery, FrtQuery, q);
2825
3317
  td = frb_sea_search_internal(q, roptions, sea);
2826
3318
 
2827
3319
  max_score = (td->max_score > 1.0f) ? td->max_score : 1.0f;
2828
3320
 
2829
3321
  /* yield normalized scores */
2830
3322
  for (i = 0; i < td->size; i++) {
2831
- rb_yield_values(2, INT2FIX(td->hits[i]->doc),
2832
- rb_float_new((double)(td->hits[i]->score/max_score)));
3323
+ rb_yield_values(2, INT2FIX(td->hits[i]->doc), rb_float_new((double)(td->hits[i]->score/max_score)));
2833
3324
  }
2834
3325
 
2835
3326
  rtotal_hits = INT2FIX(td->total_hits);
@@ -2877,10 +3368,7 @@ frb_sea_search_each(int argc, VALUE *argv, VALUE self)
2877
3368
  * # start_doc will be nil now if results is empty, ie no more matches
2878
3369
  * end while start_doc
2879
3370
  */
2880
- static VALUE
2881
- frb_sea_scan(int argc, VALUE *argv, VALUE self)
2882
- {
2883
- FrtQuery *q;
3371
+ static VALUE frb_sea_scan(int argc, VALUE *argv, VALUE self) {
2884
3372
  int i, count;
2885
3373
  VALUE rval, rquery, roptions;
2886
3374
  int *doc_array;
@@ -2888,7 +3376,7 @@ frb_sea_scan(int argc, VALUE *argv, VALUE self)
2888
3376
  int start_doc = 0, limit = 50;
2889
3377
  GET_SEA();
2890
3378
  rb_scan_args(argc, argv, "11", &rquery, &roptions);
2891
- Data_Get_Struct(rquery, FrtQuery, q);
3379
+ FrtQuery *q = DATA_PTR(rquery);
2892
3380
 
2893
3381
  if (Qnil != roptions) {
2894
3382
  Check_Type(roptions, T_HASH);
@@ -2938,15 +3426,41 @@ frb_sea_scan(int argc, VALUE *argv, VALUE self)
2938
3426
  *
2939
3427
  * puts searcher.explain(query, doc_id).to_s
2940
3428
  */
2941
- static VALUE
2942
- frb_sea_explain(VALUE self, VALUE rquery, VALUE rdoc_id)
2943
- {
3429
+
3430
+ static size_t frb_explanation_size(const void *p) {
3431
+ return sizeof(FrtExplanation);
3432
+ (void)p;
3433
+ }
3434
+
3435
+ static void frb_explanation_free(void *p) {
3436
+ frt_expl_destroy((FrtExplanation *)p);
3437
+ }
3438
+
3439
+ const rb_data_type_t frb_explanation_t = {
3440
+ .wrap_struct_name = "FrbExplanation",
3441
+ .function = {
3442
+ .dmark = NULL,
3443
+ .dfree = frb_explanation_free,
3444
+ .dsize = frb_explanation_size,
3445
+ .dcompact = NULL,
3446
+ .reserved = {0},
3447
+ },
3448
+ .parent = NULL,
3449
+ .data = NULL,
3450
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
3451
+ };
3452
+
3453
+ static VALUE frb_expl_alloc(VALUE rclass) {
3454
+ FrtExplanation *e = FRT_ALLOC(FrtExplanation);
3455
+ return TypedData_Wrap_Struct(rclass, &frb_explanation_t, e);
3456
+ }
3457
+
3458
+ static VALUE frb_sea_explain(VALUE self, VALUE rquery, VALUE rdoc_id) {
2944
3459
  GET_SEA();
2945
- FrtQuery *query;
3460
+ FrtQuery *query = DATA_PTR(rquery);
2946
3461
  FrtExplanation *expl;
2947
- Data_Get_Struct(rquery, FrtQuery, query);
2948
3462
  expl = sea->explain(sea, query, FIX2INT(rdoc_id));
2949
- return Data_Wrap_Struct(cExplanation, NULL, &frt_expl_destroy, expl);
3463
+ return TypedData_Wrap_Struct(cExplanation, &frb_explanation_t, expl);
2950
3464
  }
2951
3465
 
2952
3466
  /*
@@ -2971,12 +3485,9 @@ frb_sea_explain(VALUE self, VALUE rquery, VALUE rdoc_id)
2971
3485
  * hits the start or end of the field. You'll probably
2972
3486
  * want to change this so a Unicode ellipsis character.
2973
3487
  */
2974
- static VALUE
2975
- frb_sea_highlight(int argc, VALUE *argv, VALUE self)
2976
- {
3488
+ static VALUE frb_sea_highlight(int argc, VALUE *argv, VALUE self) {
2977
3489
  GET_SEA();
2978
3490
  VALUE rquery, rdoc_id, rfield, roptions, v;
2979
- FrtQuery *query;
2980
3491
  int excerpt_length = 150;
2981
3492
  int num_excerpts = 2;
2982
3493
  const char *pre_tag = "<b>";
@@ -2985,7 +3496,7 @@ frb_sea_highlight(int argc, VALUE *argv, VALUE self)
2985
3496
  char **excerpts;
2986
3497
 
2987
3498
  rb_scan_args(argc, argv, "31", &rquery, &rdoc_id, &rfield, &roptions);
2988
- Data_Get_Struct(rquery, FrtQuery, query);
3499
+ FrtQuery *query = DATA_PTR(rquery);
2989
3500
  if (argc > 3) {
2990
3501
  if (TYPE(roptions) != T_HASH) {
2991
3502
  rb_raise(rb_eArgError, "The fourth argument to Searcher#highlight must be a hash");
@@ -3036,23 +3547,40 @@ frb_sea_highlight(int argc, VALUE *argv, VALUE self)
3036
3547
  }
3037
3548
 
3038
3549
  /****************************************************************************
3039
- *
3040
3550
  * Searcher Methods
3041
- *
3042
3551
  ****************************************************************************/
3043
3552
 
3044
- static void
3045
- frb_sea_mark(void *p)
3046
- {
3047
- FrtIndexSearcher *isea = (FrtIndexSearcher *)p;
3048
- frb_gc_mark(isea->ir);
3049
- frb_gc_mark(isea->ir->store);
3553
+ static size_t frb_index_searcher_size(const void *p) {
3554
+ return sizeof(FrtIndexSearcher);
3555
+ (void)p;
3050
3556
  }
3051
3557
 
3052
- #define FRT_GET_IR(rir, ir) do {\
3053
- rir = Data_Wrap_Struct(cIndexReader, &frb_ir_mark, &frb_ir_free, ir);\
3054
- object_add(ir, rir);\
3055
- } while (0)
3558
+ static void frb_sea_mark(void *p) {
3559
+ FrtIndexSearcher *isea = (FrtIndexSearcher *)p;
3560
+ if (isea->ir->rir)
3561
+ rb_gc_mark(isea->ir->rir);
3562
+ if (isea->ir->store->rstore)
3563
+ rb_gc_mark(isea->ir->store->rstore);
3564
+ }
3565
+
3566
+ const rb_data_type_t frb_index_searcher_t = {
3567
+ .wrap_struct_name = "FrbIndexSearcher",
3568
+ .function = {
3569
+ .dmark = frb_sea_mark,
3570
+ .dfree = frb_sea_free,
3571
+ .dsize = frb_index_searcher_size,
3572
+ .dcompact = NULL,
3573
+ .reserved = {0},
3574
+ },
3575
+ .parent = NULL,
3576
+ .data = NULL,
3577
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
3578
+ };
3579
+
3580
+ static VALUE frb_sea_alloc(VALUE rclass) {
3581
+ FrtSearcher *s = frt_isea_alloc();
3582
+ return TypedData_Wrap_Struct(rclass, &frb_index_searcher_t, s);
3583
+ }
3056
3584
 
3057
3585
  /*
3058
3586
  * call-seq:
@@ -3064,34 +3592,33 @@ frb_sea_mark(void *p)
3064
3592
  * searching multiple indexes. Just open the IndexReader on multiple
3065
3593
  * directories.
3066
3594
  */
3067
- static VALUE
3068
- frb_sea_init(VALUE self, VALUE obj)
3069
- {
3595
+ static VALUE frb_sea_init(VALUE self, VALUE obj) {
3070
3596
  FrtStore *store = NULL;
3071
3597
  FrtIndexReader *ir = NULL;
3072
3598
  FrtSearcher *sea;
3073
3599
  if (TYPE(obj) == T_STRING) {
3074
3600
  frb_create_dir(obj);
3075
3601
  store = frt_open_fs_store(rs2s(obj));
3076
- ir = frt_ir_open(store);
3602
+ ir = frt_ir_open(NULL, store);
3077
3603
  FRT_DEREF(store);
3078
- FRT_GET_IR(obj, ir);
3604
+ ir->rir = TypedData_Wrap_Struct(cIndexReader, &frb_index_reader_t, ir);
3079
3605
  } else {
3080
- Check_Type(obj, T_DATA);
3606
+ // Check_Type(obj, T_DATA);
3081
3607
  if (rb_obj_is_kind_of(obj, cDirectory) == Qtrue) {
3082
- Data_Get_Struct(obj, FrtStore, store);
3083
- ir = frt_ir_open(store);
3084
- FRT_GET_IR(obj, ir);
3608
+ store = DATA_PTR(obj);
3609
+ ir = frt_ir_open(NULL, store);
3610
+ ir->rir = TypedData_Wrap_Struct(cIndexReader, &frb_index_reader_t, ir);
3085
3611
  } else if (rb_obj_is_kind_of(obj, cIndexReader) == Qtrue) {
3086
- Data_Get_Struct(obj, FrtIndexReader, ir);
3612
+ TypedData_Get_Struct(obj, FrtIndexReader, &frb_index_reader_t, ir);
3613
+ ir->rir = obj;
3087
3614
  } else {
3088
3615
  rb_raise(rb_eArgError, "Unknown type for argument to IndexSearcher.new");
3089
3616
  }
3090
3617
  }
3091
- sea = frt_isea_new(ir);
3618
+ TypedData_Get_Struct(self, FrtSearcher, &frb_index_searcher_t, sea);
3619
+ frt_isea_init(sea, ir);
3092
3620
  ((FrtIndexSearcher *)sea)->close_ir = false;
3093
- Frt_Wrap_Struct(self, &frb_sea_mark, &frb_sea_free, sea);
3094
- object_add(sea, self);
3621
+ sea->rsea = self;
3095
3622
  return self;
3096
3623
  }
3097
3624
 
@@ -3101,26 +3628,46 @@ frb_sea_init(VALUE self, VALUE obj)
3101
3628
  *
3102
3629
  ****************************************************************************/
3103
3630
 
3104
- static void
3105
- frb_ms_free(void *p)
3106
- {
3631
+ static size_t frb_multi_searcher_size(const void *p) {
3632
+ return sizeof(FrtMultiSearcher);
3633
+ (void)p;
3634
+ }
3635
+
3636
+ static void frb_ms_free(void *p) {
3107
3637
  FrtSearcher *sea = (FrtSearcher *)p;
3108
3638
  FrtMultiSearcher *msea = (FrtMultiSearcher *)sea;
3109
3639
  free(msea->searchers);
3110
- object_del(sea);
3111
3640
  frt_searcher_close(sea);
3112
3641
  }
3113
3642
 
3114
- static void
3115
- frb_ms_mark(void *p)
3116
- {
3643
+ static void frb_ms_mark(void *p) {
3117
3644
  int i;
3118
3645
  FrtMultiSearcher *msea = (FrtMultiSearcher *)p;
3119
3646
  for (i = 0; i < msea->s_cnt; i++) {
3120
- frb_gc_mark(msea->searchers[i]);
3647
+ if (msea->searchers[i]->rsea)
3648
+ rb_gc_mark(msea->searchers[i]->rsea);
3121
3649
  }
3122
3650
  }
3123
3651
 
3652
+ const rb_data_type_t frb_multi_searcher_t = {
3653
+ .wrap_struct_name = "FrbMultiSearcher",
3654
+ .function = {
3655
+ .dmark = frb_ms_mark,
3656
+ .dfree = frb_ms_free,
3657
+ .dsize = frb_multi_searcher_size,
3658
+ .dcompact = NULL,
3659
+ .reserved = {0},
3660
+ },
3661
+ .parent = NULL,
3662
+ .data = NULL,
3663
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
3664
+ };
3665
+
3666
+ static VALUE frb_ms_alloc(VALUE rclass) {
3667
+ FrtSearcher *s = frt_msea_alloc();
3668
+ return TypedData_Wrap_Struct(rclass, &frb_multi_searcher_t, s);
3669
+ }
3670
+
3124
3671
  /*
3125
3672
  * call-seq:
3126
3673
  * MultiSearcher.new(searcher*) -> searcher
@@ -3128,15 +3675,12 @@ frb_ms_mark(void *p)
3128
3675
  * Create a new MultiSearcher by passing a list of subsearchers to the
3129
3676
  * constructor.
3130
3677
  */
3131
- static VALUE
3132
- frb_ms_init(int argc, VALUE *argv, VALUE self)
3133
- {
3678
+ static VALUE frb_ms_init(int argc, VALUE *argv, VALUE self) {
3134
3679
  int i, j, top = 0, capa = argc;
3135
3680
 
3136
3681
  VALUE rsearcher;
3137
3682
  FrtSearcher **searchers = FRT_ALLOC_N(FrtSearcher *, capa);
3138
- FrtSearcher *s;
3139
-
3683
+ FrtSearcher *sea;
3140
3684
  for (i = 0; i < argc; i++) {
3141
3685
  rsearcher = argv[i];
3142
3686
  switch (TYPE(rsearcher)) {
@@ -3145,23 +3689,93 @@ frb_ms_init(int argc, VALUE *argv, VALUE self)
3145
3689
  FRT_REALLOC_N(searchers, FrtSearcher *, capa);
3146
3690
  for (j = 0; j < RARRAY_LEN(rsearcher); j++) {
3147
3691
  VALUE rs = RARRAY_PTR(rsearcher)[j];
3148
- Data_Get_Struct(rs, FrtSearcher, s);
3149
- searchers[top++] = s;
3692
+ sea = DATA_PTR(rs);
3693
+ searchers[top++] = sea;
3150
3694
  }
3151
3695
  break;
3152
3696
  case T_DATA:
3153
- Data_Get_Struct(rsearcher, FrtSearcher, s);
3154
- searchers[top++] = s;
3697
+ sea = DATA_PTR(rsearcher);
3698
+ searchers[top++] = sea;
3699
+ break;
3700
+ default:
3701
+ rb_raise(rb_eArgError, "Can't add class %s to MultiSearcher", rb_obj_classname(rsearcher));
3702
+ break;
3703
+ }
3704
+ }
3705
+ TypedData_Get_Struct(self, FrtSearcher, &frb_multi_searcher_t, sea);
3706
+ frt_msea_init(sea, searchers, top, false);
3707
+ sea->rsea = self;
3708
+ return self;
3709
+ }
3710
+
3711
+ VALUE frb_get_q(FrtQuery *q) {
3712
+ VALUE self = q->rquery;
3713
+
3714
+ if (self == 0 || self == Qnil) {
3715
+ switch (q->type) {
3716
+ case TERM_QUERY:
3717
+ self = TypedData_Wrap_Struct(cTermQuery, &frb_term_query_t, q);
3718
+ break;
3719
+ case MULTI_TERM_QUERY:
3720
+ self = TypedData_Wrap_Struct(cMultiTermQuery, &frb_multi_term_query_t, q);
3721
+ break;
3722
+ case BOOLEAN_QUERY:
3723
+ self = TypedData_Wrap_Struct(cBooleanQuery, &frb_boolean_query_t, q);
3724
+ break;
3725
+ case PHRASE_QUERY:
3726
+ self = TypedData_Wrap_Struct(cPhraseQuery, &frb_phrase_query_t, q);
3727
+ break;
3728
+ case CONSTANT_QUERY:
3729
+ self = TypedData_Wrap_Struct(cConstantScoreQuery, &frb_constant_score_query_t, q);
3730
+ break;
3731
+ case FILTERED_QUERY:
3732
+ self = TypedData_Wrap_Struct(cFilteredQuery, &frb_filtered_query_t, q);
3733
+ break;
3734
+ case MATCH_ALL_QUERY:
3735
+ self = TypedData_Wrap_Struct(cMatchAllQuery, &frb_match_all_query_t, q);
3736
+ break;
3737
+ case RANGE_QUERY:
3738
+ self = TypedData_Wrap_Struct(cRangeQuery, &frb_range_query_t, q);
3739
+ break;
3740
+ case TYPED_RANGE_QUERY:
3741
+ self = TypedData_Wrap_Struct(cTypedRangeQuery, &frb_typed_range_query_t, q);
3742
+ break;
3743
+ case WILD_CARD_QUERY:
3744
+ self = TypedData_Wrap_Struct(cWildcardQuery, &frb_wilcard_query_t, q);
3745
+ break;
3746
+ case FUZZY_QUERY:
3747
+ self = TypedData_Wrap_Struct(cFuzzyQuery, &frb_fuzzy_query_t, q);
3748
+ break;
3749
+ case PREFIX_QUERY:
3750
+ self = TypedData_Wrap_Struct(cPrefixQuery, &frb_prefix_query_t, q);
3751
+ break;
3752
+ case SPAN_TERM_QUERY:
3753
+ self = TypedData_Wrap_Struct(cSpanMultiTermQuery, &frb_span_multi_term_query_t, q);
3754
+ break;
3755
+ case SPAN_MULTI_TERM_QUERY:
3756
+ self = TypedData_Wrap_Struct(cSpanPrefixQuery, &frb_span_prefix_query_t, q);
3757
+ break;
3758
+ case SPAN_PREFIX_QUERY:
3759
+ self = TypedData_Wrap_Struct(cSpanTermQuery, &frb_span_term_query_t, q);
3760
+ break;
3761
+ case SPAN_FIRST_QUERY:
3762
+ self = TypedData_Wrap_Struct(cSpanFirstQuery, &frb_span_first_query_t, q);
3763
+ break;
3764
+ case SPAN_OR_QUERY:
3765
+ self = TypedData_Wrap_Struct(cSpanOrQuery, &frb_span_or_query_t, q);
3766
+ break;
3767
+ case SPAN_NOT_QUERY:
3768
+ self = TypedData_Wrap_Struct(cSpanNotQuery, &frb_span_not_query_t, q);
3769
+ break;
3770
+ case SPAN_NEAR_QUERY:
3771
+ self = TypedData_Wrap_Struct(cSpanNearQuery, &frb_span_near_query_t, q);
3155
3772
  break;
3156
3773
  default:
3157
- rb_raise(rb_eArgError, "Can't add class %s to MultiSearcher",
3158
- rb_obj_classname(rsearcher));
3774
+ rb_raise(rb_eArgError, "Unknown query type");
3159
3775
  break;
3160
3776
  }
3777
+ q->rquery = self;
3161
3778
  }
3162
- s = frt_msea_new(searchers, top, false);
3163
- Frt_Wrap_Struct(self, &frb_ms_mark, &frb_ms_free, s);
3164
- object_add(s, self);
3165
3779
  return self;
3166
3780
  }
3167
3781
 
@@ -3186,9 +3800,7 @@ cTopDocs = rb_define_class_under(mSearch, "TopDocs", rb_cObject);
3186
3800
  * is not normalized so it can be greater than 1.0. To normalize scores to
3187
3801
  * the range 0.0..1.0 divide the scores by TopDocs#max_score.
3188
3802
  */
3189
- static void
3190
- Init_Hit(void)
3191
- {
3803
+ static void Init_Hit(void) {
3192
3804
  const char *hit_class = "Hit";
3193
3805
  /* rdochack
3194
3806
  cHit = rb_define_class_under(mSearch, "Hit", rb_cObject);
@@ -3218,9 +3830,7 @@ Init_Hit(void)
3218
3830
  * puts "#{hit.doc} scored #{hit.score * 100.0 / top_docs.max_score}"
3219
3831
  * end
3220
3832
  */
3221
- static void
3222
- Init_TopDocs(void)
3223
- {
3833
+ static void Init_TopDocs(void) {
3224
3834
  const char *td_class = "TopDocs";
3225
3835
  /* rdochack
3226
3836
  cTopDocs = rb_define_class_under(mSearch, "TopDocs", rb_cObject);
@@ -3257,11 +3867,9 @@ Init_TopDocs(void)
3257
3867
  *
3258
3868
  * puts searcher.explain(query, doc_id).to_s
3259
3869
  */
3260
- static void
3261
- Init_Explanation(void)
3262
- {
3870
+ static void Init_Explanation(void) {
3263
3871
  cExplanation = rb_define_class_under(mSearch, "Explanation", rb_cObject);
3264
- rb_define_alloc_func(cExplanation, frb_data_alloc);
3872
+ rb_define_alloc_func(cExplanation, frb_expl_alloc);
3265
3873
 
3266
3874
  rb_define_method(cExplanation, "to_s", frb_expl_to_s, 0);
3267
3875
  rb_define_method(cExplanation, "to_html", frb_expl_to_html, 0);
@@ -3304,9 +3912,7 @@ Init_Explanation(void)
3304
3912
  * for train rails you might also add the tern Ruby but Rails is the more
3305
3913
  * important term so you'd give it a boost.
3306
3914
  */
3307
- static void
3308
- Init_Query(void)
3309
- {
3915
+ static void Init_Query(void) {
3310
3916
  cQuery = rb_define_class_under(mSearch, "Query", rb_cObject);
3311
3917
 
3312
3918
  rb_define_method(cQuery, "to_s", frb_q_to_s, -1);
@@ -3338,12 +3944,9 @@ Init_Query(void)
3338
3944
  * downcase all text added to the index. The title in this case was not
3339
3945
  * tokenized so the case would have been left as is.
3340
3946
  */
3341
- static void
3342
- Init_TermQuery(void)
3343
- {
3947
+ static void Init_TermQuery(void) {
3344
3948
  cTermQuery = rb_define_class_under(mSearch, "TermQuery", cQuery);
3345
- rb_define_alloc_func(cTermQuery, frb_data_alloc);
3346
-
3949
+ rb_define_alloc_func(cTermQuery, frb_tq_alloc);
3347
3950
  rb_define_method(cTermQuery, "initialize", frb_tq_init, 2);
3348
3951
  }
3349
3952
 
@@ -3368,20 +3971,16 @@ Init_TermQuery(void)
3368
3971
  *
3369
3972
  * multi_term_query << "Ruby" << "Ferret" << "Rails" << "Search"
3370
3973
  */
3371
- static void
3372
- Init_MultiTermQuery(void)
3373
- {
3974
+ static void Init_MultiTermQuery(void) {
3374
3975
  id_default_max_terms = rb_intern("@@default_max_terms");
3375
3976
  sym_max_terms = ID2SYM(rb_intern("max_terms"));
3376
3977
  sym_min_score = ID2SYM(rb_intern("min_score"));
3377
3978
 
3378
3979
  cMultiTermQuery = rb_define_class_under(mSearch, "MultiTermQuery", cQuery);
3379
- rb_define_alloc_func(cMultiTermQuery, frb_data_alloc);
3980
+ rb_define_alloc_func(cMultiTermQuery, frb_mtq_alloc);
3380
3981
  rb_cvar_set(cMultiTermQuery, id_default_max_terms, INT2FIX(512));
3381
- rb_define_singleton_method(cMultiTermQuery, "default_max_terms",
3382
- frb_mtq_get_dmt, 0);
3383
- rb_define_singleton_method(cMultiTermQuery, "default_max_terms=",
3384
- frb_mtq_set_dmt, 1);
3982
+ rb_define_singleton_method(cMultiTermQuery, "default_max_terms", frb_mtq_get_dmt, 0);
3983
+ rb_define_singleton_method(cMultiTermQuery, "default_max_terms=", frb_mtq_set_dmt, 1);
3385
3984
 
3386
3985
  rb_define_method(cMultiTermQuery, "initialize", frb_mtq_init, -1);
3387
3986
  rb_define_method(cMultiTermQuery, "add_term", frb_mtq_add_term, -1);
@@ -3415,11 +4014,9 @@ static void Init_BooleanClause(void);
3415
4014
  * query = BooleanQuery.new
3416
4015
  * query.add_query(tq1, :must).add_query(bq2, :must).add_query(rq3, :must)
3417
4016
  */
3418
- static void
3419
- Init_BooleanQuery(void)
3420
- {
4017
+ static void Init_BooleanQuery(void) {
3421
4018
  cBooleanQuery = rb_define_class_under(mSearch, "BooleanQuery", cQuery);
3422
- rb_define_alloc_func(cBooleanQuery, frb_data_alloc);
4019
+ rb_define_alloc_func(cBooleanQuery, frb_bq_alloc);
3423
4020
 
3424
4021
  rb_define_method(cBooleanQuery, "initialize", frb_bq_init, -1);
3425
4022
  rb_define_method(cBooleanQuery, "add_query", frb_bq_add_query, -1);
@@ -3447,16 +4044,13 @@ Init_BooleanQuery(void)
3447
4044
  * query = BooleanQuery.new
3448
4045
  * query << clause1 << clause2
3449
4046
  */
3450
- static void
3451
- Init_BooleanClause(void)
3452
- {
4047
+ static void Init_BooleanClause(void) {
3453
4048
  sym_should = ID2SYM(rb_intern("should"));
3454
4049
  sym_must = ID2SYM(rb_intern("must"));
3455
4050
  sym_must_not = ID2SYM(rb_intern("must_not"));
3456
4051
 
3457
- cBooleanClause = rb_define_class_under(cBooleanQuery, "BooleanClause",
3458
- rb_cObject);
3459
- rb_define_alloc_func(cBooleanClause, frb_data_alloc);
4052
+ cBooleanClause = rb_define_class_under(cBooleanQuery, "BooleanClause", rb_cObject);
4053
+ rb_define_alloc_func(cBooleanClause, frb_bc_alloc);
3460
4054
 
3461
4055
  rb_define_method(cBooleanClause, "initialize", frb_bc_init, -1);
3462
4056
  rb_define_method(cBooleanClause, "query", frb_bc_get_query, 0);
@@ -3503,9 +4097,7 @@ Init_BooleanClause(void)
3503
4097
  * [1010, 0001, 0910, 1100, 1534]
3504
4098
  *
3505
4099
  */
3506
- static void
3507
- Init_RangeQuery(void)
3508
- {
4100
+ static void Init_RangeQuery(void) {
3509
4101
  sym_upper = ID2SYM(rb_intern("upper"));
3510
4102
  sym_lower = ID2SYM(rb_intern("lower"));
3511
4103
  sym_upper_exclusive = ID2SYM(rb_intern("upper_exclusive"));
@@ -3519,7 +4111,7 @@ Init_RangeQuery(void)
3519
4111
  sym_greater_than_or_equal_to = ID2SYM(rb_intern(">="));
3520
4112
 
3521
4113
  cRangeQuery = rb_define_class_under(mSearch, "RangeQuery", cQuery);
3522
- rb_define_alloc_func(cRangeQuery, frb_data_alloc);
4114
+ rb_define_alloc_func(cRangeQuery, frb_rq_alloc);
3523
4115
 
3524
4116
  rb_define_method(cRangeQuery, "initialize", frb_rq_init, 2);
3525
4117
  }
@@ -3549,12 +4141,9 @@ Init_RangeQuery(void)
3549
4141
  * usually better to use a standard RangeQuery. This will require a little
3550
4142
  * work on your behalf. See RangeQuery for notes on how to do this.
3551
4143
  */
3552
- static void
3553
- Init_TypedRangeQuery(void)
3554
- {
3555
- cTypedRangeQuery =
3556
- rb_define_class_under(mSearch, "TypedRangeQuery", cQuery);
3557
- rb_define_alloc_func(cTypedRangeQuery, frb_data_alloc);
4144
+ static void Init_TypedRangeQuery(void) {
4145
+ cTypedRangeQuery = rb_define_class_under(mSearch, "TypedRangeQuery", cQuery);
4146
+ rb_define_alloc_func(cTypedRangeQuery, frb_trq_alloc);
3558
4147
 
3559
4148
  rb_define_method(cTypedRangeQuery, "initialize", frb_trq_init, 2);
3560
4149
  }
@@ -3622,11 +4211,9 @@ Init_TypedRangeQuery(void)
3622
4211
  * italic text for example. If you want more information about this, ask on
3623
4212
  * the mailing list.
3624
4213
  */
3625
- static void
3626
- Init_PhraseQuery(void)
3627
- {
4214
+ static void Init_PhraseQuery(void) {
3628
4215
  cPhraseQuery = rb_define_class_under(mSearch, "PhraseQuery", cQuery);
3629
- rb_define_alloc_func(cPhraseQuery, frb_data_alloc);
4216
+ rb_define_alloc_func(cPhraseQuery, frb_phq_alloc);
3630
4217
 
3631
4218
  rb_define_method(cPhraseQuery, "initialize", frb_phq_init, -1);
3632
4219
  rb_define_method(cPhraseQuery, "add_term", frb_phq_add, -1);
@@ -3664,11 +4251,9 @@ Init_PhraseQuery(void)
3664
4251
  * # matches => "cat2/sub_cat1"
3665
4252
  * # matches => "cat2/sub_cat2"
3666
4253
  */
3667
- static void
3668
- Init_PrefixQuery(void)
3669
- {
4254
+ static void Init_PrefixQuery(void) {
3670
4255
  cPrefixQuery = rb_define_class_under(mSearch, "PrefixQuery", cQuery);
3671
- rb_define_alloc_func(cPrefixQuery, frb_data_alloc);
4256
+ rb_define_alloc_func(cPrefixQuery, frb_prq_alloc);
3672
4257
 
3673
4258
  rb_define_method(cPrefixQuery, "initialize", frb_prq_init, -1);
3674
4259
  }
@@ -3699,11 +4284,9 @@ Init_PrefixQuery(void)
3699
4284
  * # matches => "falling"
3700
4285
  * # matches => "folly"
3701
4286
  */
3702
- static void
3703
- Init_WildcardQuery(void)
3704
- {
4287
+ static void Init_WildcardQuery(void) {
3705
4288
  cWildcardQuery = rb_define_class_under(mSearch, "WildcardQuery", cQuery);
3706
- rb_define_alloc_func(cWildcardQuery, frb_data_alloc);
4289
+ rb_define_alloc_func(cWildcardQuery, frb_wcq_alloc);
3707
4290
 
3708
4291
  rb_define_method(cWildcardQuery, "initialize", frb_wcq_init, -1);
3709
4292
  }
@@ -3729,9 +4312,7 @@ Init_WildcardQuery(void)
3729
4312
  * :prefix_length => 2)
3730
4313
  * # matches => "gogle", "goggle", "googol", "googel"
3731
4314
  */
3732
- static void
3733
- Init_FuzzyQuery(void)
3734
- {
4315
+ static void Init_FuzzyQuery(void) {
3735
4316
  id_default_min_similarity = rb_intern("@@default_min_similarity");
3736
4317
  id_default_prefix_length = rb_intern("@@default_prefix_length");
3737
4318
 
@@ -3739,20 +4320,14 @@ Init_FuzzyQuery(void)
3739
4320
  sym_prefix_length = ID2SYM(rb_intern("prefix_length"));
3740
4321
 
3741
4322
  cFuzzyQuery = rb_define_class_under(mSearch, "FuzzyQuery", cQuery);
3742
- rb_define_alloc_func(cFuzzyQuery, frb_data_alloc);
3743
- rb_cvar_set(cFuzzyQuery, id_default_min_similarity,
3744
- rb_float_new(0.5));
3745
- rb_cvar_set(cFuzzyQuery, id_default_prefix_length,
3746
- INT2FIX(0));
3747
-
3748
- rb_define_singleton_method(cFuzzyQuery, "default_min_similarity",
3749
- frb_fq_get_dms, 0);
3750
- rb_define_singleton_method(cFuzzyQuery, "default_min_similarity=",
3751
- frb_fq_set_dms, 1);
3752
- rb_define_singleton_method(cFuzzyQuery, "default_prefix_length",
3753
- frb_fq_get_dpl, 0);
3754
- rb_define_singleton_method(cFuzzyQuery, "default_prefix_length=",
3755
- frb_fq_set_dpl, 1);
4323
+ rb_define_alloc_func(cFuzzyQuery, frb_fq_alloc);
4324
+ rb_cvar_set(cFuzzyQuery, id_default_min_similarity, rb_float_new(0.5));
4325
+ rb_cvar_set(cFuzzyQuery, id_default_prefix_length, INT2FIX(0));
4326
+
4327
+ rb_define_singleton_method(cFuzzyQuery, "default_min_similarity", frb_fq_get_dms, 0);
4328
+ rb_define_singleton_method(cFuzzyQuery, "default_min_similarity=", frb_fq_set_dms, 1);
4329
+ rb_define_singleton_method(cFuzzyQuery, "default_prefix_length", frb_fq_get_dpl, 0);
4330
+ rb_define_singleton_method(cFuzzyQuery, "default_prefix_length=", frb_fq_set_dpl, 1);
3756
4331
 
3757
4332
  rb_define_method(cFuzzyQuery, "initialize", frb_fq_init, -1);
3758
4333
  rb_define_method(cFuzzyQuery, "prefix_length", frb_fq_pre_len, 0);
@@ -3768,9 +4343,7 @@ Init_FuzzyQuery(void)
3768
4343
  * query in combination with a filter, however, ConstantScoreQuery is
3769
4344
  * probably better in that circumstance.
3770
4345
  */
3771
- static void
3772
- Init_MatchAllQuery(void)
3773
- {
4346
+ static void Init_MatchAllQuery(void) {
3774
4347
  cMatchAllQuery = rb_define_class_under(mSearch, "MatchAllQuery", cQuery);
3775
4348
  rb_define_alloc_func(cMatchAllQuery, frb_maq_alloc);
3776
4349
 
@@ -3797,12 +4370,9 @@ Init_MatchAllQuery(void)
3797
4370
  * Once this is run once the results are cached and will be returned very
3798
4371
  * quickly in future requests.
3799
4372
  */
3800
- static void
3801
- Init_ConstantScoreQuery(void)
3802
- {
3803
- cConstantScoreQuery = rb_define_class_under(mSearch,
3804
- "ConstantScoreQuery", cQuery);
3805
- rb_define_alloc_func(cConstantScoreQuery, frb_data_alloc);
4373
+ static void Init_ConstantScoreQuery(void) {
4374
+ cConstantScoreQuery = rb_define_class_under(mSearch, "ConstantScoreQuery", cQuery);
4375
+ rb_define_alloc_func(cConstantScoreQuery, frb_csq_alloc);
3806
4376
 
3807
4377
  rb_define_method(cConstantScoreQuery, "initialize", frb_csq_init, 1);
3808
4378
  }
@@ -3818,11 +4388,9 @@ Init_ConstantScoreQuery(void)
3818
4388
  * directly to a Searcher#search method unless you are applying more than one
3819
4389
  * filter since the search method also takes a filter as a parameter.
3820
4390
  */
3821
- static void
3822
- Init_FilteredQuery(void)
3823
- {
4391
+ static void Init_FilteredQuery(void) {
3824
4392
  cFilteredQuery = rb_define_class_under(mSearch, "FilteredQuery", cQuery);
3825
- rb_define_alloc_func(cFilteredQuery, frb_data_alloc);
4393
+ rb_define_alloc_func(cFilteredQuery, frb_fqq_alloc);
3826
4394
 
3827
4395
  rb_define_method(cFilteredQuery, "initialize", frb_fqq_init, 2);
3828
4396
  }
@@ -3836,11 +4404,9 @@ Init_FilteredQuery(void)
3836
4404
  * being that it returns the start and end offset of all of its matches for
3837
4405
  * use by enclosing SpanQueries.
3838
4406
  */
3839
- static void
3840
- Init_SpanTermQuery(void)
3841
- {
4407
+ static void Init_SpanTermQuery(void) {
3842
4408
  cSpanTermQuery = rb_define_class_under(mSpans, "SpanTermQuery", cQuery);
3843
- rb_define_alloc_func(cSpanTermQuery, frb_data_alloc);
4409
+ rb_define_alloc_func(cSpanTermQuery, frb_spantq_alloc);
3844
4410
 
3845
4411
  rb_define_method(cSpanTermQuery, "initialize", frb_spantq_init, 2);
3846
4412
  }
@@ -3854,11 +4420,9 @@ Init_SpanTermQuery(void)
3854
4420
  * difference being that it returns the start and end offset of all of its
3855
4421
  * matches for use by enclosing SpanQueries.
3856
4422
  */
3857
- static void
3858
- Init_SpanMultiTermQuery(void)
3859
- {
4423
+ static void Init_SpanMultiTermQuery(void) {
3860
4424
  cSpanMultiTermQuery = rb_define_class_under(mSpans, "SpanMultiTermQuery", cQuery);
3861
- rb_define_alloc_func(cSpanMultiTermQuery, frb_data_alloc);
4425
+ rb_define_alloc_func(cSpanMultiTermQuery, frb_spanmtq_alloc);
3862
4426
 
3863
4427
  rb_define_method(cSpanMultiTermQuery, "initialize", frb_spanmtq_init, 2);
3864
4428
  }
@@ -3872,11 +4436,9 @@ Init_SpanMultiTermQuery(void)
3872
4436
  * being that it returns the start and end offset of all of its matches for
3873
4437
  * use by enclosing SpanQueries.
3874
4438
  */
3875
- static void
3876
- Init_SpanPrefixQuery(void)
3877
- {
4439
+ static void Init_SpanPrefixQuery(void) {
3878
4440
  cSpanPrefixQuery = rb_define_class_under(mSpans, "SpanPrefixQuery", cQuery);
3879
- rb_define_alloc_func(cSpanPrefixQuery, frb_data_alloc);
4441
+ rb_define_alloc_func(cSpanPrefixQuery, frb_spanprq_alloc);
3880
4442
 
3881
4443
  rb_define_method(cSpanPrefixQuery, "initialize", frb_spanprq_init, -1);
3882
4444
  }
@@ -3901,11 +4463,9 @@ Init_SpanPrefixQuery(void)
3901
4463
  *
3902
4464
  * SpanFirstQuery only works with other SpanQueries.
3903
4465
  */
3904
- static void
3905
- Init_SpanFirstQuery(void)
3906
- {
4466
+ static void Init_SpanFirstQuery(void) {
3907
4467
  cSpanFirstQuery = rb_define_class_under(mSpans, "SpanFirstQuery", cQuery);
3908
- rb_define_alloc_func(cSpanFirstQuery, frb_data_alloc);
4468
+ rb_define_alloc_func(cSpanFirstQuery, frb_spanfq_alloc);
3909
4469
 
3910
4470
  rb_define_method(cSpanFirstQuery, "initialize", frb_spanfq_init, 2);
3911
4471
  }
@@ -3948,15 +4508,13 @@ Init_SpanFirstQuery(void)
3948
4508
  *
3949
4509
  * SpanNearQuery only works with other SpanQueries.
3950
4510
  */
3951
- static void
3952
- Init_SpanNearQuery(void)
3953
- {
4511
+ static void Init_SpanNearQuery(void) {
3954
4512
  sym_slop = ID2SYM(rb_intern("slop"));
3955
4513
  sym_in_order = ID2SYM(rb_intern("in_order"));
3956
4514
  sym_clauses = ID2SYM(rb_intern("clauses"));
3957
4515
 
3958
4516
  cSpanNearQuery = rb_define_class_under(mSpans, "SpanNearQuery", cQuery);
3959
- rb_define_alloc_func(cSpanNearQuery, frb_data_alloc);
4517
+ rb_define_alloc_func(cSpanNearQuery, frb_spannq_alloc);
3960
4518
 
3961
4519
  rb_define_method(cSpanNearQuery, "initialize", frb_spannq_init, -1);
3962
4520
  rb_define_method(cSpanNearQuery, "add", frb_spannq_add, 1);
@@ -4002,11 +4560,9 @@ Init_SpanNearQuery(void)
4002
4560
  *
4003
4561
  * SpanOrQuery only works with other SpanQueries.
4004
4562
  */
4005
- static void
4006
- Init_SpanOrQuery(void)
4007
- {
4563
+ static void Init_SpanOrQuery(void) {
4008
4564
  cSpanOrQuery = rb_define_class_under(mSpans, "SpanOrQuery", cQuery);
4009
- rb_define_alloc_func(cSpanOrQuery, frb_data_alloc);
4565
+ rb_define_alloc_func(cSpanOrQuery, frb_spanoq_alloc);
4010
4566
 
4011
4567
  rb_define_method(cSpanOrQuery, "initialize", frb_spanoq_init, -1);
4012
4568
  rb_define_method(cSpanOrQuery, "add", frb_spanoq_add, 1);
@@ -4036,11 +4592,9 @@ Init_SpanOrQuery(void)
4036
4592
  *
4037
4593
  * SpanOrQuery only works with other SpanQueries.
4038
4594
  */
4039
- static void
4040
- Init_SpanNotQuery(void)
4041
- {
4595
+ static void Init_SpanNotQuery(void) {
4042
4596
  cSpanNotQuery = rb_define_class_under(mSpans, "SpanNotQuery", cQuery);
4043
- rb_define_alloc_func(cSpanNotQuery, frb_data_alloc);
4597
+ rb_define_alloc_func(cSpanNotQuery, frb_spanxq_alloc);
4044
4598
 
4045
4599
  rb_define_method(cSpanNotQuery, "initialize", frb_spanxq_init, 2);
4046
4600
  }
@@ -4061,9 +4615,7 @@ extern VALUE mSearch = rb_define_module_under(mFerret, "Search");
4061
4615
  * field. They are often used in combination to perform special types of
4062
4616
  * PhraseQuery.
4063
4617
  */
4064
- static void
4065
- Init_Spans(void)
4066
- {
4618
+ static void Init_Spans(void) {
4067
4619
  mSpans = rb_define_module_under(mSearch, "Spans");
4068
4620
  Init_SpanTermQuery();
4069
4621
  Init_SpanMultiTermQuery();
@@ -4093,12 +4645,10 @@ Init_Spans(void)
4093
4645
  * See RangeQuery for notes on how to use the RangeFilter on a field
4094
4646
  * containing numbers.
4095
4647
  */
4096
- static void
4097
- Init_RangeFilter(void)
4098
- {
4648
+ static void Init_RangeFilter(void) {
4099
4649
  cRangeFilter = rb_define_class_under(mSearch, "RangeFilter", cFilter);
4100
4650
  frb_mark_cclass(cRangeFilter);
4101
- rb_define_alloc_func(cRangeFilter, frb_data_alloc);
4651
+ rb_define_alloc_func(cRangeFilter, frb_rf_alloc);
4102
4652
 
4103
4653
  rb_define_method(cRangeFilter, "initialize", frb_rf_init, 2);
4104
4654
  }
@@ -4120,13 +4670,10 @@ Init_RangeFilter(void)
4120
4670
  *
4121
4671
  * filter = TypedRangeFilter.new(:created_on, :<= => "50.00")
4122
4672
  */
4123
- static void
4124
- Init_TypedRangeFilter(void)
4125
- {
4126
- cTypedRangeFilter =
4127
- rb_define_class_under(mSearch, "TypedRangeFilter", cFilter);
4673
+ static void Init_TypedRangeFilter(void) {
4674
+ cTypedRangeFilter = rb_define_class_under(mSearch, "TypedRangeFilter", cFilter);
4128
4675
  frb_mark_cclass(cTypedRangeFilter);
4129
- rb_define_alloc_func(cTypedRangeFilter, frb_data_alloc);
4676
+ rb_define_alloc_func(cTypedRangeFilter, frb_trf_alloc);
4130
4677
 
4131
4678
  rb_define_method(cTypedRangeFilter, "initialize", frb_trf_init, 2);
4132
4679
  }
@@ -4156,12 +4703,10 @@ Init_TypedRangeFilter(void)
4156
4703
  * caching. Don't create a new one for each request. Of course, this won't
4157
4704
  * work in a CGI application.
4158
4705
  */
4159
- static void
4160
- Init_QueryFilter(void)
4161
- {
4706
+ static void Init_QueryFilter(void) {
4162
4707
  cQueryFilter = rb_define_class_under(mSearch, "QueryFilter", cFilter);
4163
4708
  frb_mark_cclass(cQueryFilter);
4164
- rb_define_alloc_func(cQueryFilter, frb_data_alloc);
4709
+ rb_define_alloc_func(cQueryFilter, frb_qf_alloc);
4165
4710
 
4166
4711
  rb_define_method(cQueryFilter, "initialize", frb_qf_init, 1);
4167
4712
  }
@@ -4181,13 +4726,11 @@ Init_QueryFilter(void)
4181
4726
  * TODO add support for user implemented Filter.
4182
4727
  * TODO add example of user implemented Filter.
4183
4728
  */
4184
- static void
4185
- Init_Filter(void)
4186
- {
4729
+ static void Init_Filter(void) {
4187
4730
  id_bits = rb_intern("bits");
4188
4731
  cFilter = rb_define_class_under(mSearch, "Filter", rb_cObject);
4189
4732
  frb_mark_cclass(cFilter);
4190
- rb_define_alloc_func(cConstantScoreQuery, frb_data_alloc);
4733
+ rb_define_alloc_func(cConstantScoreQuery, frb_csq_alloc);
4191
4734
 
4192
4735
  rb_define_method(cFilter, "bits", frb_f_get_bits, 1);
4193
4736
  rb_define_method(cFilter, "to_s", frb_f_to_s, 0);
@@ -4230,12 +4773,11 @@ Init_Filter(void)
4230
4773
  * Note 2: When sorting by integer, integers are only 4 bytes so anything
4231
4774
  * larger will cause strange sorting behaviour.
4232
4775
  */
4233
- static void
4234
- Init_SortField(void)
4235
- {
4776
+
4777
+ static void Init_SortField(void) {
4236
4778
  /* option hash keys for SortField#initialize */
4237
- sym_type = ID2SYM(rb_intern("type"));
4238
- sym_reverse = ID2SYM(rb_intern("reverse"));
4779
+ sym_type = ID2SYM(rb_intern("type"));
4780
+ sym_reverse = ID2SYM(rb_intern("reverse"));
4239
4781
  sym_comparator = ID2SYM(rb_intern("comparator"));
4240
4782
 
4241
4783
  /* Sort types */
@@ -4248,7 +4790,7 @@ Init_SortField(void)
4248
4790
  sym_byte = ID2SYM(rb_intern("byte"));
4249
4791
 
4250
4792
  cSortField = rb_define_class_under(mSearch, "SortField", rb_cObject);
4251
- rb_define_alloc_func(cSortField, frb_data_alloc);
4793
+ rb_define_alloc_func(cSortField, frb_sf_alloc);
4252
4794
 
4253
4795
  rb_define_method(cSortField, "initialize", frb_sf_init, -1);
4254
4796
  rb_define_method(cSortField, "reverse?", frb_sf_is_reverse, 0);
@@ -4257,34 +4799,18 @@ Init_SortField(void)
4257
4799
  rb_define_method(cSortField, "comparator", frb_sf_get_comparator, 0);
4258
4800
  rb_define_method(cSortField, "to_s", frb_sf_to_s, 0);
4259
4801
 
4260
- rb_define_const(cSortField, "SCORE",
4261
- Data_Wrap_Struct(cSortField, NULL,
4262
- &frb_deref_free,
4263
- (FrtSortField *)&FRT_SORT_FIELD_SCORE));
4264
- object_add((FrtSortField *)&FRT_SORT_FIELD_SCORE,
4265
- rb_const_get(cSortField, rb_intern("SCORE")));
4266
-
4267
- rb_define_const(cSortField, "SCORE_REV",
4268
- Data_Wrap_Struct(cSortField, NULL,
4269
- &frb_deref_free,
4270
- (FrtSortField *)&FRT_SORT_FIELD_SCORE_REV));
4271
- object_add((FrtSortField *)&FRT_SORT_FIELD_SCORE_REV,
4272
- rb_const_get(cSortField, rb_intern("SCORE_REV")));
4273
-
4274
- rb_define_const(cSortField, "DOC_ID",
4275
- Data_Wrap_Struct(cSortField, NULL,
4276
- &frb_deref_free,
4277
- (FrtSortField *)&FRT_SORT_FIELD_DOC));
4802
+ rb_define_const(cSortField, "SCORE", TypedData_Wrap_Struct(cSortField, &frb_sort_field_t, FRT_SORT_FIELD_SCORE));
4803
+ FRT_SORT_FIELD_SCORE->rfield = rb_const_get(cSortField, rb_intern("SCORE"));
4278
4804
 
4805
+ rb_define_const(cSortField, "SCORE_REV", TypedData_Wrap_Struct(cSortField, &frb_sort_field_t, FRT_SORT_FIELD_SCORE_REV));
4806
+ FRT_SORT_FIELD_SCORE_REV->rfield = rb_const_get(cSortField, rb_intern("SCORE_REV"));
4807
+
4808
+ rb_define_const(cSortField, "DOC_ID", TypedData_Wrap_Struct(cSortField, &frb_sort_field_t, FRT_SORT_FIELD_DOC));
4279
4809
  oSORT_FIELD_DOC = rb_const_get(cSortField, rb_intern("DOC_ID"));
4280
- object_add((FrtSortField *)&FRT_SORT_FIELD_DOC, oSORT_FIELD_DOC);
4810
+ FRT_SORT_FIELD_DOC->rfield = oSORT_FIELD_DOC;
4281
4811
 
4282
- rb_define_const(cSortField, "DOC_ID_REV",
4283
- Data_Wrap_Struct(cSortField, NULL,
4284
- &frb_deref_free,
4285
- (FrtSortField *)&FRT_SORT_FIELD_DOC_REV));
4286
- object_add((FrtSortField *)&FRT_SORT_FIELD_DOC_REV,
4287
- rb_const_get(cSortField, rb_intern("DOC_ID_REV")));
4812
+ rb_define_const(cSortField, "DOC_ID_REV", TypedData_Wrap_Struct(cSortField, &frb_sort_field_t, FRT_SORT_FIELD_DOC_REV));
4813
+ FRT_SORT_FIELD_DOC_REV->rfield = rb_const_get(cSortField, rb_intern("DOC_ID_REV"));
4288
4814
  }
4289
4815
 
4290
4816
  /*
@@ -4307,9 +4833,7 @@ Init_SortField(void)
4307
4833
  * Remember that the :type parameter for SortField is set to :auto be default
4308
4834
  * be I strongly recommend you specify a :type value.
4309
4835
  */
4310
- static void
4311
- Init_Sort(void)
4312
- {
4836
+ static void Init_Sort(void) {
4313
4837
  /* Sort */
4314
4838
  cSort = rb_define_class_under(mSearch, "Sort", rb_cObject);
4315
4839
  rb_define_alloc_func(cSort, frb_sort_alloc);
@@ -4318,10 +4842,8 @@ Init_Sort(void)
4318
4842
  rb_define_method(cSort, "fields", frb_sort_get_fields, 0);
4319
4843
  rb_define_method(cSort, "to_s", frb_sort_to_s, 0);
4320
4844
 
4321
- rb_define_const(cSort, "RELEVANCE",
4322
- frb_sort_init(0, NULL, frb_sort_alloc(cSort)));
4323
- rb_define_const(cSort, "INDEX_ORDER",
4324
- frb_sort_init(1, &oSORT_FIELD_DOC, frb_sort_alloc(cSort)));
4845
+ rb_define_const(cSort, "RELEVANCE", frb_sort_init(0, NULL, frb_sort_alloc(cSort)));
4846
+ rb_define_const(cSort, "INDEX_ORDER", frb_sort_init(1, &oSORT_FIELD_DOC, frb_sort_alloc(cSort)));
4325
4847
  }
4326
4848
 
4327
4849
  /*
@@ -4354,9 +4876,7 @@ Init_Sort(void)
4354
4876
  * puts "#{searcher[doc_id][title] scored #{score}"
4355
4877
  * end
4356
4878
  */
4357
- static void
4358
- Init_Searcher(void)
4359
- {
4879
+ static void Init_Searcher(void) {
4360
4880
  /* option hash keys for Searcher#search */
4361
4881
  sym_offset = ID2SYM(rb_intern("offset"));
4362
4882
  sym_limit = ID2SYM(rb_intern("limit"));
@@ -4375,7 +4895,7 @@ Init_Searcher(void)
4375
4895
 
4376
4896
  /* Searcher */
4377
4897
  cSearcher = rb_define_class_under(mSearch, "Searcher", rb_cObject);
4378
- rb_define_alloc_func(cSearcher, frb_data_alloc);
4898
+ rb_define_alloc_func(cSearcher, frb_sea_alloc);
4379
4899
 
4380
4900
  rb_define_method(cSearcher, "initialize", frb_sea_init, 1);
4381
4901
  rb_define_method(cSearcher, "close", frb_sea_close, 0);
@@ -4403,11 +4923,9 @@ Init_Searcher(void)
4403
4923
  * RemoteSearcher, the MultiSearcher can be used to search multiple machines
4404
4924
  * at once.
4405
4925
  */
4406
- static void
4407
- Init_MultiSearcher(void)
4408
- {
4926
+ static void Init_MultiSearcher(void) {
4409
4927
  cMultiSearcher = rb_define_class_under(mSearch, "MultiSearcher", cSearcher);
4410
- rb_define_alloc_func(cMultiSearcher, frb_data_alloc);
4928
+ rb_define_alloc_func(cMultiSearcher, frb_ms_alloc);
4411
4929
  rb_define_method(cMultiSearcher, "initialize", frb_ms_init, -1);
4412
4930
  }
4413
4931