ferret 0.9.6 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (295) hide show
  1. data/MIT-LICENSE +1 -1
  2. data/README +12 -24
  3. data/Rakefile +38 -54
  4. data/TODO +14 -17
  5. data/ext/analysis.c +982 -823
  6. data/ext/analysis.h +133 -76
  7. data/ext/array.c +96 -58
  8. data/ext/array.h +40 -13
  9. data/ext/bitvector.c +476 -118
  10. data/ext/bitvector.h +264 -22
  11. data/ext/compound_io.c +217 -229
  12. data/ext/defines.h +49 -0
  13. data/ext/document.c +107 -317
  14. data/ext/document.h +31 -65
  15. data/ext/except.c +81 -36
  16. data/ext/except.h +117 -55
  17. data/ext/extconf.rb +2 -9
  18. data/ext/ferret.c +211 -104
  19. data/ext/ferret.h +22 -11
  20. data/ext/filter.c +97 -82
  21. data/ext/fs_store.c +348 -367
  22. data/ext/global.c +226 -188
  23. data/ext/global.h +44 -26
  24. data/ext/hash.c +474 -391
  25. data/ext/hash.h +441 -68
  26. data/ext/hashset.c +124 -96
  27. data/ext/hashset.h +169 -20
  28. data/ext/helper.c +56 -5
  29. data/ext/helper.h +7 -0
  30. data/ext/inc/lang.h +29 -49
  31. data/ext/inc/threading.h +31 -0
  32. data/ext/ind.c +288 -278
  33. data/ext/ind.h +68 -0
  34. data/ext/index.c +5688 -0
  35. data/ext/index.h +663 -616
  36. data/ext/lang.h +29 -49
  37. data/ext/libstemmer.c +3 -3
  38. data/ext/mem_pool.c +84 -0
  39. data/ext/mem_pool.h +35 -0
  40. data/ext/posh.c +1006 -0
  41. data/ext/posh.h +1007 -0
  42. data/ext/priorityqueue.c +117 -194
  43. data/ext/priorityqueue.h +135 -39
  44. data/ext/q_boolean.c +1305 -1108
  45. data/ext/q_const_score.c +106 -93
  46. data/ext/q_filtered_query.c +138 -135
  47. data/ext/q_fuzzy.c +206 -242
  48. data/ext/q_match_all.c +94 -80
  49. data/ext/q_multi_term.c +663 -0
  50. data/ext/q_parser.c +667 -593
  51. data/ext/q_phrase.c +992 -555
  52. data/ext/q_prefix.c +72 -61
  53. data/ext/q_range.c +235 -210
  54. data/ext/q_span.c +1480 -1166
  55. data/ext/q_term.c +273 -246
  56. data/ext/q_wildcard.c +127 -114
  57. data/ext/r_analysis.c +1720 -711
  58. data/ext/r_index.c +3049 -0
  59. data/ext/r_qparser.c +433 -146
  60. data/ext/r_search.c +2934 -1993
  61. data/ext/r_store.c +372 -143
  62. data/ext/r_utils.c +941 -0
  63. data/ext/ram_store.c +330 -326
  64. data/ext/search.c +1291 -668
  65. data/ext/search.h +403 -702
  66. data/ext/similarity.c +91 -113
  67. data/ext/similarity.h +45 -30
  68. data/ext/sort.c +721 -484
  69. data/ext/stopwords.c +361 -273
  70. data/ext/store.c +556 -58
  71. data/ext/store.h +706 -126
  72. data/ext/tags +3578 -2780
  73. data/ext/term_vectors.c +352 -0
  74. data/ext/threading.h +31 -0
  75. data/ext/win32.h +54 -0
  76. data/lib/ferret.rb +5 -17
  77. data/lib/ferret/document.rb +130 -2
  78. data/lib/ferret/index.rb +577 -26
  79. data/lib/ferret/number_tools.rb +157 -0
  80. data/lib/ferret_version.rb +3 -0
  81. data/test/test_helper.rb +5 -13
  82. data/test/unit/analysis/tc_analyzer.rb +513 -1
  83. data/test/unit/analysis/{ctc_tokenstream.rb → tc_token_stream.rb} +23 -0
  84. data/test/unit/index/tc_index.rb +183 -240
  85. data/test/unit/index/tc_index_reader.rb +312 -479
  86. data/test/unit/index/tc_index_writer.rb +397 -13
  87. data/test/unit/index/th_doc.rb +269 -206
  88. data/test/unit/query_parser/tc_query_parser.rb +40 -33
  89. data/test/unit/search/tc_filter.rb +59 -71
  90. data/test/unit/search/tc_fuzzy_query.rb +24 -16
  91. data/test/unit/search/tc_index_searcher.rb +23 -201
  92. data/test/unit/search/tc_multi_searcher.rb +78 -226
  93. data/test/unit/search/tc_search_and_sort.rb +93 -81
  94. data/test/unit/search/tc_sort.rb +23 -23
  95. data/test/unit/search/tc_sort_field.rb +7 -7
  96. data/test/unit/search/tc_spans.rb +51 -47
  97. data/test/unit/search/tm_searcher.rb +339 -0
  98. data/test/unit/store/tc_fs_store.rb +1 -1
  99. data/test/unit/store/tm_store_lock.rb +3 -3
  100. data/test/unit/tc_document.rb +81 -0
  101. data/test/unit/ts_analysis.rb +1 -1
  102. data/test/unit/ts_utils.rb +1 -1
  103. data/test/unit/utils/tc_bit_vector.rb +288 -0
  104. data/test/unit/utils/tc_number_tools.rb +117 -0
  105. data/test/unit/utils/tc_priority_queue.rb +106 -0
  106. metadata +140 -301
  107. data/CHANGELOG +0 -9
  108. data/ext/dummy.exe +0 -0
  109. data/ext/field.c +0 -408
  110. data/ext/frtio.h +0 -13
  111. data/ext/inc/except.h +0 -90
  112. data/ext/index_io.c +0 -382
  113. data/ext/index_rw.c +0 -2658
  114. data/ext/lang.c +0 -41
  115. data/ext/nix_io.c +0 -134
  116. data/ext/q_multi_phrase.c +0 -380
  117. data/ext/r_doc.c +0 -582
  118. data/ext/r_index_io.c +0 -1021
  119. data/ext/r_term.c +0 -219
  120. data/ext/term.c +0 -820
  121. data/ext/termdocs.c +0 -611
  122. data/ext/vector.c +0 -637
  123. data/ext/w32_io.c +0 -150
  124. data/lib/ferret/analysis.rb +0 -11
  125. data/lib/ferret/analysis/analyzers.rb +0 -112
  126. data/lib/ferret/analysis/standard_tokenizer.rb +0 -71
  127. data/lib/ferret/analysis/token.rb +0 -100
  128. data/lib/ferret/analysis/token_filters.rb +0 -86
  129. data/lib/ferret/analysis/token_stream.rb +0 -26
  130. data/lib/ferret/analysis/tokenizers.rb +0 -112
  131. data/lib/ferret/analysis/word_list_loader.rb +0 -27
  132. data/lib/ferret/document/document.rb +0 -152
  133. data/lib/ferret/document/field.rb +0 -312
  134. data/lib/ferret/index/compound_file_io.rb +0 -338
  135. data/lib/ferret/index/document_writer.rb +0 -289
  136. data/lib/ferret/index/field_infos.rb +0 -279
  137. data/lib/ferret/index/fields_io.rb +0 -181
  138. data/lib/ferret/index/index.rb +0 -675
  139. data/lib/ferret/index/index_file_names.rb +0 -33
  140. data/lib/ferret/index/index_reader.rb +0 -503
  141. data/lib/ferret/index/index_writer.rb +0 -534
  142. data/lib/ferret/index/multi_reader.rb +0 -377
  143. data/lib/ferret/index/multiple_term_doc_pos_enum.rb +0 -98
  144. data/lib/ferret/index/segment_infos.rb +0 -130
  145. data/lib/ferret/index/segment_merge_info.rb +0 -49
  146. data/lib/ferret/index/segment_merge_queue.rb +0 -16
  147. data/lib/ferret/index/segment_merger.rb +0 -358
  148. data/lib/ferret/index/segment_reader.rb +0 -412
  149. data/lib/ferret/index/segment_term_enum.rb +0 -169
  150. data/lib/ferret/index/segment_term_vector.rb +0 -58
  151. data/lib/ferret/index/term.rb +0 -53
  152. data/lib/ferret/index/term_buffer.rb +0 -83
  153. data/lib/ferret/index/term_doc_enum.rb +0 -291
  154. data/lib/ferret/index/term_enum.rb +0 -52
  155. data/lib/ferret/index/term_info.rb +0 -37
  156. data/lib/ferret/index/term_infos_io.rb +0 -321
  157. data/lib/ferret/index/term_vector_offset_info.rb +0 -20
  158. data/lib/ferret/index/term_vectors_io.rb +0 -553
  159. data/lib/ferret/query_parser.rb +0 -312
  160. data/lib/ferret/query_parser/query_parser.tab.rb +0 -928
  161. data/lib/ferret/search.rb +0 -50
  162. data/lib/ferret/search/boolean_clause.rb +0 -100
  163. data/lib/ferret/search/boolean_query.rb +0 -299
  164. data/lib/ferret/search/boolean_scorer.rb +0 -294
  165. data/lib/ferret/search/caching_wrapper_filter.rb +0 -40
  166. data/lib/ferret/search/conjunction_scorer.rb +0 -99
  167. data/lib/ferret/search/disjunction_sum_scorer.rb +0 -205
  168. data/lib/ferret/search/exact_phrase_scorer.rb +0 -32
  169. data/lib/ferret/search/explanation.rb +0 -41
  170. data/lib/ferret/search/field_cache.rb +0 -215
  171. data/lib/ferret/search/field_doc.rb +0 -31
  172. data/lib/ferret/search/field_sorted_hit_queue.rb +0 -184
  173. data/lib/ferret/search/filter.rb +0 -11
  174. data/lib/ferret/search/filtered_query.rb +0 -130
  175. data/lib/ferret/search/filtered_term_enum.rb +0 -79
  176. data/lib/ferret/search/fuzzy_query.rb +0 -154
  177. data/lib/ferret/search/fuzzy_term_enum.rb +0 -247
  178. data/lib/ferret/search/hit_collector.rb +0 -34
  179. data/lib/ferret/search/hit_queue.rb +0 -11
  180. data/lib/ferret/search/index_searcher.rb +0 -200
  181. data/lib/ferret/search/match_all_query.rb +0 -104
  182. data/lib/ferret/search/multi_phrase_query.rb +0 -216
  183. data/lib/ferret/search/multi_searcher.rb +0 -261
  184. data/lib/ferret/search/multi_term_query.rb +0 -65
  185. data/lib/ferret/search/non_matching_scorer.rb +0 -22
  186. data/lib/ferret/search/phrase_positions.rb +0 -55
  187. data/lib/ferret/search/phrase_query.rb +0 -214
  188. data/lib/ferret/search/phrase_scorer.rb +0 -152
  189. data/lib/ferret/search/prefix_query.rb +0 -54
  190. data/lib/ferret/search/query.rb +0 -140
  191. data/lib/ferret/search/query_filter.rb +0 -51
  192. data/lib/ferret/search/range_filter.rb +0 -103
  193. data/lib/ferret/search/range_query.rb +0 -139
  194. data/lib/ferret/search/req_excl_scorer.rb +0 -125
  195. data/lib/ferret/search/req_opt_sum_scorer.rb +0 -70
  196. data/lib/ferret/search/score_doc.rb +0 -38
  197. data/lib/ferret/search/score_doc_comparator.rb +0 -114
  198. data/lib/ferret/search/scorer.rb +0 -91
  199. data/lib/ferret/search/similarity.rb +0 -278
  200. data/lib/ferret/search/sloppy_phrase_scorer.rb +0 -47
  201. data/lib/ferret/search/sort.rb +0 -112
  202. data/lib/ferret/search/sort_comparator.rb +0 -60
  203. data/lib/ferret/search/sort_field.rb +0 -91
  204. data/lib/ferret/search/spans.rb +0 -12
  205. data/lib/ferret/search/spans/near_spans_enum.rb +0 -304
  206. data/lib/ferret/search/spans/span_first_query.rb +0 -79
  207. data/lib/ferret/search/spans/span_near_query.rb +0 -108
  208. data/lib/ferret/search/spans/span_not_query.rb +0 -130
  209. data/lib/ferret/search/spans/span_or_query.rb +0 -176
  210. data/lib/ferret/search/spans/span_query.rb +0 -25
  211. data/lib/ferret/search/spans/span_scorer.rb +0 -74
  212. data/lib/ferret/search/spans/span_term_query.rb +0 -105
  213. data/lib/ferret/search/spans/span_weight.rb +0 -84
  214. data/lib/ferret/search/spans/spans_enum.rb +0 -44
  215. data/lib/ferret/search/term_query.rb +0 -128
  216. data/lib/ferret/search/term_scorer.rb +0 -183
  217. data/lib/ferret/search/top_docs.rb +0 -36
  218. data/lib/ferret/search/top_field_docs.rb +0 -17
  219. data/lib/ferret/search/weight.rb +0 -54
  220. data/lib/ferret/search/wildcard_query.rb +0 -26
  221. data/lib/ferret/search/wildcard_term_enum.rb +0 -61
  222. data/lib/ferret/stemmers.rb +0 -1
  223. data/lib/ferret/stemmers/porter_stemmer.rb +0 -218
  224. data/lib/ferret/store.rb +0 -5
  225. data/lib/ferret/store/buffered_index_io.rb +0 -190
  226. data/lib/ferret/store/directory.rb +0 -141
  227. data/lib/ferret/store/fs_store.rb +0 -381
  228. data/lib/ferret/store/index_io.rb +0 -245
  229. data/lib/ferret/store/ram_store.rb +0 -286
  230. data/lib/ferret/utils.rb +0 -8
  231. data/lib/ferret/utils/bit_vector.rb +0 -123
  232. data/lib/ferret/utils/date_tools.rb +0 -138
  233. data/lib/ferret/utils/number_tools.rb +0 -91
  234. data/lib/ferret/utils/parameter.rb +0 -41
  235. data/lib/ferret/utils/priority_queue.rb +0 -120
  236. data/lib/ferret/utils/string_helper.rb +0 -47
  237. data/lib/ferret/utils/thread_local.rb +0 -28
  238. data/lib/ferret/utils/weak_key_hash.rb +0 -60
  239. data/lib/rferret.rb +0 -37
  240. data/rake_utils/code_statistics.rb +0 -106
  241. data/test/benchmark/tb_ram_store.rb +0 -76
  242. data/test/benchmark/tb_rw_vint.rb +0 -26
  243. data/test/functional/thread_safety_index_test.rb +0 -81
  244. data/test/functional/thread_safety_test.rb +0 -137
  245. data/test/longrunning/tc_numbertools.rb +0 -60
  246. data/test/longrunning/tm_store.rb +0 -19
  247. data/test/unit/analysis/ctc_analyzer.rb +0 -532
  248. data/test/unit/analysis/data/wordfile +0 -6
  249. data/test/unit/analysis/rtc_letter_tokenizer.rb +0 -20
  250. data/test/unit/analysis/rtc_lower_case_filter.rb +0 -20
  251. data/test/unit/analysis/rtc_lower_case_tokenizer.rb +0 -27
  252. data/test/unit/analysis/rtc_per_field_analyzer_wrapper.rb +0 -39
  253. data/test/unit/analysis/rtc_porter_stem_filter.rb +0 -16
  254. data/test/unit/analysis/rtc_standard_analyzer.rb +0 -20
  255. data/test/unit/analysis/rtc_standard_tokenizer.rb +0 -20
  256. data/test/unit/analysis/rtc_stop_analyzer.rb +0 -20
  257. data/test/unit/analysis/rtc_stop_filter.rb +0 -14
  258. data/test/unit/analysis/rtc_white_space_analyzer.rb +0 -21
  259. data/test/unit/analysis/rtc_white_space_tokenizer.rb +0 -20
  260. data/test/unit/analysis/rtc_word_list_loader.rb +0 -32
  261. data/test/unit/analysis/tc_token.rb +0 -25
  262. data/test/unit/document/rtc_field.rb +0 -28
  263. data/test/unit/document/tc_document.rb +0 -47
  264. data/test/unit/document/tc_field.rb +0 -98
  265. data/test/unit/index/rtc_compound_file_io.rb +0 -107
  266. data/test/unit/index/rtc_field_infos.rb +0 -127
  267. data/test/unit/index/rtc_fields_io.rb +0 -167
  268. data/test/unit/index/rtc_multiple_term_doc_pos_enum.rb +0 -83
  269. data/test/unit/index/rtc_segment_infos.rb +0 -74
  270. data/test/unit/index/rtc_segment_term_docs.rb +0 -17
  271. data/test/unit/index/rtc_segment_term_enum.rb +0 -60
  272. data/test/unit/index/rtc_segment_term_vector.rb +0 -71
  273. data/test/unit/index/rtc_term_buffer.rb +0 -57
  274. data/test/unit/index/rtc_term_info.rb +0 -19
  275. data/test/unit/index/rtc_term_infos_io.rb +0 -192
  276. data/test/unit/index/rtc_term_vectors_io.rb +0 -108
  277. data/test/unit/index/tc_term.rb +0 -27
  278. data/test/unit/index/tc_term_voi.rb +0 -18
  279. data/test/unit/search/rtc_similarity.rb +0 -37
  280. data/test/unit/search/rtc_sort_field.rb +0 -14
  281. data/test/unit/search/tc_multi_searcher2.rb +0 -126
  282. data/test/unit/store/rtc_fs_store.rb +0 -62
  283. data/test/unit/store/rtc_ram_store.rb +0 -15
  284. data/test/unit/store/rtm_store.rb +0 -150
  285. data/test/unit/store/rtm_store_lock.rb +0 -2
  286. data/test/unit/ts_document.rb +0 -2
  287. data/test/unit/utils/rtc_bit_vector.rb +0 -73
  288. data/test/unit/utils/rtc_date_tools.rb +0 -50
  289. data/test/unit/utils/rtc_number_tools.rb +0 -59
  290. data/test/unit/utils/rtc_parameter.rb +0 -40
  291. data/test/unit/utils/rtc_priority_queue.rb +0 -62
  292. data/test/unit/utils/rtc_string_helper.rb +0 -21
  293. data/test/unit/utils/rtc_thread.rb +0 -61
  294. data/test/unit/utils/rtc_weak_key_hash.rb +0 -25
  295. data/test/utils/number_to_spoken.rb +0 -132
