summaryrefslogtreecommitdiffstats
path: root/debian/htdig/htdig-3.2.0b6/test/t_fuzzy
blob: 6c28ceefccd70cf03a3022454e2674229e55ea9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/bin/sh
# Part of the ht://Dig package   <http://www.htdig.org/>
# Copyright (c) 1999-2004 The ht://Dig Group
# For copyright details, see the file COPYING in your distribution
# or the GNU Library General Public License (LGPL) version 2 or later
# <http://www.gnu.org/copyleft/lgpl.html>
#
# $Id: t_fuzzy,v 1.2 2004/05/28 13:15:30 lha Exp $
#

try() {
    comment="$1"
    shift
    query="$1"
    shift
    $htsearch -c $config "$query" > $tmp
    for pattern
    do
	if grep "$pattern" $tmp > /dev/null 
	then :
	else
	    $htsearch -vv -c $config "$query" > /dev/null
	    echo "Output doesn't match \"$pattern\""
	    fail "$htsearch -c $config '$query' >> $tmp --
		  $comment"
	fi
    done
}




test_functions_action=--start-apache
. ./test_functions

config=$testdir/conf/htdig.conf.tmp
tmp=/tmp/t_htsearch$$

databases="accents metaphone soundex synonym endings_root2word endings_word2root"

# set up config file with chosen non-default values
cp $testdir/conf/htdig.conf $config
for database in $databases; do
    set_attr ${database}_db "$testdir/var/htdig/test_${database}.db"
    rm -f $testdir/var/htdig/test_${database}.db
done
set_attr synonym_dictionary "$testdir/synonym_dict"
set_attr endings_affix_file "$testdir/dummy.affixes"
set_attr endings_dictionary "$testdir/dummy.stems"

# db.words.db needed by  htfuzzy, so dig before generating fuzzy databases
#set_attr locale fr
set_attr extra_word_characters çé
$htdig "$@" -t -i -c $config
$htpurge -c $config

# Check that databases can be generated
$htfuzzy -c $config accents soundex metaphone endings synonyms || fail "Error generating fuzzy database"

# Make sure databases put in correct locations
for database in $databases; do
    if [ ! -f $testdir/var/htdig/test_${database}.db ] ; then
	fail "htfuzzy didn't recognise ${database}_db attribute"
    fi
done

try "Search for '&aacute;lso' without search_algorithm=accents" \
    "words=álso;search_algorithm=exact" \
    'No matches'

try "Search for '&aacute;lso' with search_algorithm not in  allow_in_form" \
    "words=álso;search_algorithm=accents" \
    'No matches'

set_attr allow_in_form search_algorithm

try "Search for '&aacute;lso' with search_algorithm=accents" \
    "words=álso;search_algorithm=accents:0.1" \
    '4 matches' 'bad_local.htm' 'site2.html' 'script.html' 'site4.html' '<strong>also</strong>'

try "Search for 'francais' without search_algorithm=accents" \
    "words=francais;search_algorithm=exact:0.1" \
    'No matches'

#try "Search for '\"fran ais\"' with search_algorithm=accents" \
#    "words=%22fran+ais%22;search_algorithm=accents:1" \
#    '1 matches' 'site4.html'

try "Search for 'francais' with search_algorithm=accents" \
    "words=francais;search_algorithm=accents:0.1" \
    '1 matches' 'site4.html'

try "Search for 'quebec' without search_algorithm=accents" \
    "words=quebec;search_algorithm=exact:0.1" \
    'No matches'

try "Search for 'quebec' with search_algorithm=accents" \
    "words=quebec;search_algorithm=accents:0.1" \
    '1 matches' 'site4.html'




try "Search for 'accownt' without search_algorithm=soundex" \
    "words=accownt;search_algorithm=exact:1" \
    'No matches'

try "Search for 'accownt' with search_algorithm=soundex" \
    "words=accownt;search_algorithm=soundex:1" \
    '2 matches' 'script.html' 'site4.html' '<strong>account</strong>'

try "Search for 'accownt' with search_algorithm=metaphone" \
    "words=accownt;search_algorithm=metaphone:1" \
    '2 matches' 'script.html' 'site4.html' '<strong>account</strong>'




try "Search for 'zzyyxx' without search_algorithm=synonyms" \
    "words=zzyyxx;search_algorithm=exact:1" \
    'No matches'

try "Checking synonyms of the form   word-in-doc word-in-query" \
    "words=zzyyxx;search_algorithm=synonyms:1" \
    '1 matches' 'site3.html'

try "Search for 'xxyyzz' without search_algorithm=synonyms" \
    "words=xxyyzz;search_algorithm=exact:1" \
    'No matches'

try "Checking synonyms of the form   word-in-query word-in-doc" \
    "words=xxyyzz;search_algorithm=synonyms:1" \
    '1 matches' 'site3.html'

try "Search for 'xyzxyz' without search_algorithm=synonyms" \
    "words=xyzxyz;search_algorithm=exact:1" \
    'No matches'

try "Checking synonyms of the form   common-word word-in-query word-in-doc" \
    "words=xyzxyz;search_algorithm=synonyms:1" \
    '1 matches' 'site3.html'

