ferret 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data/Rakefile +23 -5
  2. data/TODO +2 -1
  3. data/ext/analysis.c +838 -177
  4. data/ext/analysis.h +55 -7
  5. data/ext/api.c +69 -0
  6. data/ext/api.h +27 -0
  7. data/ext/array.c +8 -5
  8. data/ext/compound_io.c +132 -96
  9. data/ext/document.c +58 -28
  10. data/ext/except.c +59 -0
  11. data/ext/except.h +88 -0
  12. data/ext/ferret.c +47 -3
  13. data/ext/ferret.h +3 -0
  14. data/ext/field.c +15 -9
  15. data/ext/filter.c +1 -1
  16. data/ext/fs_store.c +215 -34
  17. data/ext/global.c +72 -3
  18. data/ext/global.h +4 -3
  19. data/ext/hash.c +44 -3
  20. data/ext/hash.h +9 -0
  21. data/ext/header.h +58 -0
  22. data/ext/inc/except.h +88 -0
  23. data/ext/inc/lang.h +23 -13
  24. data/ext/ind.c +16 -10
  25. data/ext/index.h +2 -22
  26. data/ext/index_io.c +3 -11
  27. data/ext/index_rw.c +245 -193
  28. data/ext/lang.h +23 -13
  29. data/ext/libstemmer.c +92 -0
  30. data/ext/libstemmer.h +79 -0
  31. data/ext/modules.h +162 -0
  32. data/ext/q_boolean.c +34 -21
  33. data/ext/q_const_score.c +6 -12
  34. data/ext/q_filtered_query.c +206 -0
  35. data/ext/q_fuzzy.c +18 -15
  36. data/ext/q_match_all.c +3 -7
  37. data/ext/q_multi_phrase.c +10 -14
  38. data/ext/q_parser.c +29 -2
  39. data/ext/q_phrase.c +14 -21
  40. data/ext/q_prefix.c +15 -12
  41. data/ext/q_range.c +30 -28
  42. data/ext/q_span.c +13 -21
  43. data/ext/q_term.c +17 -26
  44. data/ext/r_analysis.c +693 -21
  45. data/ext/r_doc.c +11 -12
  46. data/ext/r_index_io.c +4 -1
  47. data/ext/r_qparser.c +21 -2
  48. data/ext/r_search.c +285 -18
  49. data/ext/ram_store.c +5 -2
  50. data/ext/search.c +11 -17
  51. data/ext/search.h +21 -45
  52. data/ext/similarity.h +67 -0
  53. data/ext/sort.c +30 -25
  54. data/ext/stem_ISO_8859_1_danish.c +338 -0
  55. data/ext/stem_ISO_8859_1_danish.h +16 -0
  56. data/ext/stem_ISO_8859_1_dutch.c +635 -0
  57. data/ext/stem_ISO_8859_1_dutch.h +16 -0
  58. data/ext/stem_ISO_8859_1_english.c +1156 -0
  59. data/ext/stem_ISO_8859_1_english.h +16 -0
  60. data/ext/stem_ISO_8859_1_finnish.c +792 -0
  61. data/ext/stem_ISO_8859_1_finnish.h +16 -0
  62. data/ext/stem_ISO_8859_1_french.c +1276 -0
  63. data/ext/stem_ISO_8859_1_french.h +16 -0
  64. data/ext/stem_ISO_8859_1_german.c +512 -0
  65. data/ext/stem_ISO_8859_1_german.h +16 -0
  66. data/ext/stem_ISO_8859_1_italian.c +1091 -0
  67. data/ext/stem_ISO_8859_1_italian.h +16 -0
  68. data/ext/stem_ISO_8859_1_norwegian.c +296 -0
  69. data/ext/stem_ISO_8859_1_norwegian.h +16 -0
  70. data/ext/stem_ISO_8859_1_porter.c +776 -0
  71. data/ext/stem_ISO_8859_1_porter.h +16 -0
  72. data/ext/stem_ISO_8859_1_portuguese.c +1035 -0
  73. data/ext/stem_ISO_8859_1_portuguese.h +16 -0
  74. data/ext/stem_ISO_8859_1_spanish.c +1119 -0
  75. data/ext/stem_ISO_8859_1_spanish.h +16 -0
  76. data/ext/stem_ISO_8859_1_swedish.c +307 -0
  77. data/ext/stem_ISO_8859_1_swedish.h +16 -0
  78. data/ext/stem_KOI8_R_russian.c +701 -0
  79. data/ext/stem_KOI8_R_russian.h +16 -0
  80. data/ext/stem_UTF_8_danish.c +344 -0
  81. data/ext/stem_UTF_8_danish.h +16 -0
  82. data/ext/stem_UTF_8_dutch.c +653 -0
  83. data/ext/stem_UTF_8_dutch.h +16 -0
  84. data/ext/stem_UTF_8_english.c +1176 -0
  85. data/ext/stem_UTF_8_english.h +16 -0
  86. data/ext/stem_UTF_8_finnish.c +808 -0
  87. data/ext/stem_UTF_8_finnish.h +16 -0
  88. data/ext/stem_UTF_8_french.c +1296 -0
  89. data/ext/stem_UTF_8_french.h +16 -0
  90. data/ext/stem_UTF_8_german.c +526 -0
  91. data/ext/stem_UTF_8_german.h +16 -0
  92. data/ext/stem_UTF_8_italian.c +1113 -0
  93. data/ext/stem_UTF_8_italian.h +16 -0
  94. data/ext/stem_UTF_8_norwegian.c +302 -0
  95. data/ext/stem_UTF_8_norwegian.h +16 -0
  96. data/ext/stem_UTF_8_porter.c +794 -0
  97. data/ext/stem_UTF_8_porter.h +16 -0
  98. data/ext/stem_UTF_8_portuguese.c +1055 -0
  99. data/ext/stem_UTF_8_portuguese.h +16 -0
  100. data/ext/stem_UTF_8_russian.c +709 -0
  101. data/ext/stem_UTF_8_russian.h +16 -0
  102. data/ext/stem_UTF_8_spanish.c +1137 -0
  103. data/ext/stem_UTF_8_spanish.h +16 -0
  104. data/ext/stem_UTF_8_swedish.c +313 -0
  105. data/ext/stem_UTF_8_swedish.h +16 -0
  106. data/ext/stopwords.c +325 -0
  107. data/ext/store.c +34 -2
  108. data/ext/tags +2953 -0
  109. data/ext/term.c +21 -15
  110. data/ext/termdocs.c +5 -3
  111. data/ext/utilities.c +446 -0
  112. data/ext/vector.c +27 -13
  113. data/lib/ferret/document/document.rb +1 -1
  114. data/lib/ferret/index/index.rb +44 -6
  115. data/lib/ferret/query_parser/query_parser.tab.rb +7 -3
  116. data/lib/rferret.rb +2 -1
  117. data/test/test_helper.rb +2 -2
  118. data/test/unit/analysis/ctc_analyzer.rb +401 -0
  119. data/test/unit/analysis/ctc_tokenstream.rb +423 -0
  120. data/test/unit/analysis/{tc_letter_tokenizer.rb → rtc_letter_tokenizer.rb} +0 -0
  121. data/test/unit/analysis/{tc_lower_case_filter.rb → rtc_lower_case_filter.rb} +0 -0
  122. data/test/unit/analysis/{tc_lower_case_tokenizer.rb → rtc_lower_case_tokenizer.rb} +0 -0
  123. data/test/unit/analysis/{tc_per_field_analyzer_wrapper.rb → rtc_per_field_analyzer_wrapper.rb} +0 -0
  124. data/test/unit/analysis/{tc_porter_stem_filter.rb → rtc_porter_stem_filter.rb} +0 -0
  125. data/test/unit/analysis/{tc_standard_analyzer.rb → rtc_standard_analyzer.rb} +0 -0
  126. data/test/unit/analysis/{tc_standard_tokenizer.rb → rtc_standard_tokenizer.rb} +0 -0
  127. data/test/unit/analysis/{tc_stop_analyzer.rb → rtc_stop_analyzer.rb} +0 -0
  128. data/test/unit/analysis/{tc_stop_filter.rb → rtc_stop_filter.rb} +0 -0
  129. data/test/unit/analysis/{tc_white_space_analyzer.rb → rtc_white_space_analyzer.rb} +0 -0
  130. data/test/unit/analysis/{tc_white_space_tokenizer.rb → rtc_white_space_tokenizer.rb} +0 -0
  131. data/test/unit/analysis/{tc_word_list_loader.rb → rtc_word_list_loader.rb} +0 -0
  132. data/test/unit/analysis/tc_analyzer.rb +1 -2
  133. data/test/unit/analysis/{c_token.rb → tc_token.rb} +0 -0
  134. data/test/unit/document/rtc_field.rb +28 -0
  135. data/test/unit/document/{c_document.rb → tc_document.rb} +0 -0
  136. data/test/unit/document/tc_field.rb +82 -12
  137. data/test/unit/index/{tc_compound_file_io.rb → rtc_compound_file_io.rb} +0 -0
  138. data/test/unit/index/{tc_field_infos.rb → rtc_field_infos.rb} +0 -0
  139. data/test/unit/index/{tc_fields_io.rb → rtc_fields_io.rb} +0 -0
  140. data/test/unit/index/{tc_multiple_term_doc_pos_enum.rb → rtc_multiple_term_doc_pos_enum.rb} +0 -0
  141. data/test/unit/index/{tc_segment_infos.rb → rtc_segment_infos.rb} +0 -0
  142. data/test/unit/index/{tc_segment_term_docs.rb → rtc_segment_term_docs.rb} +0 -0
  143. data/test/unit/index/{tc_segment_term_enum.rb → rtc_segment_term_enum.rb} +0 -0
  144. data/test/unit/index/{tc_segment_term_vector.rb → rtc_segment_term_vector.rb} +0 -0
  145. data/test/unit/index/{tc_term_buffer.rb → rtc_term_buffer.rb} +0 -0
  146. data/test/unit/index/{tc_term_info.rb → rtc_term_info.rb} +0 -0
  147. data/test/unit/index/{tc_term_infos_io.rb → rtc_term_infos_io.rb} +0 -0
  148. data/test/unit/index/{tc_term_vectors_io.rb → rtc_term_vectors_io.rb} +0 -0
  149. data/test/unit/index/{c_index.rb → tc_index.rb} +26 -6
  150. data/test/unit/index/{c_index_reader.rb → tc_index_reader.rb} +0 -0
  151. data/test/unit/index/{c_index_writer.rb → tc_index_writer.rb} +0 -0
  152. data/test/unit/index/{c_term.rb → tc_term.rb} +0 -0
  153. data/test/unit/index/{c_term_voi.rb → tc_term_voi.rb} +0 -0
  154. data/test/unit/query_parser/{c_query_parser.rb → rtc_query_parser.rb} +14 -14
  155. data/test/unit/query_parser/tc_query_parser.rb +24 -16
  156. data/test/unit/search/{tc_similarity.rb → rtc_similarity.rb} +0 -0
  157. data/test/unit/search/rtc_sort_field.rb +14 -0
  158. data/test/unit/search/{c_filter.rb → tc_filter.rb} +11 -11
  159. data/test/unit/search/{c_fuzzy_query.rb → tc_fuzzy_query.rb} +0 -0
  160. data/test/unit/search/{c_index_searcher.rb → tc_index_searcher.rb} +0 -0
  161. data/test/unit/search/{c_search_and_sort.rb → tc_search_and_sort.rb} +0 -0
  162. data/test/unit/search/{c_sort.rb → tc_sort.rb} +0 -0
  163. data/test/unit/search/tc_sort_field.rb +20 -7
  164. data/test/unit/search/{c_spans.rb → tc_spans.rb} +0 -0
  165. data/test/unit/store/rtc_fs_store.rb +62 -0
  166. data/test/unit/store/rtc_ram_store.rb +15 -0
  167. data/test/unit/store/rtm_store.rb +150 -0
  168. data/test/unit/store/rtm_store_lock.rb +2 -0
  169. data/test/unit/store/tc_fs_store.rb +54 -40
  170. data/test/unit/store/tc_ram_store.rb +20 -0
  171. data/test/unit/store/tm_store.rb +30 -146
  172. data/test/unit/store/tm_store_lock.rb +66 -0
  173. data/test/unit/utils/{tc_bit_vector.rb → rtc_bit_vector.rb} +0 -0
  174. data/test/unit/utils/{tc_date_tools.rb → rtc_date_tools.rb} +0 -0
  175. data/test/unit/utils/{tc_number_tools.rb → rtc_number_tools.rb} +0 -0
  176. data/test/unit/utils/{tc_parameter.rb → rtc_parameter.rb} +0 -0
  177. data/test/unit/utils/{tc_priority_queue.rb → rtc_priority_queue.rb} +0 -0
  178. data/test/unit/utils/{tc_string_helper.rb → rtc_string_helper.rb} +0 -0
  179. data/test/unit/utils/{tc_thread.rb → rtc_thread.rb} +0 -0
  180. data/test/unit/utils/{tc_weak_key_hash.rb → rtc_weak_key_hash.rb} +0 -0
  181. metadata +360 -289
  182. data/test/unit/document/c_field.rb +0 -98
  183. data/test/unit/search/c_sort_field.rb +0 -27
  184. data/test/unit/store/c_fs_store.rb +0 -76
  185. data/test/unit/store/c_ram_store.rb +0 -35
  186. data/test/unit/store/m_store.rb +0 -34
  187. data/test/unit/store/m_store_lock.rb +0 -68
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+
4
+ class FieldTest < Test::Unit::TestCase
5
+ include Ferret::Document
6
+ include Ferret::Utils
7
+
8
+ def test_store()
9
+ assert_equal("COMPRESS", Field::Store::COMPRESS.to_s)
10
+ assert_equal("YES", Field::Store::YES.to_s)
11
+ assert_equal("NO", Field::Store::NO.to_s)
12
+ end
13
+
14
+ def test_index()
15
+ assert_equal("TOKENIZED", Field::Index::TOKENIZED.to_s)
16
+ assert_equal("UNTOKENIZED", Field::Index::UNTOKENIZED.to_s)
17
+ assert_equal("NO", Field::Index::NO.to_s)
18
+ assert_equal("NO_NORMS", Field::Index::NO_NORMS.to_s)
19
+ end
20
+
21
+ def test_term_vector()
22
+ assert_equal("YES", Field::TermVector::YES.to_s)
23
+ assert_equal("NO", Field::TermVector::NO.to_s)
24
+ assert_equal("WITH_POSITIONS", Field::TermVector::WITH_POSITIONS.to_s)
25
+ assert_equal("WITH_OFFSETS", Field::TermVector::WITH_OFFSETS.to_s)
26
+ assert_equal("WITH_POSITIONS_OFFSETS", Field::TermVector::WITH_POSITIONS_OFFSETS.to_s)
27
+ end
28
+ end
@@ -6,23 +6,93 @@ class FieldTest < Test::Unit::TestCase
6
6
  include Ferret::Utils
