isomorfeus-ferret 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +612 -0
  3. data/README.md +44 -0
  4. data/ext/isomorfeus_ferret_ext/benchmark.c +223 -0
  5. data/ext/isomorfeus_ferret_ext/benchmark.h +45 -0
  6. data/ext/isomorfeus_ferret_ext/benchmarks_all.h +25 -0
  7. data/ext/isomorfeus_ferret_ext/bm_bitvector.c +123 -0
  8. data/ext/isomorfeus_ferret_ext/bm_hash.c +118 -0
  9. data/ext/isomorfeus_ferret_ext/bm_micro_string.c +40 -0
  10. data/ext/isomorfeus_ferret_ext/bm_store.c +93 -0
  11. data/ext/isomorfeus_ferret_ext/email.rl +21 -0
  12. data/ext/isomorfeus_ferret_ext/extconf.rb +5 -0
  13. data/ext/isomorfeus_ferret_ext/fio_tmpfile.h +53 -0
  14. data/ext/isomorfeus_ferret_ext/frb_analysis.c +2577 -0
  15. data/ext/isomorfeus_ferret_ext/frb_index.c +3457 -0
  16. data/ext/isomorfeus_ferret_ext/frb_lang.c +9 -0
  17. data/ext/isomorfeus_ferret_ext/frb_lang.h +17 -0
  18. data/ext/isomorfeus_ferret_ext/frb_qparser.c +629 -0
  19. data/ext/isomorfeus_ferret_ext/frb_search.c +4460 -0
  20. data/ext/isomorfeus_ferret_ext/frb_store.c +515 -0
  21. data/ext/isomorfeus_ferret_ext/frb_threading.h +30 -0
  22. data/ext/isomorfeus_ferret_ext/frb_utils.c +1127 -0
  23. data/ext/isomorfeus_ferret_ext/frt_analysis.c +1644 -0
  24. data/ext/isomorfeus_ferret_ext/frt_analysis.h +247 -0
  25. data/ext/isomorfeus_ferret_ext/frt_array.c +124 -0
  26. data/ext/isomorfeus_ferret_ext/frt_array.h +54 -0
  27. data/ext/isomorfeus_ferret_ext/frt_bitvector.c +95 -0
  28. data/ext/isomorfeus_ferret_ext/frt_bitvector.h +586 -0
  29. data/ext/isomorfeus_ferret_ext/frt_compound_io.c +374 -0
  30. data/ext/isomorfeus_ferret_ext/frt_config.h +44 -0
  31. data/ext/isomorfeus_ferret_ext/frt_document.c +134 -0
  32. data/ext/isomorfeus_ferret_ext/frt_document.h +52 -0
  33. data/ext/isomorfeus_ferret_ext/frt_except.c +95 -0
  34. data/ext/isomorfeus_ferret_ext/frt_except.h +188 -0
  35. data/ext/isomorfeus_ferret_ext/frt_field_index.c +233 -0
  36. data/ext/isomorfeus_ferret_ext/frt_field_index.h +42 -0
  37. data/ext/isomorfeus_ferret_ext/frt_filter.c +157 -0
  38. data/ext/isomorfeus_ferret_ext/frt_fs_store.c +502 -0
  39. data/ext/isomorfeus_ferret_ext/frt_global.c +427 -0
  40. data/ext/isomorfeus_ferret_ext/frt_global.h +290 -0
  41. data/ext/isomorfeus_ferret_ext/frt_hash.c +518 -0
  42. data/ext/isomorfeus_ferret_ext/frt_hash.h +466 -0
  43. data/ext/isomorfeus_ferret_ext/frt_hashset.c +191 -0
  44. data/ext/isomorfeus_ferret_ext/frt_hashset.h +206 -0
  45. data/ext/isomorfeus_ferret_ext/frt_helper.c +62 -0
  46. data/ext/isomorfeus_ferret_ext/frt_helper.h +13 -0
  47. data/ext/isomorfeus_ferret_ext/frt_ind.c +353 -0
  48. data/ext/isomorfeus_ferret_ext/frt_ind.h +54 -0
  49. data/ext/isomorfeus_ferret_ext/frt_index.c +6377 -0
  50. data/ext/isomorfeus_ferret_ext/frt_index.h +880 -0
  51. data/ext/isomorfeus_ferret_ext/frt_lang.c +104 -0
  52. data/ext/isomorfeus_ferret_ext/frt_lang.h +44 -0
  53. data/ext/isomorfeus_ferret_ext/frt_mempool.c +87 -0
  54. data/ext/isomorfeus_ferret_ext/frt_mempool.h +33 -0
  55. data/ext/isomorfeus_ferret_ext/frt_multimapper.c +349 -0
  56. data/ext/isomorfeus_ferret_ext/frt_multimapper.h +52 -0
  57. data/ext/isomorfeus_ferret_ext/frt_posh.c +1006 -0
  58. data/ext/isomorfeus_ferret_ext/frt_posh.h +973 -0
  59. data/ext/isomorfeus_ferret_ext/frt_priorityqueue.c +147 -0
  60. data/ext/isomorfeus_ferret_ext/frt_priorityqueue.h +147 -0
  61. data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +1612 -0
  62. data/ext/isomorfeus_ferret_ext/frt_q_const_score.c +157 -0
  63. data/ext/isomorfeus_ferret_ext/frt_q_filtered_query.c +209 -0
  64. data/ext/isomorfeus_ferret_ext/frt_q_fuzzy.c +281 -0
  65. data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +147 -0
  66. data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +672 -0
  67. data/ext/isomorfeus_ferret_ext/frt_q_parser.c +3084 -0
  68. data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +1182 -0
  69. data/ext/isomorfeus_ferret_ext/frt_q_prefix.c +98 -0
  70. data/ext/isomorfeus_ferret_ext/frt_q_range.c +665 -0
  71. data/ext/isomorfeus_ferret_ext/frt_q_span.c +2386 -0
  72. data/ext/isomorfeus_ferret_ext/frt_q_term.c +311 -0
  73. data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +166 -0
  74. data/ext/isomorfeus_ferret_ext/frt_ram_store.c +460 -0
  75. data/ext/isomorfeus_ferret_ext/frt_scanner.c +899 -0
  76. data/ext/isomorfeus_ferret_ext/frt_scanner.h +28 -0
  77. data/ext/isomorfeus_ferret_ext/frt_scanner_mb.c +6705 -0
  78. data/ext/isomorfeus_ferret_ext/frt_scanner_utf8.c +4419 -0
  79. data/ext/isomorfeus_ferret_ext/frt_search.c +1824 -0
  80. data/ext/isomorfeus_ferret_ext/frt_search.h +924 -0
  81. data/ext/isomorfeus_ferret_ext/frt_similarity.c +150 -0
  82. data/ext/isomorfeus_ferret_ext/frt_similarity.h +79 -0
  83. data/ext/isomorfeus_ferret_ext/frt_sort.c +796 -0
  84. data/ext/isomorfeus_ferret_ext/frt_stopwords.c +395 -0
  85. data/ext/isomorfeus_ferret_ext/frt_store.c +680 -0
  86. data/ext/isomorfeus_ferret_ext/frt_store.h +789 -0
  87. data/ext/isomorfeus_ferret_ext/frt_term_vectors.c +72 -0
  88. data/ext/isomorfeus_ferret_ext/frt_threading.h +23 -0
  89. data/ext/isomorfeus_ferret_ext/frt_win32.h +54 -0
  90. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +409 -0
  91. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +95 -0
  92. data/ext/isomorfeus_ferret_ext/libstemmer.c +93 -0
  93. data/ext/isomorfeus_ferret_ext/libstemmer.h +73 -0
  94. data/ext/isomorfeus_ferret_ext/q_parser.y +1366 -0
  95. data/ext/isomorfeus_ferret_ext/scanner.h +28 -0
  96. data/ext/isomorfeus_ferret_ext/scanner.in +43 -0
  97. data/ext/isomorfeus_ferret_ext/scanner.rl +84 -0
  98. data/ext/isomorfeus_ferret_ext/scanner_mb.rl +200 -0
  99. data/ext/isomorfeus_ferret_ext/scanner_utf8.rl +85 -0
  100. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.c +324 -0
  101. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.h +7 -0
  102. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.c +610 -0
  103. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.h +6 -0
  104. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.c +1104 -0
  105. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.h +6 -0
  106. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.c +749 -0
  107. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.h +7 -0
  108. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.c +1233 -0
  109. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.h +6 -0
  110. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.c +490 -0
  111. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.h +6 -0
  112. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.c +1217 -0
  113. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.h +7 -0
  114. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.c +1052 -0
  115. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.h +6 -0
  116. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.c +283 -0
  117. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.h +6 -0
  118. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.c +735 -0
  119. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.h +6 -0
  120. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.c +1003 -0
  121. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.h +7 -0
  122. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.c +1079 -0
  123. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.h +6 -0
  124. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.c +293 -0
  125. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.h +6 -0
  126. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.c +984 -0
  127. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.h +6 -0
  128. data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.c +686 -0
  129. data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.h +6 -0
  130. data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.c +325 -0
  131. data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.h +6 -0
  132. data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.c +620 -0
  133. data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.h +6 -0
  134. data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.c +1111 -0
  135. data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.h +6 -0
  136. data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.c +754 -0
  137. data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.h +6 -0
  138. data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.c +1242 -0
  139. data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.h +6 -0
  140. data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.c +495 -0
  141. data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.h +6 -0
  142. data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.c +1220 -0
  143. data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.h +6 -0
  144. data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.c +1059 -0
  145. data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.h +6 -0
  146. data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.c +285 -0
  147. data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.h +6 -0
  148. data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.c +741 -0
  149. data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.h +6 -0
  150. data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.c +1009 -0
  151. data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.h +6 -0
  152. data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.c +990 -0
  153. data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.h +6 -0
  154. data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.c +680 -0
  155. data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.h +6 -0
  156. data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.c +1083 -0
  157. data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.h +6 -0
  158. data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.c +294 -0
  159. data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.h +6 -0
  160. data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.c +2191 -0
  161. data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.h +6 -0
  162. data/ext/isomorfeus_ferret_ext/stem_api.c +66 -0
  163. data/ext/isomorfeus_ferret_ext/stem_api.h +26 -0
  164. data/ext/isomorfeus_ferret_ext/stem_header.h +57 -0
  165. data/ext/isomorfeus_ferret_ext/stem_modules.h +190 -0
  166. data/ext/isomorfeus_ferret_ext/stem_modules.txt +50 -0
  167. data/ext/isomorfeus_ferret_ext/stem_utilities.c +478 -0
  168. data/ext/isomorfeus_ferret_ext/test.c +850 -0
  169. data/ext/isomorfeus_ferret_ext/test.h +416 -0
  170. data/ext/isomorfeus_ferret_ext/test_1710.c +63 -0
  171. data/ext/isomorfeus_ferret_ext/test_analysis.c +1221 -0
  172. data/ext/isomorfeus_ferret_ext/test_array.c +272 -0
  173. data/ext/isomorfeus_ferret_ext/test_bitvector.c +600 -0
  174. data/ext/isomorfeus_ferret_ext/test_compound_io.c +170 -0
  175. data/ext/isomorfeus_ferret_ext/test_document.c +156 -0
  176. data/ext/isomorfeus_ferret_ext/test_except.c +244 -0
  177. data/ext/isomorfeus_ferret_ext/test_fields.c +522 -0
  178. data/ext/isomorfeus_ferret_ext/test_file_deleter.c +185 -0
  179. data/ext/isomorfeus_ferret_ext/test_filter.c +331 -0
  180. data/ext/isomorfeus_ferret_ext/test_fs_store.c +25 -0
  181. data/ext/isomorfeus_ferret_ext/test_global.c +299 -0
  182. data/ext/isomorfeus_ferret_ext/test_hash.c +485 -0
  183. data/ext/isomorfeus_ferret_ext/test_hashset.c +288 -0
  184. data/ext/isomorfeus_ferret_ext/test_helper.c +47 -0
  185. data/ext/isomorfeus_ferret_ext/test_highlighter.c +548 -0
  186. data/ext/isomorfeus_ferret_ext/test_index.c +2323 -0
  187. data/ext/isomorfeus_ferret_ext/test_lang.c +74 -0
  188. data/ext/isomorfeus_ferret_ext/test_mempool.c +102 -0
  189. data/ext/isomorfeus_ferret_ext/test_multimapper.c +64 -0
  190. data/ext/isomorfeus_ferret_ext/test_priorityqueue.c +213 -0
  191. data/ext/isomorfeus_ferret_ext/test_q_const_score.c +84 -0
  192. data/ext/isomorfeus_ferret_ext/test_q_filtered.c +61 -0
  193. data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +241 -0
  194. data/ext/isomorfeus_ferret_ext/test_q_parser.c +464 -0
  195. data/ext/isomorfeus_ferret_ext/test_q_span.c +575 -0
  196. data/ext/isomorfeus_ferret_ext/test_ram_store.c +77 -0
  197. data/ext/isomorfeus_ferret_ext/test_search.c +1874 -0
  198. data/ext/isomorfeus_ferret_ext/test_segments.c +167 -0
  199. data/ext/isomorfeus_ferret_ext/test_similarity.c +25 -0
  200. data/ext/isomorfeus_ferret_ext/test_sort.c +333 -0
  201. data/ext/isomorfeus_ferret_ext/test_store.c +591 -0
  202. data/ext/isomorfeus_ferret_ext/test_store.h +3 -0
  203. data/ext/isomorfeus_ferret_ext/test_term.c +351 -0
  204. data/ext/isomorfeus_ferret_ext/test_term_vectors.c +373 -0
  205. data/ext/isomorfeus_ferret_ext/test_test.c +83 -0
  206. data/ext/isomorfeus_ferret_ext/test_threading.c +188 -0
  207. data/ext/isomorfeus_ferret_ext/testhelper.c +561 -0
  208. data/ext/isomorfeus_ferret_ext/testhelper.h +25 -0
  209. data/ext/isomorfeus_ferret_ext/tests_all.h +87 -0
  210. data/ext/isomorfeus_ferret_ext/uchar-ucs4.rl +1854 -0
  211. data/ext/isomorfeus_ferret_ext/uchar-utf8.rl +1999 -0
  212. data/ext/isomorfeus_ferret_ext/url.rl +27 -0
  213. data/ext/isomorfeus_ferret_ext/word_list.h +15156 -0
  214. data/lib/isomorfeus/ferret/document.rb +132 -0
  215. data/lib/isomorfeus/ferret/field_symbol.rb +85 -0
  216. data/lib/isomorfeus/ferret/index/field_infos.rb +48 -0
  217. data/lib/isomorfeus/ferret/index/index.rb +970 -0
  218. data/lib/isomorfeus/ferret/monitor.rb +323 -0
  219. data/lib/isomorfeus/ferret/stdlib_patches.rb +151 -0
  220. data/lib/isomorfeus/ferret/version.rb +5 -0
  221. data/lib/isomorfeus-ferret.rb +8 -0
  222. metadata +307 -0
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Exception Handling Framework
3
+ *
4
+ * Exception Handling looks something like this;
5
+ *
6
+ * ### NOTE ###
7
+ * You must use a FRT_FINALLY block if you use "default:" block. Otherwise the
8
+ * default: block will get called in place of the FRT_FINALLY block.
9
+ *
10
+ *
11
+ * <pre>
12
+ * FRT_TRY
13
+ * FRT_RAISE(FRT_EXCEPTION, msg1);
14
+ * break;
15
+ * case FRT_EXCEPTION:
16
+ * // This should be called
17
+ * exception_handled = true;
18
+ * FRT_HANDLED();
19
+ * break;
20
+ * default:
21
+ * // shouldn't enter here
22
+ * break;
23
+ * FRT_XFINALLY
24
+ * // this code will always be run
25
+ * if (close_widget_one(arg) == 0) {
26
+ * FRT_RAISE(FRT_EXCEPTION_CODE, msg);
27
+ * }
28
+ * // this code will also always run, even if the above exception is
29
+ * // raised
30
+ * if (close_widget_two(arg) == 0) {
31
+ * FRT_RAISE(FRT_EXCEPTION_CODE, msg);
32
+ * }
33
+ * FRT_XENDTRY
34
+ * </pre>
35
+ *
36
+ * Basically exception handling uses the following macros;
37
+ *
38
+ * FRT_TRY
39
+ * Sets up the exception handler and need be placed before any expected
40
+ * exceptions would be raised.
41
+ *
42
+ * case <EXCEPTION_CODE>:
43
+ * Internally the exception handling uses a switch statement so use the case
44
+ * statement with the appropriate error code to catch Exceptions. Hence, if
45
+ * you want to catch all exceptions, use the default keyword.
46
+ *
47
+ * FRT_HANDLED
48
+ * If you catch and handle an exception you need to explicitely call
49
+ * FRT_HANDLED(); or the exeption will be re-raised once the current exception
50
+ * handling context is left.
51
+ *
52
+ * case FRT_FINALLY:
53
+ * Code in this block is always called. Use this block to close any
54
+ * resources opened in the Exception handling body.
55
+ *
56
+ * FRT_ENDTRY
57
+ * Must be placed at the end of all exception handling code.
58
+ *
59
+ * FRT_XFINALLY
60
+ * Similar to case FRT_FINALLY: except that it uses a fall through (ie, you must
61
+ * not use a break before it) instead of a jump to get to it. This saves a
62
+ * jump. It must be used in combination with FRT_XENDTRY and must not have any
63
+ * other catches. This is an optimization so should probably be not be used
64
+ * in most cases.
65
+ *
66
+ * FRT_XCATCHALL
67
+ * Like FRT_XFINALLY but the block is only called when an exception is raised.
68
+ * Must use in combination with FRT_XENDTRY and do not have any other FRT_FINALLY or
69
+ * catch block.
70
+ *
71
+ * FRT_XENDTRY
72
+ * Must use in combination with FRT_XFINALLY or FRT_XCATCHALL. Simply, it doesn't
73
+ * jump to FRT_FINALLY, making it more efficient.
74
+ */
75
+ #ifndef FRT_EXCEPT_H
76
+ #define FRT_EXCEPT_H
77
+
78
+ #include <setjmp.h>
79
+ #include "frt_config.h"
80
+
81
+ /* TODO make this an enum */
82
+ #define FRT_BODY 0
83
+ #define FRT_FINALLY 1
84
+ #define FRT_EXCEPTION 2
85
+ #define FRT_IO_ERROR 3
86
+ #define FRT_FILE_NOT_FOUND_ERROR 4
87
+ #define FRT_ARG_ERROR 5
88
+ #define FRT_EOF_ERROR 6
89
+ #define FRT_UNSUPPORTED_ERROR 7
90
+ #define FRT_STATE_ERROR 8
91
+ #define FRT_PARSE_ERROR 9
92
+ #define FRT_MEM_ERROR 10
93
+ #define FRT_INDEX_ERROR 11
94
+ #define FRT_LOCK_ERROR 12
95
+
96
+ #define FRT_EM_EXCEPTION "Exception"
97
+ #define FRT_EM_IO_ERROR "IO Error"
98
+ #define FRT_EM_FILE_NOT_FOUND_ERROR "File Not Found Error"
99
+ #define FRT_EM_ARG_ERROR "Argument Error"
100
+ #define FRT_EM_EOF_ERROR "End-of-File Error"
101
+ #define FRT_EM_UNSUPPORTED_ERROR "Unsupported Function Error"
102
+ #define FRT_EM_STATE_ERROR "State Error"
103
+ #define FRT_EM_PARSE_ERROR "ParseError"
104
+ #define FRT_EM_MEM_ERROR "Memory Error"
105
+ #define FRT_EM_INDEX_ERROR "Index Error"
106
+ #define FRT_EM_LOCK_ERROR "Lock Error"
107
+
108
+ extern const char *const ERROR_TYPES[];
109
+ extern const char *const FRT_UNSUPPORTED_ERROR_MSG;
110
+ extern const char *const FRT_EOF_ERROR_MSG;
111
+ extern const char *frt_err_code_to_type(const int err_code);
112
+
113
+ extern void frb_rb_raise(const char *file, int line_num, const char *func, const char *err_type, const char *fmt, ...);
114
+
115
+ typedef struct frt_xcontext_t
116
+ {
117
+ jmp_buf jbuf;
118
+ struct frt_xcontext_t *next;
119
+ const char *msg;
120
+ int excode;
121
+ unsigned int handled : 1;
122
+ unsigned int in_finally : 1;
123
+ } frt_xcontext_t;
124
+
125
+ #define FRT_TRY\
126
+ do {\
127
+ frt_xcontext_t xcontext;\
128
+ xcontext.excode = 0;\
129
+ xcontext.msg = NULL;\
130
+ frt_xpush_context(&xcontext);\
131
+ switch (setjmp(xcontext.jbuf)) {\
132
+ case FRT_BODY:
133
+
134
+
135
+ #define FRT_XENDTRY\
136
+ }\
137
+ frt_xpop_context();\
138
+ } while (0);
139
+
140
+ #define FRT_ENDTRY\
141
+ }\
142
+ if (!xcontext.in_finally) {\
143
+ frt_xpop_context();\
144
+ xcontext.in_finally = 1;\
145
+ longjmp(xcontext.jbuf, FRT_FINALLY);\
146
+ }\
147
+ } while (0);
148
+
149
+ #define FRT_RETURN_EARLY() frt_xpop_context()
150
+
151
+ #define FRT_XFINALLY default: xcontext.in_finally = 1;
152
+
153
+ #define FRT_XCATCHALL break; default: xcontext.in_finally = 1;
154
+
155
+ #define FRT_HANDLED() xcontext.handled = 1; /* true */
156
+
157
+ #define FRT_XMSG_BUFFER_SIZE 2048
158
+ #define FRT_XMSG_BUFFER_FINAL_SIZE 2248
159
+
160
+ #ifdef FRT_HAS_ISO_VARARGS
161
+ # define FRT_RAISE(excode, ...) do {\
162
+ snprintf(frt_xmsg_buffer, FRT_XMSG_BUFFER_SIZE, __VA_ARGS__);\
163
+ snprintf(frt_xmsg_buffer_final, FRT_XMSG_BUFFER_FINAL_SIZE,\
164
+ "Error occurred in %s:%d - %s\n\t%s",\
165
+ __FILE__, __LINE__, __func__, frt_xmsg_buffer);\
166
+ frt_xraise(excode, frt_xmsg_buffer_final);\
167
+ } while (0)
168
+ #elif defined(FRT_HAS_GNUC_VARARGS)
169
+ # define FRT_RAISE(excode, args...) do {\
170
+ snprintf(frt_xmsg_buffer, FRT_XMSG_BUFFER_SIZE, ##args);\
171
+ snprintf(frt_xmsg_buffer_final, FRT_XMSG_BUFFER_FINAL_SIZE,\
172
+ "Error occurred in %s:%d - %s\n\t%s\n",\
173
+ __FILE__, __LINE__, __func__, frt_xmsg_buffer);\
174
+ frt_xraise(excode, frt_xmsg_buffer_final);\
175
+ } while (0)
176
+
177
+ #else
178
+ extern void FRT_RAISE(int excode, const char *fmt, ...);
179
+ #endif
180
+
181
+ extern void frt_xraise(int excode, const char *const msg);
182
+ extern void frt_xpush_context(frt_xcontext_t *context);
183
+ extern void frt_xpop_context();
184
+
185
+ extern char frt_xmsg_buffer[FRT_XMSG_BUFFER_SIZE];
186
+ extern char frt_xmsg_buffer_final[FRT_XMSG_BUFFER_FINAL_SIZE];
187
+
188
+ #endif
@@ -0,0 +1,233 @@
1
+ #include <string.h>
2
+ #include "frt_field_index.h"
3
+
4
+ /***************************************************************************
5
+ *
6
+ * FrtFieldIndex
7
+ *
8
+ ***************************************************************************/
9
+
10
+ static unsigned long long field_index_hash(const void *p)
11
+ {
12
+ FrtFieldIndex *self = (FrtFieldIndex *)p;
13
+ return frt_str_hash(rb_id2name(self->field)) ^ (unsigned long long)(self->klass);
14
+ }
15
+
16
+ static int field_index_eq(const void *p1, const void *p2)
17
+ {
18
+ FrtFieldIndex *fi1 = (FrtFieldIndex *)p1;
19
+ FrtFieldIndex *fi2 = (FrtFieldIndex *)p2;
20
+ return (fi1->field == fi2->field) &&
21
+ (fi1->klass->type == fi2->klass->type);
22
+ }
23
+
24
+ static void field_index_destroy(void *p)
25
+ {
26
+ FrtFieldIndex *self = (FrtFieldIndex *)p;
27
+ if (self->index) {
28
+ self->klass->destroy_index(self->index);
29
+ }
30
+ free(self);
31
+ }
32
+
33
+ FrtFieldIndex *frt_field_index_get(FrtIndexReader *ir, FrtSymbol field,
34
+ const FrtFieldIndexClass *klass)
35
+ {
36
+ int length = 0;
37
+ FrtTermEnum *volatile te = NULL;
38
+ FrtTermDocEnum *volatile tde = NULL;
39
+ FrtFieldInfo *fi = frt_fis_get_field(ir->fis, field);
40
+ const volatile int field_num = fi ? fi->number : -1;
41
+ FrtFieldIndex *volatile self = NULL;
42
+ FrtFieldIndex key;
43
+
44
+ if (field_num < 0) {
45
+ FRT_RAISE(FRT_ARG_ERROR,
46
+ "Cannot sort by field \"%s\". It doesn't exist in the index.",
47
+ rb_id2name(field));
48
+ }
49
+
50
+ if (!ir->field_index_cache) {
51
+ ir->field_index_cache = frt_h_new(&field_index_hash, &field_index_eq,
52
+ NULL, &field_index_destroy);
53
+ }
54
+
55
+ key.field = field;
56
+ key.klass = klass;
57
+ self = (FrtFieldIndex *)frt_h_get(ir->field_index_cache, &key);
58
+
59
+ if (self == NULL) {
60
+ self = FRT_ALLOC(FrtFieldIndex);
61
+ self->klass = klass;
62
+ /* FieldIndex only lives as long as the IndexReader lives so we can
63
+ * just use the field_infos field symbol */
64
+ self->field = fi->name;
65
+
66
+ length = ir->max_doc(ir);
67
+ if (length > 0) {
68
+ FRT_TRY
69
+ {
70
+ void *index;
71
+ tde = ir->term_docs(ir);
72
+ te = ir->terms(ir, field_num);
73
+ index = self->index = klass->create_index(length);
74
+ while (te->next(te)) {
75
+ tde->seek_te(tde, te);
76
+ klass->handle_term(index, tde, te->curr_term);
77
+ }
78
+ }
79
+ FRT_XFINALLY
80
+ tde->close(tde);
81
+ te->close(te);
82
+ FRT_XENDTRY
83
+ }
84
+ frt_h_set(ir->field_index_cache, self, self);
85
+ }
86
+
87
+ return self;
88
+ }
89
+
90
+ /******************************************************************************
91
+ * ByteFieldIndex < FieldIndex
92
+ *
93
+ * The ByteFieldIndex holds an array of integers for each document in the
94
+ * index where the integer represents the sort value for the document. This
95
+ * index should only be used for sorting and not as a field cache of the
96
+ * column's value.
97
+ ******************************************************************************/
98
+ static void byte_handle_term(void *index_ptr,
99
+ FrtTermDocEnum *tde,
100
+ const char *text)
101
+ {
102
+ long *index = (long *)index_ptr;
103
+ long val = index[-1]++;
104
+ (void)text;
105
+ while (tde->next(tde)) {
106
+ index[tde->doc_num(tde)] = val;
107
+ }
108
+ }
109
+
110
+ static void *byte_create_index(int size)
111
+ {
112
+ long *index = FRT_ALLOC_AND_ZERO_N(long, size + 1);
113
+ index[0] = 1;
114
+ return &index[1];
115
+ }
116
+
117
+ static void byte_destroy_index(void *p)
118
+ {
119
+ long *index = (long *)p;
120
+ free(&index[-1]);
121
+ }
122
+
123
+ const FrtFieldIndexClass FRT_BYTE_FIELD_INDEX_CLASS = {
124
+ "byte",
125
+ &byte_create_index,
126
+ &byte_destroy_index,
127
+ &byte_handle_term
128
+ };
129
+
130
+ /******************************************************************************
131
+ * IntegerFieldIndex < FieldIndex
132
+ ******************************************************************************/
133
+ static void *integer_create_index(int size)
134
+ {
135
+ return FRT_ALLOC_AND_ZERO_N(long, size);
136
+ }
137
+
138
+ static void integer_handle_term(void *index_ptr,
139
+ FrtTermDocEnum *tde,
140
+ const char *text)
141
+ {
142
+ long *index = (long *)index_ptr;
143
+ long val;
144
+ sscanf(text, "%ld", &val);
145
+ while (tde->next(tde)) {
146
+ index[tde->doc_num(tde)] = val;
147
+ }
148
+ }
149
+
150
+ const FrtFieldIndexClass FRT_INTEGER_FIELD_INDEX_CLASS = {
151
+ "integer",
152
+ &integer_create_index,
153
+ &free,
154
+ &integer_handle_term
155
+ };
156
+
157
+ /******************************************************************************
158
+ * FloatFieldIndex < FieldIndex
159
+ ******************************************************************************/
160
+ #define VALUES_ARRAY_START_SIZE 8
161
+ static void *float_create_index(int size)
162
+ {
163
+ return FRT_ALLOC_AND_ZERO_N(float, size);
164
+ }
165
+
166
+ static void float_handle_term(void *index_ptr,
167
+ FrtTermDocEnum *tde,
168
+ const char *text)
169
+ {
170
+ float *index = (float *)index_ptr;
171
+ float val;
172
+ sscanf(text, "%g", &val);
173
+ while (tde->next(tde)) {
174
+ index[tde->doc_num(tde)] = val;
175
+ }
176
+ }
177
+
178
+ const FrtFieldIndexClass FRT_FLOAT_FIELD_INDEX_CLASS = {
179
+ "float",
180
+ &float_create_index,
181
+ &free,
182
+ &float_handle_term
183
+ };
184
+
185
+ /******************************************************************************
186
+ * StringFieldIndex < FieldIndex
187
+ ******************************************************************************/
188
+
189
+ static void *string_create_index(int size)
190
+ {
191
+ FrtStringIndex *self = FRT_ALLOC_AND_ZERO(FrtStringIndex);
192
+ self->size = size;
193
+ self->index = FRT_ALLOC_AND_ZERO_N(long, size);
194
+ self->v_capa = VALUES_ARRAY_START_SIZE;
195
+ self->v_size = 1; /* leave the first value as NULL */
196
+ self->values = FRT_ALLOC_AND_ZERO_N(char *, VALUES_ARRAY_START_SIZE);
197
+ return self;
198
+ }
199
+
200
+ static void string_destroy_index(void *p)
201
+ {
202
+ FrtStringIndex *self = (FrtStringIndex *)p;
203
+ int i;
204
+ free(self->index);
205
+ for (i = 0; i < self->v_size; i++) {
206
+ free(self->values[i]);
207
+ }
208
+ free(self->values);
209
+ free(self);
210
+ }
211
+
212
+ static void string_handle_term(void *index_ptr,
213
+ FrtTermDocEnum *tde,
214
+ const char *text)
215
+ {
216
+ FrtStringIndex *index = (FrtStringIndex *)index_ptr;
217
+ if (index->v_size >= index->v_capa) {
218
+ index->v_capa *= 2;
219
+ FRT_REALLOC_N(index->values, char *, index->v_capa);
220
+ }
221
+ index->values[index->v_size] = frt_estrdup(text);
222
+ while (tde->next(tde)) {
223
+ index->index[tde->doc_num(tde)] = index->v_size;
224
+ }
225
+ index->v_size++;
226
+ }
227
+
228
+ const FrtFieldIndexClass FRT_STRING_FIELD_INDEX_CLASS = {
229
+ "string",
230
+ &string_create_index,
231
+ &string_destroy_index,
232
+ &string_handle_term
233
+ };
@@ -0,0 +1,42 @@
1
+ #ifndef FRT_FIELD_INDEX_H
2
+ #define FRT_FIELD_INDEX_H
3
+
4
+ #include "frt_index.h"
5
+
6
+ /***************************************************************************
7
+ *
8
+ * FrtFieldIndex
9
+ *
10
+ ***************************************************************************/
11
+
12
+ typedef struct FrtStringIndex {
13
+ int size;
14
+ long *index;
15
+ char **values;
16
+ int v_size;
17
+ int v_capa;
18
+ } FrtStringIndex;
19
+
20
+ typedef struct FrtFieldIndexClass FrtFieldIndexClass;
21
+ struct FrtFieldIndexClass {
22
+ const char *type;
23
+ void *(*create_index)(int size);
24
+ void (*destroy_index)(void *p);
25
+ void (*handle_term)(void *index, FrtTermDocEnum *tde, const char *text);
26
+ };
27
+
28
+ typedef struct FrtFieldIndex {
29
+ FrtSymbol field;
30
+ const FrtFieldIndexClass *klass;
31
+ void *index;
32
+ } FrtFieldIndex;
33
+
34
+ extern const FrtFieldIndexClass FRT_INTEGER_FIELD_INDEX_CLASS;
35
+ extern const FrtFieldIndexClass FRT_FLOAT_FIELD_INDEX_CLASS;
36
+ extern const FrtFieldIndexClass FRT_STRING_FIELD_INDEX_CLASS;
37
+ extern const FrtFieldIndexClass FRT_BYTE_FIELD_INDEX_CLASS;
38
+
39
+ extern FrtFieldIndex *frt_field_index_get(FrtIndexReader *ir, FrtSymbol field,
40
+ const FrtFieldIndexClass *klass);
41
+
42
+ #endif
@@ -0,0 +1,157 @@
1
+ #include "frt_global.h"
2
+ #include "frt_search.h"
3
+ #include <string.h>
4
+
5
+ /***************************************************************************
6
+ *
7
+ * Filter
8
+ *
9
+ ***************************************************************************/
10
+
11
+ void frt_filt_destroy_i(FrtFilter *filt)
12
+ {
13
+ frt_h_destroy(filt->cache);
14
+ free(filt);
15
+ }
16
+
17
+ void frt_filt_deref(FrtFilter *filt)
18
+ {
19
+ if (--(filt->ref_cnt) == 0) {
20
+ filt->destroy_i(filt);
21
+ }
22
+ }
23
+
24
+ FrtBitVector *frt_filt_get_bv(FrtFilter *filt, FrtIndexReader *ir)
25
+ {
26
+ FrtCacheObject *co = (FrtCacheObject *)frt_h_get(filt->cache, ir);
27
+
28
+ if (!co) {
29
+ FrtBitVector *bv;
30
+ if (!ir->cache) {
31
+ frt_ir_add_cache(ir);
32
+ }
33
+ bv = filt->get_bv_i(filt, ir);
34
+ co = frt_co_create(filt->cache, ir->cache, filt, ir,
35
+ (frt_free_ft)&frt_bv_destroy, (void *)bv);
36
+ }
37
+ return (FrtBitVector *)co->obj;
38
+ }
39
+
40
+ static char *filt_to_s_i(FrtFilter *filt)
41
+ {
42
+ return frt_estrdup(rb_id2name(filt->name));
43
+ }
44
+
45
+ static unsigned long long frt_filt_hash_default(FrtFilter *filt)
46
+ {
47
+ (void)filt;
48
+ return 0;
49
+ }
50
+
51
+ static int frt_filt_eq_default(FrtFilter *filt, FrtFilter *o)
52
+ {
53
+ (void)filt; (void)o;
54
+ return false;
55
+ }
56
+
57
+ FrtFilter *frt_filt_create(size_t size, FrtSymbol name)
58
+ {
59
+ FrtFilter *filt = (FrtFilter *)frt_emalloc(size);
60
+ filt->cache = frt_co_hash_create();
61
+ filt->name = name;
62
+ filt->to_s = &filt_to_s_i;
63
+ filt->hash = &frt_filt_hash_default;
64
+ filt->eq = &frt_filt_eq_default;
65
+ filt->destroy_i = &frt_filt_destroy_i;
66
+ filt->ref_cnt = 1;
67
+ return filt;
68
+ }
69
+
70
+ unsigned long long frt_filt_hash(FrtFilter *filt)
71
+ {
72
+ return frt_str_hash(rb_id2name(filt->name)) ^ filt->hash(filt);
73
+ }
74
+
75
+ int frt_filt_eq(FrtFilter *filt, FrtFilter *o)
76
+ {
77
+ return ((filt == o)
78
+ || ((filt->name == o->name)
79
+ && (filt->eq == o->eq)
80
+ && (filt->eq(filt, o))));
81
+ }
82
+
83
+ /***************************************************************************
84
+ *
85
+ * QueryFilter
86
+ *
87
+ ***************************************************************************/
88
+
89
+ #define QF(filt) ((QueryFilter *)(filt))
90
+ typedef struct QueryFilter
91
+ {
92
+ FrtFilter super;
93
+ FrtQuery *query;
94
+ } QueryFilter;
95
+
96
+ static char *qfilt_to_s(FrtFilter *filt)
97
+ {
98
+ FrtQuery *query = QF(filt)->query;
99
+ char *query_str = query->to_s(query, (FrtSymbol)NULL);
100
+ char *filter_str = frt_strfmt("QueryFilter< %s >", query_str);
101
+ free(query_str);
102
+ return filter_str;
103
+ }
104
+
105
+ static FrtBitVector *qfilt_get_bv_i(FrtFilter *filt, FrtIndexReader *ir)
106
+ {
107
+ FrtBitVector *bv = frt_bv_new_capa(ir->max_doc(ir));
108
+ FrtSearcher *sea = frt_isea_new(ir);
109
+ FrtWeight *weight = frt_q_weight(QF(filt)->query, sea);
110
+ FrtScorer *scorer = weight->scorer(weight, ir);
111
+ if (scorer) {
112
+ while (scorer->next(scorer)) {
113
+ frt_bv_set(bv, scorer->doc);
114
+ }
115
+ scorer->destroy(scorer);
116
+ }
117
+ weight->destroy(weight);
118
+ free(sea);
119
+ return bv;
120
+ }
121
+
122
+ static unsigned long long qfilt_hash(FrtFilter *filt)
123
+ {
124
+ return frt_q_hash(QF(filt)->query);
125
+ }
126
+
127
+ static int qfilt_eq(FrtFilter *filt, FrtFilter *o)
128
+ {
129
+ return frt_q_eq(QF(filt)->query, QF(o)->query);
130
+ }
131
+
132
+ static void qfilt_destroy_i(FrtFilter *filt)
133
+ {
134
+ FrtQuery *query = QF(filt)->query;
135
+ frt_q_deref(query);
136
+ frt_filt_destroy_i(filt);
137
+ }
138
+
139
+ FrtFilter *frt_qfilt_new_nr(FrtQuery *query)
140
+ {
141
+ FrtFilter *filt = filt_new(QueryFilter);
142
+
143
+ QF(filt)->query = query;
144
+
145
+ filt->get_bv_i = &qfilt_get_bv_i;
146
+ filt->hash = &qfilt_hash;
147
+ filt->eq = &qfilt_eq;
148
+ filt->to_s = &qfilt_to_s;
149
+ filt->destroy_i = &qfilt_destroy_i;
150
+ return filt;
151
+ }
152
+
153
+ FrtFilter *frt_qfilt_new(FrtQuery *query)
154
+ {
155
+ FRT_REF(query);
156
+ return frt_qfilt_new_nr(query);
157
+ }