ferret 0.9.6 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +1 -1
- data/README +12 -24
- data/Rakefile +38 -54
- data/TODO +14 -17
- data/ext/analysis.c +982 -823
- data/ext/analysis.h +133 -76
- data/ext/array.c +96 -58
- data/ext/array.h +40 -13
- data/ext/bitvector.c +476 -118
- data/ext/bitvector.h +264 -22
- data/ext/compound_io.c +217 -229
- data/ext/defines.h +49 -0
- data/ext/document.c +107 -317
- data/ext/document.h +31 -65
- data/ext/except.c +81 -36
- data/ext/except.h +117 -55
- data/ext/extconf.rb +2 -9
- data/ext/ferret.c +211 -104
- data/ext/ferret.h +22 -11
- data/ext/filter.c +97 -82
- data/ext/fs_store.c +348 -367
- data/ext/global.c +226 -188
- data/ext/global.h +44 -26
- data/ext/hash.c +474 -391
- data/ext/hash.h +441 -68
- data/ext/hashset.c +124 -96
- data/ext/hashset.h +169 -20
- data/ext/helper.c +56 -5
- data/ext/helper.h +7 -0
- data/ext/inc/lang.h +29 -49
- data/ext/inc/threading.h +31 -0
- data/ext/ind.c +288 -278
- data/ext/ind.h +68 -0
- data/ext/index.c +5688 -0
- data/ext/index.h +663 -616
- data/ext/lang.h +29 -49
- data/ext/libstemmer.c +3 -3
- data/ext/mem_pool.c +84 -0
- data/ext/mem_pool.h +35 -0
- data/ext/posh.c +1006 -0
- data/ext/posh.h +1007 -0
- data/ext/priorityqueue.c +117 -194
- data/ext/priorityqueue.h +135 -39
- data/ext/q_boolean.c +1305 -1108
- data/ext/q_const_score.c +106 -93
- data/ext/q_filtered_query.c +138 -135
- data/ext/q_fuzzy.c +206 -242
- data/ext/q_match_all.c +94 -80
- data/ext/q_multi_term.c +663 -0
- data/ext/q_parser.c +667 -593
- data/ext/q_phrase.c +992 -555
- data/ext/q_prefix.c +72 -61
- data/ext/q_range.c +235 -210
- data/ext/q_span.c +1480 -1166
- data/ext/q_term.c +273 -246
- data/ext/q_wildcard.c +127 -114
- data/ext/r_analysis.c +1720 -711
- data/ext/r_index.c +3049 -0
- data/ext/r_qparser.c +433 -146
- data/ext/r_search.c +2934 -1993
- data/ext/r_store.c +372 -143
- data/ext/r_utils.c +941 -0
- data/ext/ram_store.c +330 -326
- data/ext/search.c +1291 -668
- data/ext/search.h +403 -702
- data/ext/similarity.c +91 -113
- data/ext/similarity.h +45 -30
- data/ext/sort.c +721 -484
- data/ext/stopwords.c +361 -273
- data/ext/store.c +556 -58
- data/ext/store.h +706 -126
- data/ext/tags +3578 -2780
- data/ext/term_vectors.c +352 -0
- data/ext/threading.h +31 -0
- data/ext/win32.h +54 -0
- data/lib/ferret.rb +5 -17
- data/lib/ferret/document.rb +130 -2
- data/lib/ferret/index.rb +577 -26
- data/lib/ferret/number_tools.rb +157 -0
- data/lib/ferret_version.rb +3 -0
- data/test/test_helper.rb +5 -13
- data/test/unit/analysis/tc_analyzer.rb +513 -1
- data/test/unit/analysis/{ctc_tokenstream.rb → tc_token_stream.rb} +23 -0
- data/test/unit/index/tc_index.rb +183 -240
- data/test/unit/index/tc_index_reader.rb +312 -479
- data/test/unit/index/tc_index_writer.rb +397 -13
- data/test/unit/index/th_doc.rb +269 -206
- data/test/unit/query_parser/tc_query_parser.rb +40 -33
- data/test/unit/search/tc_filter.rb +59 -71
- data/test/unit/search/tc_fuzzy_query.rb +24 -16
- data/test/unit/search/tc_index_searcher.rb +23 -201
- data/test/unit/search/tc_multi_searcher.rb +78 -226
- data/test/unit/search/tc_search_and_sort.rb +93 -81
- data/test/unit/search/tc_sort.rb +23 -23
- data/test/unit/search/tc_sort_field.rb +7 -7
- data/test/unit/search/tc_spans.rb +51 -47
- data/test/unit/search/tm_searcher.rb +339 -0
- data/test/unit/store/tc_fs_store.rb +1 -1
- data/test/unit/store/tm_store_lock.rb +3 -3
- data/test/unit/tc_document.rb +81 -0
- data/test/unit/ts_analysis.rb +1 -1
- data/test/unit/ts_utils.rb +1 -1
- data/test/unit/utils/tc_bit_vector.rb +288 -0
- data/test/unit/utils/tc_number_tools.rb +117 -0
- data/test/unit/utils/tc_priority_queue.rb +106 -0
- metadata +140 -301
- data/CHANGELOG +0 -9
- data/ext/dummy.exe +0 -0
- data/ext/field.c +0 -408
- data/ext/frtio.h +0 -13
- data/ext/inc/except.h +0 -90
- data/ext/index_io.c +0 -382
- data/ext/index_rw.c +0 -2658
- data/ext/lang.c +0 -41
- data/ext/nix_io.c +0 -134
- data/ext/q_multi_phrase.c +0 -380
- data/ext/r_doc.c +0 -582
- data/ext/r_index_io.c +0 -1021
- data/ext/r_term.c +0 -219
- data/ext/term.c +0 -820
- data/ext/termdocs.c +0 -611
- data/ext/vector.c +0 -637
- data/ext/w32_io.c +0 -150
- data/lib/ferret/analysis.rb +0 -11
- data/lib/ferret/analysis/analyzers.rb +0 -112
- data/lib/ferret/analysis/standard_tokenizer.rb +0 -71
- data/lib/ferret/analysis/token.rb +0 -100
- data/lib/ferret/analysis/token_filters.rb +0 -86
- data/lib/ferret/analysis/token_stream.rb +0 -26
- data/lib/ferret/analysis/tokenizers.rb +0 -112
- data/lib/ferret/analysis/word_list_loader.rb +0 -27
- data/lib/ferret/document/document.rb +0 -152
- data/lib/ferret/document/field.rb +0 -312
- data/lib/ferret/index/compound_file_io.rb +0 -338
- data/lib/ferret/index/document_writer.rb +0 -289
- data/lib/ferret/index/field_infos.rb +0 -279
- data/lib/ferret/index/fields_io.rb +0 -181
- data/lib/ferret/index/index.rb +0 -675
- data/lib/ferret/index/index_file_names.rb +0 -33
- data/lib/ferret/index/index_reader.rb +0 -503
- data/lib/ferret/index/index_writer.rb +0 -534
- data/lib/ferret/index/multi_reader.rb +0 -377
- data/lib/ferret/index/multiple_term_doc_pos_enum.rb +0 -98
- data/lib/ferret/index/segment_infos.rb +0 -130
- data/lib/ferret/index/segment_merge_info.rb +0 -49
- data/lib/ferret/index/segment_merge_queue.rb +0 -16
- data/lib/ferret/index/segment_merger.rb +0 -358
- data/lib/ferret/index/segment_reader.rb +0 -412
- data/lib/ferret/index/segment_term_enum.rb +0 -169
- data/lib/ferret/index/segment_term_vector.rb +0 -58
- data/lib/ferret/index/term.rb +0 -53
- data/lib/ferret/index/term_buffer.rb +0 -83
- data/lib/ferret/index/term_doc_enum.rb +0 -291
- data/lib/ferret/index/term_enum.rb +0 -52
- data/lib/ferret/index/term_info.rb +0 -37
- data/lib/ferret/index/term_infos_io.rb +0 -321
- data/lib/ferret/index/term_vector_offset_info.rb +0 -20
- data/lib/ferret/index/term_vectors_io.rb +0 -553
- data/lib/ferret/query_parser.rb +0 -312
- data/lib/ferret/query_parser/query_parser.tab.rb +0 -928
- data/lib/ferret/search.rb +0 -50
- data/lib/ferret/search/boolean_clause.rb +0 -100
- data/lib/ferret/search/boolean_query.rb +0 -299
- data/lib/ferret/search/boolean_scorer.rb +0 -294
- data/lib/ferret/search/caching_wrapper_filter.rb +0 -40
- data/lib/ferret/search/conjunction_scorer.rb +0 -99
- data/lib/ferret/search/disjunction_sum_scorer.rb +0 -205
- data/lib/ferret/search/exact_phrase_scorer.rb +0 -32
- data/lib/ferret/search/explanation.rb +0 -41
- data/lib/ferret/search/field_cache.rb +0 -215
- data/lib/ferret/search/field_doc.rb +0 -31
- data/lib/ferret/search/field_sorted_hit_queue.rb +0 -184
- data/lib/ferret/search/filter.rb +0 -11
- data/lib/ferret/search/filtered_query.rb +0 -130
- data/lib/ferret/search/filtered_term_enum.rb +0 -79
- data/lib/ferret/search/fuzzy_query.rb +0 -154
- data/lib/ferret/search/fuzzy_term_enum.rb +0 -247
- data/lib/ferret/search/hit_collector.rb +0 -34
- data/lib/ferret/search/hit_queue.rb +0 -11
- data/lib/ferret/search/index_searcher.rb +0 -200
- data/lib/ferret/search/match_all_query.rb +0 -104
- data/lib/ferret/search/multi_phrase_query.rb +0 -216
- data/lib/ferret/search/multi_searcher.rb +0 -261
- data/lib/ferret/search/multi_term_query.rb +0 -65
- data/lib/ferret/search/non_matching_scorer.rb +0 -22
- data/lib/ferret/search/phrase_positions.rb +0 -55
- data/lib/ferret/search/phrase_query.rb +0 -214
- data/lib/ferret/search/phrase_scorer.rb +0 -152
- data/lib/ferret/search/prefix_query.rb +0 -54
- data/lib/ferret/search/query.rb +0 -140
- data/lib/ferret/search/query_filter.rb +0 -51
- data/lib/ferret/search/range_filter.rb +0 -103
- data/lib/ferret/search/range_query.rb +0 -139
- data/lib/ferret/search/req_excl_scorer.rb +0 -125
- data/lib/ferret/search/req_opt_sum_scorer.rb +0 -70
- data/lib/ferret/search/score_doc.rb +0 -38
- data/lib/ferret/search/score_doc_comparator.rb +0 -114
- data/lib/ferret/search/scorer.rb +0 -91
- data/lib/ferret/search/similarity.rb +0 -278
- data/lib/ferret/search/sloppy_phrase_scorer.rb +0 -47
- data/lib/ferret/search/sort.rb +0 -112
- data/lib/ferret/search/sort_comparator.rb +0 -60
- data/lib/ferret/search/sort_field.rb +0 -91
- data/lib/ferret/search/spans.rb +0 -12
- data/lib/ferret/search/spans/near_spans_enum.rb +0 -304
- data/lib/ferret/search/spans/span_first_query.rb +0 -79
- data/lib/ferret/search/spans/span_near_query.rb +0 -108
- data/lib/ferret/search/spans/span_not_query.rb +0 -130
- data/lib/ferret/search/spans/span_or_query.rb +0 -176
- data/lib/ferret/search/spans/span_query.rb +0 -25
- data/lib/ferret/search/spans/span_scorer.rb +0 -74
- data/lib/ferret/search/spans/span_term_query.rb +0 -105
- data/lib/ferret/search/spans/span_weight.rb +0 -84
- data/lib/ferret/search/spans/spans_enum.rb +0 -44
- data/lib/ferret/search/term_query.rb +0 -128
- data/lib/ferret/search/term_scorer.rb +0 -183
- data/lib/ferret/search/top_docs.rb +0 -36
- data/lib/ferret/search/top_field_docs.rb +0 -17
- data/lib/ferret/search/weight.rb +0 -54
- data/lib/ferret/search/wildcard_query.rb +0 -26
- data/lib/ferret/search/wildcard_term_enum.rb +0 -61
- data/lib/ferret/stemmers.rb +0 -1
- data/lib/ferret/stemmers/porter_stemmer.rb +0 -218
- data/lib/ferret/store.rb +0 -5
- data/lib/ferret/store/buffered_index_io.rb +0 -190
- data/lib/ferret/store/directory.rb +0 -141
- data/lib/ferret/store/fs_store.rb +0 -381
- data/lib/ferret/store/index_io.rb +0 -245
- data/lib/ferret/store/ram_store.rb +0 -286
- data/lib/ferret/utils.rb +0 -8
- data/lib/ferret/utils/bit_vector.rb +0 -123
- data/lib/ferret/utils/date_tools.rb +0 -138
- data/lib/ferret/utils/number_tools.rb +0 -91
- data/lib/ferret/utils/parameter.rb +0 -41
- data/lib/ferret/utils/priority_queue.rb +0 -120
- data/lib/ferret/utils/string_helper.rb +0 -47
- data/lib/ferret/utils/thread_local.rb +0 -28
- data/lib/ferret/utils/weak_key_hash.rb +0 -60
- data/lib/rferret.rb +0 -37
- data/rake_utils/code_statistics.rb +0 -106
- data/test/benchmark/tb_ram_store.rb +0 -76
- data/test/benchmark/tb_rw_vint.rb +0 -26
- data/test/functional/thread_safety_index_test.rb +0 -81
- data/test/functional/thread_safety_test.rb +0 -137
- data/test/longrunning/tc_numbertools.rb +0 -60
- data/test/longrunning/tm_store.rb +0 -19
- data/test/unit/analysis/ctc_analyzer.rb +0 -532
- data/test/unit/analysis/data/wordfile +0 -6
- data/test/unit/analysis/rtc_letter_tokenizer.rb +0 -20
- data/test/unit/analysis/rtc_lower_case_filter.rb +0 -20
- data/test/unit/analysis/rtc_lower_case_tokenizer.rb +0 -27
- data/test/unit/analysis/rtc_per_field_analyzer_wrapper.rb +0 -39
- data/test/unit/analysis/rtc_porter_stem_filter.rb +0 -16
- data/test/unit/analysis/rtc_standard_analyzer.rb +0 -20
- data/test/unit/analysis/rtc_standard_tokenizer.rb +0 -20
- data/test/unit/analysis/rtc_stop_analyzer.rb +0 -20
- data/test/unit/analysis/rtc_stop_filter.rb +0 -14
- data/test/unit/analysis/rtc_white_space_analyzer.rb +0 -21
- data/test/unit/analysis/rtc_white_space_tokenizer.rb +0 -20
- data/test/unit/analysis/rtc_word_list_loader.rb +0 -32
- data/test/unit/analysis/tc_token.rb +0 -25
- data/test/unit/document/rtc_field.rb +0 -28
- data/test/unit/document/tc_document.rb +0 -47
- data/test/unit/document/tc_field.rb +0 -98
- data/test/unit/index/rtc_compound_file_io.rb +0 -107
- data/test/unit/index/rtc_field_infos.rb +0 -127
- data/test/unit/index/rtc_fields_io.rb +0 -167
- data/test/unit/index/rtc_multiple_term_doc_pos_enum.rb +0 -83
- data/test/unit/index/rtc_segment_infos.rb +0 -74
- data/test/unit/index/rtc_segment_term_docs.rb +0 -17
- data/test/unit/index/rtc_segment_term_enum.rb +0 -60
- data/test/unit/index/rtc_segment_term_vector.rb +0 -71
- data/test/unit/index/rtc_term_buffer.rb +0 -57
- data/test/unit/index/rtc_term_info.rb +0 -19
- data/test/unit/index/rtc_term_infos_io.rb +0 -192
- data/test/unit/index/rtc_term_vectors_io.rb +0 -108
- data/test/unit/index/tc_term.rb +0 -27
- data/test/unit/index/tc_term_voi.rb +0 -18
- data/test/unit/search/rtc_similarity.rb +0 -37
- data/test/unit/search/rtc_sort_field.rb +0 -14
- data/test/unit/search/tc_multi_searcher2.rb +0 -126
- data/test/unit/store/rtc_fs_store.rb +0 -62
- data/test/unit/store/rtc_ram_store.rb +0 -15
- data/test/unit/store/rtm_store.rb +0 -150
- data/test/unit/store/rtm_store_lock.rb +0 -2
- data/test/unit/ts_document.rb +0 -2
- data/test/unit/utils/rtc_bit_vector.rb +0 -73
- data/test/unit/utils/rtc_date_tools.rb +0 -50
- data/test/unit/utils/rtc_number_tools.rb +0 -59
- data/test/unit/utils/rtc_parameter.rb +0 -40
- data/test/unit/utils/rtc_priority_queue.rb +0 -62
- data/test/unit/utils/rtc_string_helper.rb +0 -21
- data/test/unit/utils/rtc_thread.rb +0 -61
- data/test/unit/utils/rtc_weak_key_hash.rb +0 -25
- 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(
|
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(
|
105
|
-
:
|
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
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
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
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
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
|
-
|
138
|
-
|
139
|
-
|
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
|
-
|
143
|
-
|
146
|
+
parser = Ferret::QueryParser.new(:default_field => "xxx",
|
147
|
+
:fields => ["xxx", "key"],
|
148
|
+
:analyzer => WhiteSpaceAnalyzer.new)
|
144
149
|
|
145
|
-
|
146
|
-
|
147
|
-
|
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(
|
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(
|
160
|
-
|
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(
|
169
|
-
|
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
|
-
|
24
|
-
{
|
25
|
-
{
|
26
|
-
{
|
27
|
-
{
|
28
|
-
{
|
29
|
-
{
|
30
|
-
{
|
31
|
-
{
|
32
|
-
{
|
33
|
-
{
|
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(
|
44
|
-
top_docs =
|
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.
|
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.
|
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
|
-
|
53
|
+
searcher = Searcher.new(@dir)
|
54
54
|
q = MatchAllQuery.new()
|
55
|
-
rf = RangeFilter.new(
|
56
|
-
do_test_top_docs(
|
57
|
-
rf = RangeFilter.new(
|
58
|
-
do_test_top_docs(
|
59
|
-
rf = RangeFilter.new(
|
60
|
-
do_test_top_docs(
|
61
|
-
rf = RangeFilter.new(
|
62
|
-
do_test_top_docs(
|
63
|
-
rf = RangeFilter.
|
64
|
-
do_test_top_docs(
|
65
|
-
rf = RangeFilter.
|
66
|
-
do_test_top_docs(
|
67
|
-
rf = RangeFilter.
|
68
|
-
do_test_top_docs(
|
69
|
-
rf = RangeFilter.
|
70
|
-
do_test_top_docs(
|
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(
|
75
|
-
assert_raise(ArgumentError) {f = RangeFilter.new(
|
76
|
-
assert_raise(ArgumentError) {f = RangeFilter.new(
|
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
|
-
|
80
|
+
searcher = Searcher.new(@dir)
|
82
81
|
q = MatchAllQuery.new()
|
83
|
-
qf = QueryFilter.new(TermQuery.new(
|
84
|
-
do_test_top_docs(
|
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(
|
87
|
-
qf = QueryFilter.new(TermQuery.new(
|
88
|
-
do_test_top_docs(
|
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
|
-
|
91
|
+
searcher = Searcher.new(@dir)
|
93
92
|
q = MatchAllQuery.new()
|
94
|
-
rf = RangeFilter.new(
|
93
|
+
rf = RangeFilter.new(:int, :>= => "2", :<= => "6")
|
95
94
|
rq = FilteredQuery.new(q, rf)
|
96
|
-
qf = QueryFilter.new(TermQuery.new(
|
97
|
-
do_test_top_docs(
|
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.
|
100
|
-
do_test_top_docs(
|
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
|
-
|
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.
|
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.
|
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(
|
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(
|
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 =
|
55
|
+
is = Searcher.new(@dir)
|
57
56
|
|
58
|
-
fq = FuzzyQuery.new(
|
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(
|
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(
|
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 =
|
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(
|
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)
|
134
|
-
|
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
|
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(
|
13
|
-
|
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
|
-
@
|
20
|
+
@searcher = Searcher.new(@dir)
|
17
21
|
end
|
18
22
|
|
19
23
|
def tear_down()
|
20
|
-
@
|
24
|
+
@searcher.close
|
21
25
|
@dir.close()
|
22
26
|
end
|
23
27
|
|
24
|
-
def get_docs(
|
28
|
+
def get_docs(hits)
|
25
29
|
docs = []
|
26
|
-
|
27
|
-
docs <<
|
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 = @
|
34
|
-
assert_equal(expected.length, top_docs.
|
35
|
-
assert_equal(top, top_docs.
|
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.
|
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 =~ @
|
45
|
-
"Scores(#{score_doc.score} != #{@
|
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, @
|
60
|
-
assert_equal("20050930", @
|
61
|
-
assert_equal("cat1/sub2/subsub2", @
|
62
|
-
assert_equal("20051012", @
|
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
|