7
7
 
8
8
  def test_store()
9
- assert_equal("COMPRESS", Field::Store::COMPRESS.to_s)
10
- assert_equal("YES", Field::Store::YES.to_s)
11
- assert_equal("NO", Field::Store::NO.to_s)
9
+ assert_not_nil(Field::Store::COMPRESS)
10
+ assert_not_nil(Field::Store::YES)
11
+ assert_not_nil(Field::Store::NO)
12
12
  end
13
13
 
14
14
  def test_index()
15
- assert_equal("TOKENIZED", Field::Index::TOKENIZED.to_s)
16
- assert_equal("UNTOKENIZED", Field::Index::UNTOKENIZED.to_s)
17
- assert_equal("NO", Field::Index::NO.to_s)
18
- assert_equal("NO_NORMS", Field::Index::NO_NORMS.to_s)
15
+ assert_not_nil(Field::Index::TOKENIZED)
16
+ assert_not_nil(Field::Index::UNTOKENIZED)
17
+ assert_not_nil(Field::Index::NO)
18
+ assert_not_nil(Field::Index::NO_NORMS)
19
19
  end
20
20
 
21
21
  def test_term_vector()
22
- assert_equal("YES", Field::TermVector::YES.to_s)
23
- assert_equal("NO", Field::TermVector::NO.to_s)
24
- assert_equal("WITH_POSITIONS", Field::TermVector::WITH_POSITIONS.to_s)
25
- assert_equal("WITH_OFFSETS", Field::TermVector::WITH_OFFSETS.to_s)
26
- assert_equal("WITH_POSITIONS_OFFSETS", Field::TermVector::WITH_POSITIONS_OFFSETS.to_s)
22
+ assert_not_nil(Field::TermVector::YES)
23
+ assert_not_nil(Field::TermVector::NO)
24
+ assert_not_nil(Field::TermVector::WITH_POSITIONS)
25
+ assert_not_nil(Field::TermVector::WITH_OFFSETS)
26
+ assert_not_nil(Field::TermVector::WITH_POSITIONS_OFFSETS)
27
+ end
28
+
29
+ def test_standard_field()
30
+ f = Field.new("name", "value", Field::Store::COMPRESS, Field::Index::TOKENIZED)
31
+ assert_equal("name", f.name)
32
+ assert_equal("value", f.data)
33
+ assert_equal(true, f.stored?)
34
+ assert_equal(true, f.compressed?)
35
+ assert_equal(true, f.indexed?)
36
+ assert_equal(true, f.tokenized?)
37
+ assert_equal(false, f.store_term_vector?)
38
+ assert_equal(false, f.store_offsets?)
39
+ assert_equal(false, f.store_positions?)
40
+ assert_equal(false, f.omit_norms?)
41
+ assert_equal(false, f.binary?)
42
+ assert_equal("stored/compressed,indexed,tokenized,<name:value>", f.to_s)
43
+ f.data = "183"
44
+ f.boost = 0.001
45
+ assert_equal("183", f.data)
46
+ assert(0.001 =~ f.boost)
47
+ end
48
+
49
+ def test_set_store()
50
+ f = Field.new("name", "", Field::Store::COMPRESS, Field::Index::TOKENIZED)
51
+ f.store = Field::Store::NO
52
+ assert_equal(false, f.stored?)
53
+ assert_equal(false, f.compressed?)
54
+ assert_equal("indexed,tokenized,<name:>", f.to_s)
55
+ end
56
+
57
+ def test_set_index()
58
+ f = Field.new("name", "value", Field::Store::COMPRESS, Field::Index::TOKENIZED)
59
+ f.index = Field::Index::NO
60
+ assert_equal(false, f.indexed?)
61
+ assert_equal(false, f.tokenized?)
62
+ assert_equal(false, f.omit_norms?)
63
+ assert_equal("stored/compressed,<name:value>", f.to_s)
64
+ f.index = Field::Index::NO_NORMS
65
+ assert_equal(true, f.indexed?)
66
+ assert_equal(false, f.tokenized?)
67
+ assert_equal(true, f.omit_norms?)
68
+ assert_equal("stored/compressed,indexed,omit_norms,<name:value>", f.to_s)
69
+ end
70
+
71
+ def test_set_term_vector()
72
+ f = Field.new("name", "value", Field::Store::COMPRESS, Field::Index::TOKENIZED)
73
+ f.term_vector = Field::TermVector::WITH_POSITIONS_OFFSETS
74
+ assert_equal(true, f.store_term_vector?)
75
+ assert_equal(true, f.store_offsets?)
76
+ assert_equal(true, f.store_positions?)
77
+ assert_equal("stored/compressed,indexed,tokenized,store_term_vector,store_offsets,store_positions,<name:value>", f.to_s)
78
+ end
79
+
80
+ def test_new_binary_field()
81
+ tmp = []
82
+ 256.times {|i| tmp[i] = i}
83
+ bin = tmp.pack("c*")
84
+ f = Field.new_binary_field("name", bin, Field::Store::YES)
85
+ assert_equal("name", f.name)
86
+ assert_equal(bin, f.data)
87
+ assert_equal(true, f.stored?)
88
+ assert_equal(false, f.compressed?)
89
+ assert_equal(false, f.indexed?)
90
+ assert_equal(false, f.tokenized?)
91
+ assert_equal(false, f.store_term_vector?)
92
+ assert_equal(false, f.store_offsets?)
93
+ assert_equal(false, f.store_positions?)
94
+ assert_equal(false, f.omit_norms?)
95
+ assert_equal(true, f.binary?)
96
+ assert_equal("stored/uncompressed,binary,<name:=bin_data=>", f.to_s)
27
97
  end
