Debian Codegraph @

test/t_factors

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/bin/sh
2 # Part of the ht://Dig package <http://www.htdig.org/>
3 # Copyright (c) 1999-2004 The ht://Dig Group
4 # For copyright details, see the file COPYING in your distribution
5 # or the GNU Library General Public License (LGPL) version 2 or later
6 # <http://www.gnu.org/copyleft/lgpl.html>
7 #
8 # $Id: t_factors,v 1.7 2004/06/05 06:26:22 lha Exp $
9 #
10
11 # Tests (or should eventually test) the following config attributes:
12 # author_factor
13 # backlink_factor
14 # caps_factor
15 # date_factor (TODO)
16 # description_factor
17 # heading_factor
18 # keywords_factor
19 # meta_description_factor
20 # multimatch_factor
21 # search_results_order
22 # text_factor
23 # title_factor
24 # url_seed_score
25 # url_text_factor
26
27 # try_order comment query pattern1 patern2 ...
28 # comment - description of test, displayed if error occurs
29 # query - search string passed to htsearch
30 # pattern - strings expected to occur *in order* in the output
31 try_order() {
32 comment="$1"
33 shift
34 query="$1"
35 shift
36 $htsearch -c $config "$query" > $tmp 2> /dev/null
37 array=""
38 for pattern
39 do
40 array="$array; array[i++] = "\"$pattern\"
41 done
42 miss=`$awk "BEGIN {$array; line = 0; } \
43 "'$0'" ~ \".*\"array[line] { line++ } \
44 END { print array[line] } " < $tmp `
45 if [ "$miss" != "" ]
46 then
47 $htsearch -vv -c $config "$query" > /dev/null
48 echo "String \"$miss\" was not found where expected"
49 fail "$htsearch -c $config '$query' >> $tmp --
50 $comment"
51 fi
52 }
53
54
55
56
57 test_functions_action=--start-apache
58 . ./test_functions
59
60 config=$testdir/conf/htdig.conf.tmp
61 tmp=/tmp/t_htsearch$$
62
63 # set up config file with chosen non-default values
64 cp $testdir/conf/htdig.conf $config
65
66 $htdig "$@" -t -i -c $config || fail "Couldn't dig"
67 $htpurge -c $config || fail "Couldn't purge"
68
69 try_order "Search for 'also'" \
70 "words=also" \
71 '4 matches' 'site2.html' 'site4.html' 'bad_local.htm' 'script.html'
72
73 set_attr url_seed_score "site4 *1000+1000"
74 try_order "Seed score 1000 for site4.html" \
75 "words=also" \
76 '4 matches' 'site4.html' 'site2.html' 'bad_local.htm' 'script.html'
77
78 set_attr url_seed_score "site4 *1000+1000 script *1000+1000"
79 try_order "Seed score 1000 for site4.html and script.html" \
80 "words=also" \
81 '4 matches' 'site4.html' 'script.html' 'site2.html' 'bad_local.htm'
82
83 set_attr url_seed_score "site4|script *1000+1000"
84 try_order "Seed score 1000 for site4|script" \
85 "words=also" \
86 '4 matches' 'site4.html' 'script.html' 'site2.html' 'bad_local.htm'
87
88 set_attr search_results_order "bad_local"
89 try_order "Search_results_order bad_local" \
90 "words=also" \
91 '4 matches' 'bad_local.htm' 'site4.html' 'script.html' 'site2.html'
92
93 set_attr search_results_order "script * e2|e4"
94 try_order "Search_results_order * script e2|e4" \
95 "words=also" \
96 '4 matches' 'script.html' 'bad_local.htm' 'site4.html' 'site2.html'
97
98 set_attr url_seed_score ""
99 set_attr search_results_order ""
100 set_attr author_factor 0
101 set_attr backlink_factor 0
102 set_attr caps_factor 0 # not implemented
103 set_attr date_factor 0 # TODO
104 set_attr description_factor 0
105 set_attr heading_factor 0
106 set_attr keywords_factor 0
107 set_attr meta_description_factor 0
108 set_attr multimatch_factor 0
109 set_attr text_factor 0
110 set_attr title_factor 0
111 set_attr url_text_factor 0 # not implemented
112
113 try_order "Search with factors 0" \
114 "words=also" \
115 'No matches'
116
117 try_order "Search for 'service' with title_factor 0" \
118 "words=service" \
119 'No matches'
120 set_attr title_factor 1
121 try_order "Search for 'service' with title_factor 1" \
122 "words=service" \
123 '1 matches' 'script.html'
124 set_attr text_factor 0.3
125 try_order "Greater weight to title factor" \
126 "words=service" \
127 '4 matches' 'script.html' 'site4.html' 'site%201.html' 'site3.html'
128 set_attr title_factor -3.2
129 try_order "Checking negative title factor" \
130 "words=service" \
131 '4 matches' 'site4.html' 'site%201.html' 'site3.html' 'script.html'
132 set_attr title_factor 0
133 set_attr text_factor 0
134
135 # test with all factors 0 except the one which matches
136
137 set_attr description_factor 1
138 try_order "Search for 'crossRef' with description_factor 1" \
139 "words=crossRef" \
140 '1 matches' 'site%201.html'
141 set_attr description_factor 0
142
143 set_attr author_factor 1
144 try_order "Search for 'media' with author_factor 1" \
145 "words=media" \
146 '1 matches' 'script.html'
147 set_attr author_factor 0
148
149 set_attr meta_description_factor 1
150 try_order "Search for 'stars' with meta_description_factor 1" \
151 "words=stars" \
152 '1 matches' 'site2.html'
153 set_attr meta_description_factor 0
154
155 set_attr heading_factor 1
156 try_order "Search for 'obtain' with heading_factor 1" \
157 "words=obtain" \
158 '1 matches' 'bad_local.htm'
159 set_attr heading_factor 0
160
161 set_attr keywords_factor 1
162 try_order "Search for 'newWord' with keywords_factor 1" \
163 "words=newWord" \
164 '1 matches' 'title.html'
165 set_attr keywords_factor 0
166
167
168 # test with all document-based factors non-zero except the one which matches
169 set_attr author_factor 1
170 #set_attr backlink_factor 1 # not document based
171 set_attr caps_factor 1
172 #set_attr date_factor 1 # not document based
173 set_attr description_factor 1
174 set_attr heading_factor 1
175 set_attr keywords_factor 1
176 set_attr meta_description_factor 1
177 set_attr multimatch_factor 1
178 set_attr text_factor 1
179 set_attr title_factor 1
180 set_attr url_text_factor 1
181 set_attr description_factor 1
182
183 set_attr description_factor 0
184 try_order "Search for 'crossRef' with description_factor 0" \
185 "words=crossRef" \
186 '1 matches' 'title.html'
187 set_attr description_factor 1
188
189 set_attr author_factor 0
190 try_order "Search for 'media' with author_factor 0" \
191 "words=media" \
192 'No matches'
193 set_attr author_factor 1
194
195 set_attr meta_description_factor 0
196 try_order "Search for 'stars' with meta_description_factor 0" \
197 "words=stars" \
198 'No matches'
199 set_attr meta_description_factor 1
200
201 set_attr heading_factor 0
202 try_order "Search for 'obtain' with heading_factor 0" \
203 "words=obtain" \
204 'No matches'
205 set_attr heading_factor 1
206
207 set_attr keywords_factor 0
208 try_order "Search for 'newWord' with keywords_factor 0" \
209 "words=newWord" \
210 'No matches'
211 set_attr keywords_factor 1
212
213 # multimatch_factor gives a "boost" to searches matching multiple terms
214 set_attr title_factor 10 # "get" in title of bad_local
215 set_attr multimatch_factor 10000
216 try_order "Search for 'get or interest or repay' with multimatch_factor 10000" \
217 "words=get+interest+repay;method=or" \
218 '2 matches' 'site4.html' 'bad_local.htm'
219 set_attr multimatch_factor 0
220 try_order "Search for 'get or interest or repay' with multimatch_factor 0" \
221 "words=get+interest+repay;method=or" \
222 '2 matches' 'bad_local.htm' 'site4.html'
223
224 # backlink counts the number of references (of any type) to this document
225 set_attr backlink_factor 0
226 try_order "site4.html has repay+interest, site 1.html only has suggestions" \
227 "words=suggestions+repay+interest;method=or" \
228 '2 matches' 'site4.html' 'site%201.html'
229 set_attr backlink_factor 100
230 try_order "site 1.html has a higher ratio of backlinks to outgoing links" \
231 "words=suggestions+repay+interest;method=or" \
232 '2 matches' 'site%201.html' 'site4.html'
233
234 test_functions_action=--stop-apache
235 . ./test_functions