@@ -1,9 +1,11 @@
1
1
  require File.dirname(__FILE__) + "/../../test_helper"
2
2
 
3
3
  class QueryParserTest < Test::Unit::TestCase
4
+ include Ferret::Analysis
4
5
 
5
6
  def test_strings()
6
- parser = Ferret::QueryParser.new("xxx", :fields => ["xxx", "field", "f1", "f2"])
7
+ parser = Ferret::QueryParser.new(:default_field => "xxx",
8
+ :fields => ["xxx", "field", "f1", "f2"])
7
9
  pairs = [
8
10
  ['', ''],
9
11
  ['*:word', 'word field:word f1:word f2:word'],
@@ -101,8 +103,9 @@ class QueryParserTest < Test::Unit::TestCase
101
103
  end
102
104
 
103
105
  def test_qp_with_standard_analyzer()
104
- parser = Ferret::QueryParser.new("xxx", :fields => ["xxx", "key"],
105
- :analyzer => Ferret::Analysis::StandardAnalyzer.new)
106
+ parser = Ferret::QueryParser.new(:default_field => "xxx",
107
+ :fields => ["xxx", "key"],
108
+ :analyzer => StandardAnalyzer.new)
106
109
  pairs = [
107
110
  ['key:1234', 'key:1234'],
108
111
  ['key:(1234 and Dave)', 'key:1234 key:dave'],
@@ -116,48 +119,51 @@ class QueryParserTest < Test::Unit::TestCase
116
119
 
117
120
  end
118
121
 
119
- if not $ferret_pure_ruby
120
- def test_qp_changing_fields()
121
- parser = Ferret::QueryParser.new("xxx", :fields => ["xxx", "key"],
122
- :analyzer => Ferret::Analysis::WhiteSpaceAnalyzer.new)
123
- assert_equal('word key:word', parser.parse("*:word").to_s("xxx"))
124
-
125
- parser.fields = ["xxx", "one", "two", "three"]
126
- assert_equal('word one:word two:word three:word',
127
- parser.parse("*:word").to_s("xxx"))
128
- assert_equal('three:word four:word',
129
- parser.parse("three:word four:word").to_s("xxx"))
130
- end
122
+ def test_qp_changing_fields()
123
+ parser = Ferret::QueryParser.new(:default_field => "xxx",
124
+ :fields => ["xxx", "key"],
125
+ :analyzer => WhiteSpaceAnalyzer.new)
126
+ assert_equal('word key:word', parser.parse("*:word").to_s("xxx"))
127
+
128
+ parser.fields = ["xxx", "one", "two", "three"]
129
+ assert_equal('word one:word two:word three:word',
130
+ parser.parse("*:word").to_s("xxx"))
131
+ assert_equal('three:word four:word',
132
+ parser.parse("three:word four:word").to_s("xxx"))
133
+ end
131
134
 
132
- def test_qp_allow_any_field()
133
- parser = Ferret::QueryParser.new("xxx", :fields => ["xxx", "key"],
134
- :analyzer => Ferret::Analysis::WhiteSpaceAnalyzer.new,
135
- :allow_any_fields => false)
135
+ def test_qp_allow_any_field()
136
+ parser = Ferret::QueryParser.new(:default_field => "xxx",
137
+ :fields => ["xxx", "key"],
138
+ :analyzer => WhiteSpaceAnalyzer.new,
139
+ :validate_fields => true)
136
140
 
137
- assert_equal('key:word',
138
- parser.parse("key:word song:word").to_s("xxx"))
139
- assert_equal('word key:word', parser.parse("*:word").to_s("xxx"))
141
+ assert_equal('key:word',
142
+ parser.parse("key:word song:word").to_s("xxx"))
143
+ assert_equal('word key:word', parser.parse("*:word").to_s("xxx"))
140
144
 
141
145
 
142
- parser = Ferret::QueryParser.new("xxx", :fields => ["xxx", "key"],
143
- :analyzer => Ferret::Analysis::WhiteSpaceAnalyzer.new)
146
+ parser = Ferret::QueryParser.new(:default_field => "xxx",
147
+ :fields => ["xxx", "key"],
148
+ :analyzer => WhiteSpaceAnalyzer.new)
144
149
 
145
- assert_equal('key:word song:word',
146
- parser.parse("key:word song:word").to_s("xxx"))
147
- assert_equal('word key:word song:word', parser.parse("*:word").to_s("xxx"))
148
- end
150
+ assert_equal('key:word song:word',
151
+ parser.parse("key:word song:word").to_s("xxx"))
152
+ assert_equal('word key:word', parser.parse("*:word").to_s("xxx"))
149
153
  end
150
154
 
151
155
  def do_test_query_parse_exception_raised(str)
152
- parser = Ferret::QueryParser.new("xxx", :fields => ["f1", "f2", "f3"])
156
+ parser = Ferret::QueryParser.new(:default_field => "xxx",
157
+ :fields => ["f1", "f2", "f3"])
153
158
  assert_raise(Ferret::QueryParser::QueryParseException) do
154
159
  parser.parse(str)
155
160
  end
156
161
  end
157
162
 
158
163
  def test_prefix_query
159
- parser = Ferret::QueryParser.new("xxx", :fields => ["xxx"],
160
- :analyzer => Ferret::Analysis::StandardAnalyzer.new)
164
+ parser = Ferret::QueryParser.new(:default_field => "xxx",
165
+ :fields => ["xxx"],
166
+ :analyzer => StandardAnalyzer.new)
161
167
  assert_equal(Ferret::Search::PrefixQuery, parser.parse("asdg*").class)
162
168
  assert_equal(Ferret::Search::WildcardQuery, parser.parse("a?dg*").class)
163
169
  assert_equal(Ferret::Search::WildcardQuery, parser.parse("a*dg*").class)
@@ -165,8 +171,9 @@ class QueryParserTest < Test::Unit::TestCase
165
171
  end
166
172
 
167
173
  def test_bad_queries
168
- parser = Ferret::QueryParser.new("xxx", :fields => ["f1", "f2"],
169
- :handle_parse_errors => true)
174
+ parser = Ferret::QueryParser.new(:default_field => "xxx",
175
+ :fields => ["f1", "f2"],
176
+ :handle_parse_errors => true)
170
177
 
171
178
  pairs = [
172
179
  ['::*word', 'word'],
@@ -2,37 +2,27 @@ require File.dirname(__FILE__) + "/../../test_helper"
2
2
 
3
3
 
4
4
  class FilterTest < Test::Unit::TestCase
5
- include Ferret::Document
6
5
  include Ferret::Search
7
6
  include Ferret::Analysis
8
7
  include Ferret::Index
9
8
 
10
- def add_doc(hash, writer)
11
- doc = Document.new()
12
- hash.each_pair do |field, text|
13
- doc << Field.new(field, text, Field::Store::NO, Field::Index::UNTOKENIZED)
14
- end
15
- writer << doc
16
- end
17
-
18
9
  def setup()
19
10
  @dir = Ferret::Store::RAMDirectory.new()
20
- iw = IndexWriter.new(@dir,
11
+ iw = IndexWriter.new(:dir => @dir,
21
12
  :analyzer => WhiteSpaceAnalyzer.new(),
22
13
  :create => true)
23
- docs = [
24
- {"int"=>"0","date"=>"20040601","switch"=>"on"},
25
- {"int"=>"1","date"=>"20041001","switch"=>"off"},
26
- {"int"=>"2","date"=>"20051101","switch"=>"on"},
27
- {"int"=>"3","date"=>"20041201","switch"=>"off"},
28
- {"int"=>"4","date"=>"20051101","switch"=>"on"},
29
- {"int"=>"5","date"=>"20041201","switch"=>"off"},
30
- {"int"=>"6","date"=>"20050101","switch"=>"on"},
31
- {"int"=>"7","date"=>"20040701","switch"=>"off"},
32
- {"int"=>"8","date"=>"20050301","switch"=>"on"},
33
- {"int"=>"9","date"=>"20050401","switch"=>"off"}
34
- ]
35
- docs.each {|doc| add_doc(doc, iw)}
14
+ [
15
+ {:int => "0", :date => "20040601", :switch => "on"},
16
+ {:int => "1", :date => "20041001", :switch => "off"},
17
+ {:int => "2", :date => "20051101", :switch => "on"},
18
+ {:int => "3", :date => "20041201", :switch => "off"},
19
+ {:int => "4", :date => "20051101", :switch => "on"},
20
+ {:int => "5", :date => "20041201", :switch => "off"},
21
+ {:int => "6", :date => "20050101", :switch => "on"},
22
+ {:int => "7", :date => "20040701", :switch => "off"},
23
+ {:int => "8", :date => "20050301", :switch => "on"},
24
+ {:int => "9", :date => "20050401", :switch => "off"}
25
+ ].each {|doc| iw << doc}
36
26
  iw.close
37
27
  end
38
28
 
@@ -40,74 +30,72 @@ class FilterTest < Test::Unit::TestCase
40
30
  @dir.close()
41
31
  end
42
32
 
43
- def do_test_top_docs(is, query, expected, filter)
44
- top_docs = is.search(query, {:filter => filter})
33
+ def do_test_top_docs(searcher, query, expected, filter)
34
+ top_docs = searcher.search(query, {:filter => filter})
45
35
  #puts top_docs
46
- assert_equal(expected.size, top_docs.score_docs.size)
36
+ assert_equal(expected.size, top_docs.hits.size)
47
37
  top_docs.total_hits.times do |i|
48
- assert_equal(expected[i], top_docs.score_docs[i].doc)
38
+ assert_equal(expected[i], top_docs.hits[i].doc)
39
+ end
40
+ end
41
+
42
+ def test_filter_proc
43
+ searcher = Searcher.new(@dir)
44
+ q = MatchAllQuery.new()
45
+ filter_proc = lambda {|doc, score, s| (s[doc][:int] % 2) == 0}
46
+ top_docs = searcher.search(q, :filter_proc => filter_proc)
47
+ top_docs.hits.each do |hit|
48
+ assert_equal(0, searcher[hit.doc][:int] % 2)
49
49
  end
50
50
  end
51
51
 
52
52
  def test_range_filter
53
- is = IndexSearcher.new(@dir)
53
+ searcher = Searcher.new(@dir)
54
54
  q = MatchAllQuery.new()
55
- rf = RangeFilter.new("int", "2", "6", true, true)
56
- do_test_top_docs(is, q, [2,3,4,5,6], rf)
57
- rf = RangeFilter.new("int", "2", "6", true, false)
58
- do_test_top_docs(is, q, [2,3,4,5], rf)
59
- rf = RangeFilter.new("int", "2", "6", false, true)
60
- do_test_top_docs(is, q, [3,4,5,6], rf)
61
- rf = RangeFilter.new("int", "2", "6", false, false)
62
- do_test_top_docs(is, q, [3,4,5], rf)
63
- rf = RangeFilter.new_more("int", "6")
64
- do_test_top_docs(is, q, [6,7,8,9], rf)
65
- rf = RangeFilter.new_more("int", "6", false)
66
- do_test_top_docs(is, q, [7,8,9], rf)
67
- rf = RangeFilter.new_less("int", "2")
68
- do_test_top_docs(is, q, [0,1,2], rf)
69
- rf = RangeFilter.new_less("int", "2", false)
70
- do_test_top_docs(is, q, [0,1], rf)
55
+ rf = RangeFilter.new(:int, :>= => "2", :<= => "6")
56
+ do_test_top_docs(searcher, q, [2,3,4,5,6], rf)
57
+ rf = RangeFilter.new(:int, :>= => "2", :< => "6")
58
+ do_test_top_docs(searcher, q, [2,3,4,5], rf)
59
+ rf = RangeFilter.new(:int, :> => "2", :<= => "6")
60
+ do_test_top_docs(searcher, q, [3,4,5,6], rf)
61
+ rf = RangeFilter.new(:int, :> => "2", :< => "6")
62
+ do_test_top_docs(searcher, q, [3,4,5], rf)
63
+ rf = RangeFilter.new(:int, :>= => "6")
64
+ do_test_top_docs(searcher, q, [6,7,8,9], rf)
65
+ rf = RangeFilter.new(:int, :> => "6")
66
+ do_test_top_docs(searcher, q, [7,8,9], rf)
67
+ rf = RangeFilter.new(:int, :<= => "2")
68
+ do_test_top_docs(searcher, q, [0,1,2], rf)
69
+ rf = RangeFilter.new(:int, :< => "2")
70
+ do_test_top_docs(searcher, q, [0,1], rf)
71
71
  end
72
72
 
73
73
  def test_range_filter_errors
74
- assert_raise(ArgumentError) {f = RangeFilter.new("", "asd", nil, false, true)}
75
- assert_raise(ArgumentError) {f = RangeFilter.new("", nil, "asd", true, false)}
76
- assert_raise(ArgumentError) {f = RangeFilter.new("", "ac", "ab", false, false)}
77
- assert_raise(ArgumentError) {f = RangeFilter.new("", nil, nil, false, false)}
74
+ assert_raise(ArgumentError) {f = RangeFilter.new(:f, :> => "b", :< => "a")}
75
+ assert_raise(ArgumentError) {f = RangeFilter.new(:f, :include_lower => true)}
76
+ assert_raise(ArgumentError) {f = RangeFilter.new(:f, :include_upper => true)}
78
77
  end
79
78
 
80
79
  def test_query_filter()
81
- is = IndexSearcher.new(@dir)
80
+ searcher = Searcher.new(@dir)
82
81
  q = MatchAllQuery.new()
83
- qf = QueryFilter.new(TermQuery.new(Term.new("switch", "on")))
84
- do_test_top_docs(is, q, [0,2,4,6,8], qf)
82
+ qf = QueryFilter.new(TermQuery.new(:switch, "on"))
83
+ do_test_top_docs(searcher, q, [0,2,4,6,8], qf)
85
84
  # test again to test caching doesn't break it
86
- do_test_top_docs(is, q, [0,2,4,6,8], qf)
87
- qf = QueryFilter.new(TermQuery.new(Term.new("switch", "off")))
88
- do_test_top_docs(is, q, [1,3,5,7,9], qf)
85
+ do_test_top_docs(searcher, q, [0,2,4,6,8], qf)
86
+ qf = QueryFilter.new(TermQuery.new(:switch, "off"))
87
+ do_test_top_docs(searcher, q, [1,3,5,7,9], qf)
89
88
  end
90
89
 
91
90
  def test_filtered_query
92
- is = IndexSearcher.new(@dir)
91
+ searcher = Searcher.new(@dir)
93
92
  q = MatchAllQuery.new()
94
- rf = RangeFilter.new("int", "2", "6", true, true)
93
+ rf = RangeFilter.new(:int, :>= => "2", :<= => "6")
95
94
  rq = FilteredQuery.new(q, rf)
96
- qf = QueryFilter.new(TermQuery.new(Term.new("switch", "on")))
97
- do_test_top_docs(is, rq, [2,4,6], qf)
95
+ qf = QueryFilter.new(TermQuery.new(:switch, "on"))
96
+ do_test_top_docs(searcher, rq, [2,4,6], qf)
98
97
  query = FilteredQuery.new(rq, qf)
99
- rf2 = RangeFilter.new_more("int", "3")
100
- do_test_top_docs(is, query, [4,6], rf2)
98
+ rf2 = RangeFilter.new(:int, :>= => "3")
99
+ do_test_top_docs(searcher, query, [4,6], rf2)
101
100
  end
102
- #def test_filtered_query
103
- # is = IndexSearcher.new(@dir)
104
- # q = MatchAllQuery.new()
105
- # rf = RangeFilter.new("int", "2", "6", true, true)
106
- # rq = FilteredQuery.new(q, rf)
107
- # qf = QueryFilter.new(TermQuery.new(Term.new("switch", "on")))
108
- # do_test_top_docs(is, rq, [2,4,6], qf)
109
- # query = FilteredQuery.new(rq, qf)
110
- # rf2 = RangeFilter.new_more("int", "3")
111
- # do_test_top_docs(is, query, [4,6], rf2)
112
- #end
113
101
  end
@@ -1,16 +1,13 @@
1
1
  require File.dirname(__FILE__) + "/../../test_helper"
2
2
 
3
3
  class FuzzyQueryTest < Test::Unit::TestCase
4
- include Ferret::Document
5
4
  include Ferret::Search
6
5
  include Ferret::Store
7
6
  include Ferret::Analysis
8
7
  include Ferret::Index
9
8
 
10
9
  def add_doc(text, writer)
11
- doc = Document.new()
12
- doc << Field.new("field", text, Field::Store::NO, Field::Index::TOKENIZED)
13
- writer << doc
10
+ writer << {:field => text}
14
11
  end
15
12
 
16
13
  def setup()
@@ -25,21 +22,23 @@ class FuzzyQueryTest < Test::Unit::TestCase
25
22
  top_docs = is.search(query)
26
23
  assert_equal(expected.length, top_docs.total_hits,
27
24
  "expected #{expected.length} hits but got #{top_docs.total_hits}")
28
- assert_equal(expected.length, top_docs.score_docs.size)
25
+ assert_equal(expected.length, top_docs.hits.size)
29
26
  top_docs.total_hits.times do |i|
30
- assert_equal(expected[i], top_docs.score_docs[i].doc)
27
+ assert_equal(expected[i], top_docs.hits[i].doc)
31
28
  end
32
29
  end
33
30
 
34
31
  def do_prefix_test(is, text, prefix, expected)
35
- fq = FuzzyQuery.new(Term.new("field", text), FuzzyQuery.default_min_similarity, prefix)
32
+ fq = FuzzyQuery.new(:field, text, :prefix_length => prefix)
36
33
  #puts is.explain(fq, 0)
37
34
  #puts is.explain(fq, 1)
38
35
  do_test_top_docs(is, fq, expected)
39
36
  end
40
37
 
41
38
  def test_fuzziness()
42
- iw = IndexWriter.new(@dir, :analyzer => WhiteSpaceAnalyzer.new(), :create => true)
39
+ iw = IndexWriter.new(:dir => @dir,
40
+ :analyzer => WhiteSpaceAnalyzer.new(),
41
+ :create => true)
43
42
  add_doc("aaaaa", iw)
44
43
  add_doc("aaaab", iw)
45
44
  add_doc("aaabb", iw)
@@ -53,9 +52,9 @@ class FuzzyQueryTest < Test::Unit::TestCase
53
52
  iw.close()
54
53
 
55
54
 
56
- is = IndexSearcher.new(@dir)
55
+ is = Searcher.new(@dir)
57
56
 
58
- fq = FuzzyQuery.new(Term.new("field", "aaaaa"), FuzzyQuery.default_min_similarity, 5)
57
+ fq = FuzzyQuery.new(:field, "aaaaa", :prefix_length => 5)
59
58
 
60
59
  do_prefix_test(is, "aaaaaaaaaaaaaaaaaaaaaa", 1, [8])
61
60
  do_prefix_test(is, "aaaaa", 0, [0,1,2])
@@ -84,7 +83,7 @@ class FuzzyQueryTest < Test::Unit::TestCase
84
83
  do_prefix_test(is, "ddddX", 4, [6])
85
84
  do_prefix_test(is, "ddddX", 5, [])
86
85
 
87
- fq = FuzzyQuery.new(Term.new("anotherfield", "ddddX"), FuzzyQuery.default_min_similarity, 0)
86
+ fq = FuzzyQuery.new(:anotherfield, "ddddX", :prefix_length => 0)
88
87
  top_docs = is.search(fq)
89
88
  assert_equal(0, top_docs.total_hits)
90
89
 
@@ -92,12 +91,14 @@ class FuzzyQueryTest < Test::Unit::TestCase
92
91
  end
93
92
 
94
93
  def test_fuzziness_long()
95
- iw = IndexWriter.new(@dir, :analyzer => WhiteSpaceAnalyzer.new(), :create => true)
94
+ iw = IndexWriter.new(:dir => @dir,
95
+ :analyzer => WhiteSpaceAnalyzer.new(),
96
+ :create => true)
96
97
  add_doc("aaaaaaa", iw)
97
98
  add_doc("segment", iw)
98
99
  iw.optimize()
99
100
  iw.close()
100
- is = IndexSearcher.new(@dir)
101
+ is = Searcher.new(@dir)
101
102
 
102
103
  # not similar enough:
103
104
  do_prefix_test(is, "xxxxx", 0, [])
@@ -126,12 +127,19 @@ class FuzzyQueryTest < Test::Unit::TestCase
126
127
  do_prefix_test(is, "stellent", 2, [])
127
128
 
128
129
  # "student" doesn't match anymore thanks to increased minimum similarity:
129
- fq = FuzzyQuery.new(Term.new("field", "student"), 0.6, 0)
130
+ fq = FuzzyQuery.new(:field, "student",
131
+ :min_similarity => 0.6,
132
+ :prefix_length => 0)
133
+
130
134
  top_docs = is.search(fq)
131
135
  assert_equal(0, top_docs.total_hits)
132
136
 
133
- assert_raise(ArgumentError) {fq = FuzzyQuery.new(Term.new("f", "s"), 1.1)}
134
- assert_raise(ArgumentError) {fq = FuzzyQuery.new(Term.new("f", "s"), -0.1)}
137
+ assert_raise(ArgumentError) do
138
+ fq = FuzzyQuery.new(:f, "s", :min_similarity => 1.1)
139
+ end
140
+ assert_raise(ArgumentError) do
141
+ fq = FuzzyQuery.new(:f, "s", :min_similarity => -0.1)
142
+ end
135
143
 
136
144
  is.close()
137
145
  end
@@ -1,237 +1,59 @@
1
1
  require File.dirname(__FILE__) + "/../../test_helper"
2
+ require File.dirname(__FILE__) + "/tm_searcher"
2
3
 
3
- class IndexSearcherTest < Test::Unit::TestCase
4
- include Ferret::Document
4
+ class SearcherTest < Test::Unit::TestCase
5
5
  include Ferret::Search
6
6
  include Ferret::Store
7
7
  include Ferret::Analysis
8
8
  include Ferret::Index
9
9
 
10
+ include SearcherTests
11
+
10
12
  def setup()
11
13
  @dir = RAMDirectory.new()
12
- iw = IndexWriter.new(@dir, :analyzer => WhiteSpaceAnalyzer.new(), :create => true)
13
- @documents = IndexTestHelper.prepare_search_docs()
14
+ iw = IndexWriter.new(:dir => @dir,
15
+ :analyzer => WhiteSpaceAnalyzer.new(),
16
+ :create => true)
17
+ @documents = IndexTestHelper::SEARCH_TEST_DOCS
14
18
  @documents.each { |doc| iw << doc }
15
19
  iw.close()
16
- @is = IndexSearcher.new(@dir)
20
+ @searcher = Searcher.new(@dir)
17
21
  end
18
22
 
19
23
  def tear_down()
20
- @is.close
24
+ @searcher.close
21
25
  @dir.close()
22
26
  end
23
27
 
24
- def get_docs(score_docs)
28
+ def get_docs(hits)
25
29
  docs = []
26
- score_docs.each do |score_doc|
27
- docs << score_doc.doc
30
+ hits.each do |hit|
31
+ docs << hit.doc
28
32
  end
29
33
  docs
30
34
  end
31
35
 
32
36
  def check_hits(query, expected, top=nil, total_hits=nil)
33
- top_docs = @is.search(query)
34
- assert_equal(expected.length, top_docs.score_docs.size)
35
- assert_equal(top, top_docs.score_docs[0].doc) if top
37
+ top_docs = @searcher.search(query)
38
+ assert_equal(expected.length, top_docs.hits.size)
39
+ assert_equal(top, top_docs.hits[0].doc) if top
36
40
  if total_hits
37
41
  assert_equal(total_hits, top_docs.total_hits)
38
42
  else
39
43
  assert_equal(expected.length, top_docs.total_hits)
40
44
  end
41
- top_docs.score_docs.each do |score_doc|
45
+ top_docs.hits.each do |score_doc|
42
46
  assert(expected.include?(score_doc.doc),
43
47
  "#{score_doc.doc} was found unexpectedly")
44
- assert(score_doc.score =~ @is.explain(query, score_doc.doc).value,
45
- "Scores(#{score_doc.score} != #{@is.explain(query, score_doc.doc).value})")
46
- end
47
- end
48
-
49
- def check_docs(query, options, expected=[])
50
- top_docs = @is.search(query, options)
51
- docs = top_docs.score_docs
52
- assert_equal(expected.length, docs.length)
53
- docs.length.times do |i|
54
- assert_equal(expected[i], docs[i].doc)
48
+ assert(score_doc.score =~ @searcher.explain(query, score_doc.doc).score,
49
+ "Scores(#{score_doc.score} != #{@searcher.explain(query, score_doc.doc).score})")
55
50
  end
56
51
  end
57
52
 
58
53
  def test_get_doc()
59
- assert_equal(18, @is.max_doc)
60
- assert_equal("20050930", @is.doc(0).values(:date))
61
- assert_equal("cat1/sub2/subsub2", @is.doc(4)[:cat])
62
- assert_equal("20051012", @is.doc(12)[:date])
63
- end
64
-
65
- def test_term_query
66
- tq = TermQuery.new(Term.new("field", "word2"))
67
- tq.boost = 100
68
- check_hits(tq, [1,4,8])
69
- #puts @is.explain(tq, 1)
70
- #puts @is.explain(tq, 4)
71
- #puts @is.explain(tq, 8)
72
-
73
- tq = TermQuery.new(Term.new("field", "2342"))
74
- check_hits(tq, [])
75
-
76
- tq = TermQuery.new(Term.new("field", ""))
77
- check_hits(tq, [])
78
-
79
- tq = TermQuery.new(Term.new("field", "word1"))
80
- top_docs = @is.search(tq)
81
- assert_equal(@documents.size, top_docs.total_hits)
82
- assert_equal(10, top_docs.score_docs.size)
83
- top_docs = @is.search(tq, {:num_docs => 20})
84
- assert_equal(@documents.size, top_docs.score_docs.size)
85
- end
86
-
87
-
88
- def test_first_doc
89
- tq = TermQuery.new(Term.new("field", "word1"))
90
- tq.boost = 100
91
- top_docs = @is.search(tq, {:num_docs => 100})
92
- expected = []
93
- top_docs.score_docs.each do |sd|
94
- expected << sd.doc
95
- end
96
-
97
- assert_raise(ArgumentError) { @is.search(tq, {:first_doc => -1}) }
98
- assert_raise(ArgumentError) { @is.search(tq, {:num_docs => 0}) }
99
- assert_raise(ArgumentError) { @is.search(tq, {:num_docs => -1}) }
100
-
101
- check_docs(tq, {:num_docs => 8, :first_doc => 0}, expected[0,8])
102
- check_docs(tq, {:num_docs => 3, :first_doc => 1}, expected[1,3])
103
- check_docs(tq, {:num_docs => 6, :first_doc => 2}, expected[2,6])
104
- check_docs(tq, {:num_docs => 2, :first_doc => expected.length}, [])
105
- check_docs(tq, {:num_docs => 2, :first_doc => expected.length + 100}, [])
106
- end
107
-
108
- def test_boolean_query
109
- bq = BooleanQuery.new()
110
- tq1 = TermQuery.new(Term.new("field", "word1"))
111
- tq2 = TermQuery.new(Term.new("field", "word3"))
112
- bq.add_query(tq1, BooleanClause::Occur::MUST)
113
- bq.add_query(tq2, BooleanClause::Occur::MUST)
114
- check_hits(bq, [2,3,6,8,11,14], 14)
115
-
116
- tq3 = TermQuery.new(Term.new("field", "word2"))
117
- bq.add_query(tq3, BooleanClause::Occur::SHOULD)
118
- check_hits(bq, [2,3,6,8,11,14], 8)
119
-
120
- bq = BooleanQuery.new()
121
- bq.add_query(tq2, BooleanClause::Occur::MUST)
122
- bq.add_query(tq3, BooleanClause::Occur::MUST_NOT)
123
- check_hits(bq, [2,3,6,11,14])
124
-
125
- bq = BooleanQuery.new()
126
- bq.add_query(tq2, BooleanClause::Occur::MUST_NOT)
127
- check_hits(bq, [])
128
-
129
- bq = BooleanQuery.new()
130
- bq.add_query(tq2, BooleanClause::Occur::SHOULD)
131
- bq.add_query(tq3, BooleanClause::Occur::SHOULD)
132
- check_hits(bq, [1,2,3,4,6,8,11,14])
133
-
134
- bq = BooleanQuery.new()
135
- bc1 = BooleanClause.new(tq2, BooleanClause::Occur::SHOULD)
136
- bc2 = BooleanClause.new(tq3, BooleanClause::Occur::SHOULD)
137
- bq.add_clause(bc1)
138
- bq.add_clause(bc2)
139
- check_hits(bq, [1,2,3,4,6,8,11,14])
140
- end
141
-
142
- def test_phrase_query()
143
- pq = PhraseQuery.new()
144
- t1 = Term.new("field", "quick")
145
- t2 = Term.new("field", "brown")
146
- t3 = Term.new("field", "fox")
147
- pq << t1 << t2 << t3
148
- check_hits(pq, [1])
149
-
150
- pq = PhraseQuery.new()
151
- pq << t1
152
- pq.add(t3, 2)
153
- check_hits(pq, [1,11,14])
154
-
155
- pq.slop = 1
156
- check_hits(pq, [1,11,14,16])
157
-
158
- pq.slop = 4
159
- check_hits(pq, [1,11,14,16,17])
160
- end
161
-
162
- def test_range_query()
163
- rq = RangeQuery.new("date", "20051006", "20051010", true, true)
164
- check_hits(rq, [6,7,8,9,10])
165
-
166
- rq = RangeQuery.new("date", "20051006", "20051010", false, true)
167
- check_hits(rq, [7,8,9,10])
168
-
169
- rq = RangeQuery.new("date", "20051006", "20051010", true, false)
170
- check_hits(rq, [6,7,8,9])
171
-
172
- rq = RangeQuery.new("date", "20051006", "20051010", false, false)
173
- check_hits(rq, [7,8,9])
174
-
175
- rq = RangeQuery.new("date", nil, "20051003", false, true)
176
- check_hits(rq, [0,1,2,3])
177
-
178
- rq = RangeQuery.new("date", nil, "20051003", false, false)
179
- check_hits(rq, [0,1,2])
180
-
181
- rq = RangeQuery.new_less("date", "20051003", true)
182
- check_hits(rq, [0,1,2,3])
183
-
184
- rq = RangeQuery.new_less("date", "20051003", false)
185
- check_hits(rq, [0,1,2])
186
-
187
- rq = RangeQuery.new("date", "20051014", nil, true, false)
188
- check_hits(rq, [14,15,16,17])
189
-
190
- rq = RangeQuery.new("date", "20051014", nil, false, false)
191
- check_hits(rq, [15,16,17])
192
-
193
- rq = RangeQuery.new_more("date", "20051014", true)
194
- check_hits(rq, [14,15,16,17])
195
-
196
- rq = RangeQuery.new_more("date", "20051014", false)
197
- check_hits(rq, [15,16,17])
198
- end
199
-
200
- def test_prefix_query()
201
- t = Term.new("cat", "cat1")
202
- pq = PrefixQuery.new(t)
203
- check_hits(pq, [0, 1, 2, 3, 4, 13, 14, 15, 16, 17])
204
-
205
- t.text = "cat1/sub2"
206
- pq = PrefixQuery.new(t)
207
- check_hits(pq, [3, 4, 13, 15])
208
- end
209
-
210
- def test_wildcard_query()
211
- t = Term.new("cat", "cat1*")
212
- wq = WildcardQuery.new(t)
213
- check_hits(wq, [0, 1, 2, 3, 4, 13, 14, 15, 16, 17])
214
-
215
- t.text = "cat1*/su??ub2"
216
- wq = WildcardQuery.new(t)
217
- check_hits(wq, [4, 16])
218
- end
219
-
220
- def test_multi_phrase_query()
221
- t11 = Term.new("field", "quick")
222
- t12 = Term.new("field", "fast")
223
- t21 = Term.new("field", "brown")
224
- t22 = Term.new("field", "red")
225
- t23 = Term.new("field", "hairy")
226
- t3 = Term.new("field", "fox")
227
-
228
- mpq = MultiPhraseQuery.new()
229
- mpq << [t11, t12]
230
- mpq << [t21, t22, t23]
231
- mpq << t3
232
- check_hits(mpq, [1, 8, 11, 14])
233
-
234
- mpq.slop = 4
235
- check_hits(mpq, [1, 8, 11, 14, 16, 17])
54
+ assert_equal(18, @searcher.max_doc)
55
+ assert_equal("20050930", @searcher.get_document(0)[:date])
56
+ assert_equal("cat1/sub2/subsub2", @searcher.get_document(4)[:category])
57
+ assert_equal("20051012", @searcher.get_document(12)[:date])
236
58
  end
237
59
  end