28
98
  end
@@ -77,7 +77,7 @@ class IndexTest < Test::Unit::TestCase
77
77
 
78
78
  def do_test_index_with_doc_array(index)
79
79
  data = [
80
- {"def_field" => "one two multi", :id => "me"},
80
+ {"def_field" => "one two multi", :id => "myid"},
81
81
  {"def_field" => "one", :field2 => "three multi"},
82
82
  {"def_field" => "two"},
83
83
  {"def_field" => "one", :field2 => "four"},
@@ -125,8 +125,8 @@ class IndexTest < Test::Unit::TestCase
125
125
  assert(! index.deleted?(7))
126
126
  t = Term.new("field2", "four")
127
127
  assert_equal("one", index[t]["def_field"])
128
- assert_equal("one two multi", index["me"]["def_field"])
129
- index.delete("me")
128
+ assert_equal("one two multi", index["myid"]["def_field"])
129
+ index.delete("myid")
130
130
  assert(index.deleted?(0))
131
131
  end
132
132
 
@@ -193,6 +193,26 @@ class IndexTest < Test::Unit::TestCase
193
193
  index.close
194
194
  end
195
195
 
196
+ def test_key_used_for_id_field
197
+ fs_path = File.expand_path(File.join(File.dirname(__FILE__), '../../temp/fsdir'))
198
+ Dir[File.join(fs_path, "*")].each {|path| begin File.delete(path) rescue nil end}
199
+ data = [
200
+ {:my_id => "one two", :id => "me"},
201
+ {:my_id => "one", :field2 => "three"},
202
+ {:my_id => "two"},
203
+ {:my_id => "one", :field2 => "four"},
204
+ {:my_id => "one two"},
205
+ {:my_id => "two", :field2 => "three", "field3" => "four"},
206
+ {:my_id => "one"},
207
+ {:my_id => "two", :field2 => "three", "field3" => "five"}
208
+ ]
209
+ index = Index.new(:path => fs_path, :key => :my_id)
210
+ data.each {|doc| index << doc }
211
+ assert_equal(3, index.size)
212
+ assert_equal("three", index[:two][:field2])
213
+ index.close
214
+ end
215
+
196
216
  def test_merging_indexes
197
217
  data = [
198
218
  {"f" => "zero"},
@@ -432,7 +452,7 @@ class IndexTest < Test::Unit::TestCase
432
452
  {:id => 1, :val => "four"},
433
453
  ]
434
454
  index = Index.new(:analyzer => WhiteSpaceAnalyzer.new,
435
- :key => "id")
455
+ :key => :id)
436
456
  data.each { |doc| index << doc }