try "Checking exact is used as a default if fuzzy rules yield no word" \
    "words=road;search_algorithm=synonyms:1" \
    '1 matches' 'site4.html' '<strong>Road</strong>'


try "Searching for 'copy' without 'endings'" \
    "words=copy;search_algorithm=exact:1" \
    'No matches'

try "Searching for 'copy' with 'endings'" \
    "words=copy;search_algorithm=endings:1" \
    '2 matches' 'bad_local.htm' 'site3.html' '<strong>Copyright</strong>'



try "Searching for 'univers*' without 'prefix'" \
    "words=univers*;search_algorithm=exact:1" \
    'No matches'

try "Searching for 'univers*' with 'prefix'" \
    "words=univers*;search_algorithm=prefix:1" \
    '2 matches' 'script.html' 'site4.html'

set_attr allow_in_form "search_algorithm max_prefix_matches min_prefix_length"
set_attr prefix_match_character "?"

try "Searching for 'res?' with 'prefix'" \
    "words=res?;search_algorithm=prefix:1;max_prefix_matches=100" \
    '3 matches' 'script.html' 'site3.html' 'site4.html' 'reserved' 'residency' 'residents' 'resources' 'respectively' 'response' 'restricted'

try "Searching for 'res?' with 'prefix', at most 2 prefixes" \
    "words=res?;search_algorithm=prefix:1;max_prefix_matches=2" \
    '2 matches' 'site3.html' 'site4.html' 'reserved' 'residency)'

set_attr prefix_match_character "etc"

try "Searching for 'resetc' with 'prefix', prefix_match_character=etc" \
    "words=resetc;search_algorithm=prefix:1;max_prefix_matches=2" \
    '2 matches' 'site3.html' 'site4.html' 'reserved' 'residency)'

set_attr minimum_prefix_length 4

# Check it doesn't count the prefix_match "character" as part of the
# "minimum_prefix_length"
try "Searching for 'resetc' with 'prefix', minimum prefix length 4" \
    "words=resetc;search_algorithm=prefix:1;max_prefix_matches=4" \
    'No matches'

set_attr prefix_match_character "?"

try "Searching for 'res?' with 'prefix', minimum prefix length 4" \
    "words=res?;search_algorithm=prefix:1;max_prefix_matches=100" \
    'No matches'






try "Searching for 'ili' without 'substring'" \
    "words=ili;search_algorithm=exact:1" \
    'No matches'

try "Searching for 'ili' with 'substring'" \
    "words=ili;search_algorithm=substring:1" \
    '2 matches' 'script.html' 'site4.html' '(affiliated' 'utilised)'

set_attr allow_in_form "search_algorithm substring_max_words"

try "Searching for 'ili' with 'substring', substring_max_words=3" \
    "words=ili;search_algorithm=substring:1;substring_max_words=3" \
    '2 matches' 'script.html' 'site4.html' 'eligibility)'



try "Searching for 'acccount' without 'speling'" \
    "words=acccount;search_algorithm=exact:1" \
    'No matches'

try "Searching for 'acccount' with 'speling'" \
    "words=acccount;search_algorithm=speling:1" \
    '2 matches' 'script.html' 'site4.html' '<strong>account</strong>'

try "Searching for 'accountx' with 'speling'" \
    "words=accountx;search_algorithm=speling:1" \
    '2 matches' 'script.html' 'site4.html' '<strong>account</strong>'


set_attr allow_in_form "search_algorithm minimum_speling_length"

try "Searching for 'accountx' with minimum_speling_length=9" \
    "words=accountx;search_algorithm=speling:1;minimum_speling_length=9" \
    'No matches'

try "Searching for 'accountx' with minimum_speling_length=8" \
    "words=accountx;search_algorithm=speling:1;minimum_speling_length=8" \
    '2 matches' 'script.html' 'site4.html' '<strong>account</strong>'





try "Searching for '.*vers[^a].*' without 'regex'" \
    "words=.*vers[^a].*;search_algorithm=exact:1" \
    'No matches'

set_attr extra_word_characters ".*[^]\\$"

try "Searching for '.*vers[^a].*' with 'regex'" \
    "words=.*vers[^a].*;search_algorithm=regex:1" \
    '3 matches' '(universities' 'versions)'

set_attr allow_in_form "search_algorithm regex_max_words"

try "Searching for '.*vers[^a].*' with 'regex', regex_max_words=3" \
    "words=.*vers[^a].*;search_algorithm=regex:1;regex_max_words=3" \
    '2 matches' '(universities' 'version)'




try "Searching for 'versi' without 'substring'" \
    "words=versi;search_algorithm=exact:1" \
    'No matches'

try "Searching for 'versi' with 'substring'" \
    "words=versi;search_algorithm=substring:1" \
    '3 matches' '(universities' 'versions)'

set_attr allow_in_form "search_algorithm substring_max_words"

try "Searching for 'versi' with 'substring', substring_max_words=3" \
    "words=versi;search_algorithm=substring:1;substring_max_words=3" \
    '2 matches' '(universities' 'version)'





for database in $databases; do
    rm -f $testdir/var/htdig/test_${database}.db
    try "Searching width $database database missing" \
        "words=account" \
	'2 matches'
done

test_functions_action=--stop-apache
. ./test_functions