437
457
  assert_equal(2, index.size)
438
458
  assert_equal("two", index[0][:val])
@@ -453,7 +473,7 @@ class IndexTest < Test::Unit::TestCase
453
473
  {:id => 1, :table => "product", :product => "backpack"}
454
474
  ]
455
475
  index = Index.new(:analyzer => WhiteSpaceAnalyzer.new,
456
- :key => ["id", "table"])
476
+ :key => [:id, :table])
457
477
  data.each { |doc| index << doc }
458
478
  assert_equal(4, index.size)
459
479
  assert_equal("super tent", index[0][:product])
@@ -476,7 +496,7 @@ class IndexTest < Test::Unit::TestCase
476
496
  {:id => 1, :table => "Product", :product => "backpack"}
477
497
  ]
478
498
  index = Index.new(:analyzer => Analyzer.new,
479
- :key => ["id", "table"])
499
+ :key => [:id, :table])
480
500
  data.each do |dat|
481
501
  doc = Document.new
482
502
  dat.each_pair do |key, value|
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + "/../../test_helper"
3
3
  class QueryParserTest < Test::Unit::TestCase
4
4
 
5
5
  def test_strings()
6
- parser = Ferret::QueryParser.new("xxx", :fields => ["xxx", "field", "f1", "f2"])
6
+ parser = Ferret::QueryParser.new("xxx", :fields => ["f1", "f2", "f3"])
7
7
  pairs = [
8
8
  ['', ''],
9
9
  ['word', 'word'],
@@ -17,7 +17,7 @@ class QueryParserTest < Test::Unit::TestCase
17
17
  ['field:"one <> <> <> three <>"', 'field:"one <> <> <> three"'],
18
18
  ['field:"one <> <> <> three|four|five <>"', 'field:"one <> <> <> three|four|five"'],
19
19
  ['field:"one|two three|four|five six|seven"', 'field:"one|two three|four|five six|seven"'],
20
- ['field:"testing|trucks"', 'field:testing field:trucks'],
20
+ ['contents:"testing|trucks"', 'contents:testing contents:trucks'],
21
21
  ['[aaa bbb]', '[aaa bbb]'],
22
22
  ['{aaa bbb]', '{aaa bbb]'],
23
23
  ['field:[aaa bbb}', 'field:[aaa bbb}'],
@@ -54,7 +54,7 @@ class QueryParserTest < Test::Unit::TestCase
54
54
  ['one AND (two OR three)', '+one +(two three)'],
55
55
  ['field:(one AND (two OR three))', '+field:one +(field:two field:three)'],
56
56
  ['one AND (two OR [aaa vvv})', '+one +(two [aaa vvv})'],
57
- ['one AND (f1:two OR f2:three) AND four', '+one +(f1:two f2:three) +four'],
57
+ ['one AND (one:two OR two:three) AND four', '+one +(one:two two:three) +four'],
58
58
  ['one^1.23', 'one^1.23'],
59
59
  ['(one AND two)^100.23', '(+one +two)^100.23'],
60
60
  ['field:(one AND two)^100.23', '(+field:one +field:two)^100.23'],
@@ -73,42 +73,42 @@ class QueryParserTest < Test::Unit::TestCase
73
73
  ['field:abc~ AND field:(b*)', '+field:abc~ +field:b*'],
74
74
  ['asdf?*?asd*dsf?asfd*asdf?^20.0', 'asdf?*?asd*dsf?asfd*asdf?^20.0'],
75
75
 
76
- ['*:xxx', 'xxx field:xxx f1:xxx f2:xxx'],
76
+ ['*:xxx', 'f1:xxx f2:xxx f3:xxx'],
77
77
  ['f1|f2:xxx', 'f1:xxx f2:xxx'],
78
78
 
79
- ['*:asd~0.2', 'asd~0.2 field:asd~0.2 f1:asd~0.2 f2:asd~0.2'],
79
+ ['*:asd~0.2', 'f1:asd~0.2 f2:asd~0.2 f3:asd~0.2'],
80
80
  ['f1|f2:asd~0.2', 'f1:asd~0.2 f2:asd~0.2'],
81
81
 
82
- ['*:a?d*^20.0', '(a?d* field:a?d* f1:a?d* f2:a?d*)^20.0'],
82
+ ['*:a?d*^20.0', '(f1:a?d* f2:a?d* f3:a?d*)^20.0'],
83
83
  ['f1|f2:a?d*^20.0', '(f1:a?d* f2:a?d*)^20.0'],
84
84
 
85
- ['*:"asdf <> xxx|yyy"', '"asdf <> xxx|yyy" field:"asdf <> xxx|yyy" f1:"asdf <> xxx|yyy" f2:"asdf <> xxx|yyy"'],
85
+ ['*:"asdf <> xxx|yyy"', 'f1:"asdf <> xxx|yyy" f2:"asdf <> xxx|yyy" f3:"asdf <> xxx|yyy"'],
86
86
  ['f1|f2:"asdf <> xxx|yyy"', 'f1:"asdf <> xxx|yyy" f2:"asdf <> xxx|yyy"'],
87
87
 
88
- ['*:[bbb xxx]', '[bbb xxx] field:[bbb xxx] f1:[bbb xxx] f2:[bbb xxx]'],
88
+ ['*:[bbb xxx]', 'f1:[bbb xxx] f2:[bbb xxx] f3:[bbb xxx]'],
89
89
  ['f1|f2:[bbb xxx]', 'f1:[bbb xxx] f2:[bbb xxx]'],
90
90
 
91
- ['*:(xxx AND bbb)', '+(xxx field:xxx f1:xxx f2:xxx) +(bbb field:bbb f1:bbb f2:bbb)'],
91
+ ['*:(xxx AND bbb)', '+(f1:xxx f2:xxx f3:xxx) +(f1:bbb f2:bbb f3:bbb)'],
92
92
  ['f1|f2:(xxx AND bbb)', '+(f1:xxx f2:xxx) +(f1:bbb f2:bbb)'],
93
93
  ['asdf?*?asd*dsf?asfd*asdf?^20.0', 'asdf?*?asd*dsf?asfd*asdf?^20.0'],
94
94
  ['"onewordphrase"', 'onewordphrase']
95
95
  ]
96
96
 
97
97
  pairs.each do |query_str, expected|
98
- assert_equal(expected, parser.parse(query_str).to_s("xxx"))
98
+ assert_equal(expected, parser.parse(query_str).to_s(parser.default_field))
99
99
  end
100
100
  end
101
101
 
102
102
  def test_qp_with_standard_analyzer()
103
- parser = Ferret::QueryParser.new("xxx", :fields => ["xxx", "key"],
103
+ parser = Ferret::QueryParser.new("xxx", :fields => ["f1", "f2", "f3"],
104
104
  :analyzer => Ferret::Analysis::StandardAnalyzer.new)
105
105
  pairs = [
106
- ['key:1234', 'key:1234'],
106
+ ['key:1234', 'key:1234'],
107
107
  ['key:(1234)', 'key:1234']
108
108
  ]
109
109
 
110
110
  pairs.each do |query_str, expected|
111
- assert_equal(expected, parser.parse(query_str).to_s("xxx"))
111
+ assert_equal(expected, parser.parse(query_str).to_s(parser.default_field))
112
112
  end
113
113
  end
114
114
 
@@ -132,7 +132,7 @@ class QueryParserTest < Test::Unit::TestCase
132
132
 
133
133
  pairs.each do |query_str, expected|
134
134
  do_test_query_parse_exception_raised(query_str)
135
- assert_equal(expected, parser.parse(query_str).to_s("xxx"))
135
+ assert_equal(expected, parser.parse(query_str).to_s(parser.default_field))
136
136
  end
137
137
  end
138
138
  end
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + "/../../test_helper"
3
3
  class QueryParserTest < Test::Unit::TestCase
4
4
 
5
5
  def test_strings()
6
- parser = Ferret::QueryParser.new("xxx", :fields => ["f1", "f2", "f3"])
6
+ parser = Ferret::QueryParser.new("xxx", :fields => ["xxx", "field", "f1", "f2"])
7
7
  pairs = [
8
8
  ['', ''],
9
9
  ['word', 'word'],
@@ -17,7 +17,7 @@ class QueryParserTest < Test::Unit::TestCase
17
17
  ['field:"one <> <> <> three <>"', 'field:"one <> <> <> three"'],
18
18
  ['field:"one <> <> <> three|four|five <>"', 'field:"one <> <> <> three|four|five"'],
19
19
  ['field:"one|two three|four|five six|seven"', 'field:"one|two three|four|five six|seven"'],
20
- ['contents:"testing|trucks"', 'contents:"testing|trucks"'],
20
+ ['field:"testing|trucks"', 'field:testing field:trucks'],
21
21
  ['[aaa bbb]', '[aaa bbb]'],
22
22
  ['{aaa bbb]', '{aaa bbb]'],
23
23
  ['field:[aaa bbb}', 'field:[aaa bbb}'],
@@ -54,7 +54,7 @@ class QueryParserTest < Test::Unit::TestCase
54
54
  ['one AND (two OR three)', '+one +(two three)'],
55
55
  ['field:(one AND (two OR three))', '+field:one +(field:two field:three)'],
56
56
  ['one AND (two OR [aaa vvv})', '+one +(two [aaa vvv})'],
57
- ['one AND (one:two OR two:three) AND four', '+one +(one:two two:three) +four'],
57
+ ['one AND (f1:two OR f2:three) AND four', '+one +(f1:two f2:three) +four'],
58
58
  ['one^1.23', 'one^1.23'],
59
59
  ['(one AND two)^100.23', '(+one +two)^100.23'],
60
60
  ['field:(one AND two)^100.23', '(+field:one +field:two)^100.23'],
@@ -70,45 +70,45 @@ class QueryParserTest < Test::Unit::TestCase
70
70
  ['ab*de', 'ab*de'],
71
71
  ['asdf?*?asd*dsf?asfd*asdf?', 'asdf?*?asd*dsf?asfd*asdf?'],
72
72
  ['field:a* AND field:(b*)', '+field:a* +field:b*'],
73
- ['field:abc~ AND field:(b*)', '+field:abc~0.5 +field:b*'],
73
+ ['field:abc~ AND field:(b*)', '+field:abc~ +field:b*'],
74
74
  ['asdf?*?asd*dsf?asfd*asdf?^20.0', 'asdf?*?asd*dsf?asfd*asdf?^20.0'],
75
75
 
76
- ['*:xxx', 'f1:xxx f2:xxx f3:xxx'],
76
+ ['*:xxx', 'xxx field:xxx f1:xxx f2:xxx'],
77
77
  ['f1|f2:xxx', 'f1:xxx f2:xxx'],
78
78
 
79
- ['*:asd~0.2', 'f1:asd~0.2 f2:asd~0.2 f3:asd~0.2'],
79
+ ['*:asd~0.2', 'asd~0.2 field:asd~0.2 f1:asd~0.2 f2:asd~0.2'],
80
80
  ['f1|f2:asd~0.2', 'f1:asd~0.2 f2:asd~0.2'],
81
81
 
82
- ['*:a?d*^20.0', '(f1:a?d* f2:a?d* f3:a?d*)^20.0'],
82
+ ['*:a?d*^20.0', '(a?d* field:a?d* f1:a?d* f2:a?d*)^20.0'],
83
83
  ['f1|f2:a?d*^20.0', '(f1:a?d* f2:a?d*)^20.0'],
84
84
 
85
- ['*:"asdf <> xxx|yyy"', 'f1:"asdf <> xxx|yyy" f2:"asdf <> xxx|yyy" f3:"asdf <> xxx|yyy"'],
85
+ ['*:"asdf <> xxx|yyy"', '"asdf <> xxx|yyy" field:"asdf <> xxx|yyy" f1:"asdf <> xxx|yyy" f2:"asdf <> xxx|yyy"'],
86
86
  ['f1|f2:"asdf <> xxx|yyy"', 'f1:"asdf <> xxx|yyy" f2:"asdf <> xxx|yyy"'],
87
87
 
88
- ['*:[bbb xxx]', 'f1:[bbb xxx] f2:[bbb xxx] f3:[bbb xxx]'],
88
+ ['*:[bbb xxx]', '[bbb xxx] field:[bbb xxx] f1:[bbb xxx] f2:[bbb xxx]'],
89
89
  ['f1|f2:[bbb xxx]', 'f1:[bbb xxx] f2:[bbb xxx]'],
90
90
 
91
- ['*:(xxx AND bbb)', '+(f1:xxx f2:xxx f3:xxx) +(f1:bbb f2:bbb f3:bbb)'],
91
+ ['*:(xxx AND bbb)', '+(xxx field:xxx f1:xxx f2:xxx) +(bbb field:bbb f1:bbb f2:bbb)'],
92
92
  ['f1|f2:(xxx AND bbb)', '+(f1:xxx f2:xxx) +(f1:bbb f2:bbb)'],
93
93
  ['asdf?*?asd*dsf?asfd*asdf?^20.0', 'asdf?*?asd*dsf?asfd*asdf?^20.0'],
94
94
  ['"onewordphrase"', 'onewordphrase']
95
95
  ]
96
96
 
97
97
  pairs.each do |query_str, expected|
98
- assert_equal(expected, parser.parse(query_str).to_s(parser.default_field))
98
+ assert_equal(expected, parser.parse(query_str).to_s("xxx"))
99
99
  end
100
100
  end
101
101
 
102
102
  def test_qp_with_standard_analyzer()
103
- parser = Ferret::QueryParser.new("xxx", :fields => ["f1", "f2", "f3"],
103
+ parser = Ferret::QueryParser.new("xxx", :fields => ["xxx", "key"],
104
104
  :analyzer => Ferret::Analysis::StandardAnalyzer.new)
105
105
  pairs = [
106
- ['key:1234', 'key:1234'],
106
+ ['key:1234', 'key:1234'],
107
107
  ['key:(1234)', 'key:1234']
108
108
  ]
109
109
 
110
110
  pairs.each do |query_str, expected|
111
- assert_equal(expected, parser.parse(query_str).to_s(parser.default_field))
111
+ assert_equal(expected, parser.parse(query_str).to_s("xxx"))
112
112
  end
113
113
  end
114
114
 
@@ -119,6 +119,14 @@ class QueryParserTest < Test::Unit::TestCase
119
119
  end
120
120
  end
121
121
 
122
+ def test_prefix_query
123
+ parser = Ferret::QueryParser.new("xxx", :fields => ["xxx"],
124
+ :analyzer => Ferret::Analysis::StandardAnalyzer.new)
125
+ assert_equal(Ferret::Search::PrefixQuery, parser.parse("asdg*").class)
126
+ assert_equal(Ferret::Search::WildcardQuery, parser.parse("a?dg*").class)
127
+ assert_equal(Ferret::Search::WildcardQuery, parser.parse("a*dg*").class)
128
+ assert_equal(Ferret::Search::WildcardQuery, parser.parse("adg*c").class)
129
+ end
122
130
 
123
131
  def test_bad_queries
124
132
  parser = Ferret::QueryParser.new("xxx", :fields => ["f1", "f2"],
@@ -127,12 +135,12 @@ class QueryParserTest < Test::Unit::TestCase
127
135
  pairs = [
128
136
  ['::*word', 'word'],
129
137
  ['()*&)(*^&*(', ''],
130
- ['()*&one)(*two(*&"', 'one two']
138
+ ['()*&one)(*two(*&"', '"one two"']
131
139
  ]
132
140
 
133
141
  pairs.each do |query_str, expected|
134
142
  do_test_query_parse_exception_raised(query_str)
135
- assert_equal(expected, parser.parse(query_str).to_s(parser.default_field))
143
+ assert_equal(expected, parser.parse(query_str).to_s("xxx"))
136
144
  end
137
145
  end
138
146
  end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ class SortFieldTest < Test::Unit::TestCase
4
+ include Ferret::Search
5
+
6
+ def test_params()
7
+ assert_equal("score", SortField::SortType::SCORE.to_s)
8
+ assert_equal("doc", SortField::SortType::DOC.to_s)
9
+ assert_equal("auto", SortField::SortType::AUTO.to_s)
10
+ assert_equal("string", SortField::SortType::STRING.to_s)
11
+ assert_equal("int", SortField::SortType::INTEGER.to_s)
12
+ assert_equal("float", SortField::SortType::FLOAT.to_s)
13
+ end
14
+ end