1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2010 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 \brief test various search attributes */
25 const char *myrec[] = {
26 "<gils>\n<title>My title</title>\n"
27 " <abstract>test record with single coordset, negatives</abstract>\n"
28 " <Spatial-Domain><Bounding-Coordinates>\n"
29 " <West-Bounding-Coordinate> -120 </West-Bounding-Coordinate>\n"
30 " <East-Bounding-Coordinate> -102 </East-Bounding-Coordinate>\n"
31 " <North-Bounding-Coordinate> 49 </North-Bounding-Coordinate>\n"
32 " <South-Bounding-Coordinate> 31 </South-Bounding-Coordinate>\n"
33 " </Bounding-Coordinates></Spatial-Domain>\n"
36 "<gils>\n<title>My x title</title>\n"
37 " <abstract>second test with two coord sets</abstract>\n"
38 " <Spatial-Domain><Bounding-Coordinates>\n"
39 " <West-Bounding-Coordinate> -120 </West-Bounding-Coordinate>\n"
40 " <East-Bounding-Coordinate> -102 </East-Bounding-Coordinate>\n"
41 " <North-Bounding-Coordinate> 49 </North-Bounding-Coordinate>\n"
42 " <South-Bounding-Coordinate> 31 </South-Bounding-Coordinate>\n"
43 " </Bounding-Coordinates>"
44 " <Bounding-Coordinates>\n"
45 " <West-Bounding-Coordinate> -125 </West-Bounding-Coordinate>\n"
46 " <East-Bounding-Coordinate> -108 </East-Bounding-Coordinate>\n"
47 " <North-Bounding-Coordinate> 41 </North-Bounding-Coordinate>\n"
48 " <South-Bounding-Coordinate> 25 </South-Bounding-Coordinate>\n"
49 " </Bounding-Coordinates></Spatial-Domain>\n"
52 "<gils>\n<title>My title x</title><abstract>a b c c c a y</abstract>\n</gils>\n" ,
53 "<gils>\n<title>test</title><abstract>a1 a2 c a1 a2 a3</abstract>\n</gils>\n" ,
56 " <date>2107-09-19 00:00:00</date>\n"
61 static void tst(int argc, char **argv)
63 ZebraService zs = tl_start_up(0, argc, argv);
64 ZebraHandle zh = zebra_open(zs, 0);
66 YAZ_CHECK(tl_init_data(zh, myrec));
69 YAZ_CHECK(tl_query(zh, "@attr 1=4 notfound", 0));
70 YAZ_CHECK(tl_query(zh, "@attr 1=4 title", 3));
71 YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::title:w",
76 "term 2 2: x\n"), ZEBRA_OK);
78 YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::title:s",
81 "term 1 1: my title\n"
82 "term 1 1: my title x\n"
83 "term 1 1: my x title\n"), ZEBRA_OK);
86 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=1 titl", 3));
88 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=1 x", 2));
89 YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::title:w",
94 "term 2 2: x\n"), ZEBRA_OK);
97 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=2 titl", 0));
98 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=2 x", 2));
99 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=2 le", 3));
101 /* trunc left&right */
102 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=3 titl", 3));
103 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=3 x", 2));
104 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=3 le", 3));
107 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=100 titl", 0));
108 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=100 x", 2));
109 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=100 le", 0));
111 /* trunc: process # in term */
112 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=101 titl", 0));
113 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=101 x", 2));
114 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=101 le", 0));
115 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=101 #le", 3));
118 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=102 titl", 0));
119 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=102 x", 2));
120 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=102 le", 0));
121 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=102 .*le", 3));
124 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 titl", 3));
125 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 titlx", 3));
126 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 titlxx", 0));
127 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 x", 2));
128 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 le", 0));
129 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=103 .*le", 3));
131 /* trunc: CCL #=. ?=.* (?[0-9] = n times .) */
132 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 titl", 0));
133 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 tit#e", 3));
134 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 x", 2));
135 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 le", 0));
136 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 ?le", 3));
137 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 ?1le", 0));
138 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 ?2le", 0));
139 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=104 ?3le", 3));
141 /* trunc: * = .* ! = . and right truncate */
142 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=105 titl", 3));
143 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=105 tit!e", 3));
144 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=105 x", 2));
145 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=105 le", 0));
146 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=105 *le", 3));
148 /* trunc: * = .* ! = . and do not truncate */
149 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=106 titl", 0));
150 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=106 tit!e", 3));
151 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=106 x", 2));
152 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=106 le", 0));
153 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 5=106 *le", 3));
155 /* string relations, < */
156 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=1 0", 0));
157 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=1 my", 0));
159 /* string relations, <= */
160 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=2 my", 3));
161 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=2 mn", 0));
164 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=3 my", 3));
166 /* string relations, >= */
167 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=4 x", 2));
168 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=4 tu", 2));
169 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=4 title", 3));
171 /* string relations, > */
172 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=5 x", 0));
173 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=5 tu", 2));
174 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=5 title", 2));
176 /* always-matches relation */
177 YAZ_CHECK(tl_query(zh, "@attr 1=_ALLRECORDS @attr 2=103 {ym}", 5));
178 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 2=103 {x my}", 4));
179 YAZ_CHECK(tl_query_x(zh, "@attr 1=1 @attr 2=103 {x my}", 0, 114));
182 YAZ_CHECK(tl_query(zh, "@and @attr 1=4 notfound @attr 1=4 x", 0));
183 YAZ_CHECK(tl_query(zh, "@and @attr 1=4 x @attr 1=4 notfound", 0));
184 YAZ_CHECK(tl_query(zh, "@and @attr 1=4 notfound @attr 1=4 notfound", 0));
185 YAZ_CHECK(tl_query(zh, "@and @attr 1=4 x @attr 1=4 x", 2));
186 YAZ_CHECK(tl_query(zh, "@and @attr 1=4 x @attr 1=4 my", 2));
187 YAZ_CHECK(tl_query(zh, "@and @attr 1=4 my @attr 1=4 x", 2));
188 YAZ_CHECK(tl_query(zh, "@and @attr 1=4 my @attr 1=4 my", 3));
191 YAZ_CHECK(tl_query(zh, "@or @attr 1=4 notfound @attr 1=4 x", 2));
192 YAZ_CHECK(tl_query(zh, "@or @attr 1=4 x @attr 1=4 notfound", 2));
193 YAZ_CHECK(tl_query(zh, "@or @attr 1=4 notfound @attr 1=4 notfound", 0));
194 YAZ_CHECK(tl_query(zh, "@or @attr 1=4 x @attr 1=4 x", 2));
195 YAZ_CHECK(tl_query(zh, "@or @attr 1=4 x @attr 1=4 my", 3));
196 YAZ_CHECK(tl_query(zh, "@or @attr 1=4 my @attr 1=4 x", 3));
197 YAZ_CHECK(tl_query(zh, "@or @attr 1=4 my @attr 1=4 my", 3));
201 YAZ_CHECK(tl_query(zh, "@not @attr 1=4 notfound @attr 1=4 x", 0));
202 YAZ_CHECK(tl_query(zh, "@not @attr 1=4 x @attr 1=4 x", 0));
203 YAZ_CHECK(tl_query(zh, "@not @attr 1=4 my @attr 1=4 x", 1));
204 YAZ_CHECK(tl_query(zh, "@not @attr 1=4 my @attr 1=4 notfound", 3));
205 YAZ_CHECK(tl_query(zh, "@not @attr 1=4 notfound @attr 1=4 notfound", 0));
207 /* phrase searches */
208 YAZ_CHECK(tl_query(zh, "@attr 1=4 my", 3));
209 YAZ_CHECK(tl_query(zh, "@attr 1=4 {my x}", 1));
210 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=1 {my x}", 1));
211 YAZ_CHECK(tl_query(zh, "@attr 1=4 {my x}", 1));
212 YAZ_CHECK(tl_query(zh, "@attr 1=4 {x my}", 0));
213 YAZ_CHECK(tl_query(zh, "@attr 1=4 {my x title}", 1));
214 YAZ_CHECK(tl_query(zh, "@attr 1=4 {my title}", 2));
216 /* and-list searches */
217 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=6 {x my}", 2));
218 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=6 {my x}", 2));
219 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=6 {my my}", 3));
220 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=6 {e x}", 0));
222 /* or-list searches */
223 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=105 {x my}", 3));
224 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=105 {my x}", 3));
225 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=105 {my my}", 3));
226 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=105 {e x}", 2));
227 YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=106 {e x}", 2));
229 /* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */
230 YAZ_CHECK(tl_query(zh, "@attr 1=4 @prox 0 2 1 2 k 2 my x", 2));
232 /* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */
233 YAZ_CHECK(tl_query(zh, "@attr 1=4 @prox 0 2 1 2 k 2 x my", 0));
235 /* exl=0 distance=2 order=0 relation=2 (<=), known, unit=word */
236 YAZ_CHECK(tl_query(zh, "@attr 1=4 @prox 0 2 0 2 k 2 x my", 2));
238 /* exl=0 distance=2 order=0 relation=3 (=), known, unit=word */
239 YAZ_CHECK(tl_query(zh, "@attr 1=4 @prox 0 2 1 3 k 2 my x", 1));
241 /* exl=1 distance=2 order=0 relation=3 (=), known, unit=word */
242 YAZ_CHECK(tl_query(zh, "@attr 1=4 @prox 1 2 1 3 k 2 my x", 1));
244 /* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */
245 YAZ_CHECK(tl_query(zh, "@attr 1=1016 @prox 0 2 1 2 k 2 a y", 1));
247 /* exl=0 distance=1 order=1 relation=3 (=), known, unit=word */
248 YAZ_CHECK(tl_query(zh, "@attr 1=1016 @prox 0 1 1 3 k 2 a b", 1));
251 /* exl=0 distance=1 order=1 relation=3 (=), known, unit=word */
252 YAZ_CHECK(tl_query(zh, "@attr 1=1016 @prox 0 1 1 3 k 2 c a", 1));
253 /* exl=0 distance=1 order=1 relation=2 (<=), known, unit=word */
254 YAZ_CHECK(tl_query(zh, "@attr 1=1016 @prox 0 1 1 2 k 2 c a", 1));
256 /* exl=0 distance=1 order=1 relation=2 (<=), known, unit=word */
257 YAZ_CHECK(tl_query(zh, "@attr 1=1016 @prox 0 1 1 2 k 2 @prox 0 1 1 2 k 2 a1 a2 a3", 1));
258 YAZ_CHECK(tl_query(zh, "@attr 1=1016 @prox 0 1 1 3 k 2 @prox 0 1 1 3 k 2 a1 a2 a3", 1));
260 /* 3 term @prox test.. */
261 YAZ_CHECK(tl_query(zh, "@attr 1=1016 \"a b c\"", 1));
263 /* exl=0 distance=1 order=1 relation=2 (<=), known, unit=word */
264 /* right associative (does not work, so zero hits) */
265 YAZ_CHECK(tl_query(zh, "@attr 1=1016 @prox 0 1 1 2 k 2 a @prox 0 1 1 2 k 2 b c", 0));
266 /* left associative (works fine) */
267 YAZ_CHECK(tl_query(zh, "@attr 1=1016 @prox 0 1 1 2 k 2 @prox 0 1 1 2 k 2 a b c", 1));
269 /* exl=0 distance=1 order=1 relation=3 (=), known, unit=word */
270 /* right associative (does not work, so zero hits) */
271 YAZ_CHECK(tl_query(zh, "@attr 1=1016 @prox 0 1 1 3 k 2 a @prox 0 1 1 3 k 2 b c", 0));
272 /* left associative (works fine) */
273 YAZ_CHECK(tl_query(zh, "@attr 1=1016 @prox 0 1 1 3 k 2 @prox 0 1 1 3 k 2 a b c", 1));
275 /* Non-indexed numeric use, but specified in bib1.att (bug #1142) */
276 YAZ_CHECK(tl_query_x(zh, "@attr 1=1000 x", 0, 114));
277 YAZ_CHECK(tl_query_x(zh, "@attr 1=1000 @attr 14=0 x", 0, 114));
278 YAZ_CHECK(tl_query_x(zh, "@attr 1=1000 @attr 14=1 x", 0, 0));
279 /* Non-indexed numeric use and unspecified in bib1.att */
280 YAZ_CHECK(tl_query_x(zh, "@attr 1=999 x", 0, 114));
281 YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 14=1 x", 0, 114));
282 /* Non-indexed string use attribute */
283 YAZ_CHECK(tl_query_x(zh, "@attr 1=gyf x", 0, 114));
284 YAZ_CHECK(tl_query_x(zh, "@attr 1=gyf @attr 14=0 x", 0, 114));
285 YAZ_CHECK(tl_query_x(zh, "@attr 1=gyf @attr 14=1 x", 0, 0));
287 /* provoke unsupported use attribute */
288 YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 4=1 x", 0, 114));
289 YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 4=6 x", 0, 114));
290 YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 4=105 x", 0, 114));
291 YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 4=109 123", 0, 114));
292 YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.840.10003.3.1 @attr 1=999 x",
294 /* provoke unsupported attribute set */
295 YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.8 @attr 1=999 @attr 4=1 x", 0, 121));
296 YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.8 @attr 1=999 @attr 4=6 x", 0,
298 YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.8 @attr 1=999 @attr 4=105 x", 0,
300 YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.8 @attr 1=999 @attr 4=109 123",
303 /* provoke unsupported relation */
304 YAZ_CHECK(tl_query_x(zh, "@attr 1=4 @attr 2=6 x", 0, 117));
305 YAZ_CHECK(tl_query_x(zh, "@attr 1=1016 @attr 2=6 @attr 4=109 x", 0, 114));
307 /* position , phrase searches */
308 YAZ_CHECK(tl_query(zh, "@attr 3=1 title", 0));
309 YAZ_CHECK(tl_query(zh, "@attr 3=1 my", 3));
311 YAZ_CHECK(tl_query(zh, "@attr 3=1 {my title}", 2));
312 YAZ_CHECK(tl_query(zh, "@attr 4=1 @attr 3=1 {my title}", 2));
314 YAZ_CHECK(tl_query(zh, "@attr 3=1 {title my}", 0));
315 YAZ_CHECK(tl_query(zh, "@attr 4=1 @attr 3=1 {title my}", 0));
317 YAZ_CHECK(tl_query(zh, "@attr 4=1 @attr 3=1 {title my}", 0));
319 /* position , or-list */
320 YAZ_CHECK(tl_query(zh, "@attr 4=105 @attr 3=1 {title my}", 3));
321 YAZ_CHECK(tl_query(zh, "@attr 4=105 @attr 3=1 {title x}", 0));
323 /* position, and-list */
324 YAZ_CHECK(tl_query(zh, "@attr 4=6 @attr 3=1 {title my}", 0));
325 YAZ_CHECK(tl_query(zh, "@attr 4=6 @attr 3=1 {title x}", 0));
326 YAZ_CHECK(tl_query(zh, "@attr 4=6 @attr 3=1 my", 3));
329 /* 1=2038: West-Bounding-Coordinate 2039: East: 2040: North: 2041 South*/
330 /* 4=109: numeric string */
331 /* 2=3: equal 2=1: less, 2=4: greater or equal 2=5 greater */
333 /* N>=25, search attributes work */
334 YAZ_CHECK(tl_query(zh, "@attr 2=4 @attr gils 1=2040 @attr 4=109 25", 2));
336 /* N>49, search attributes work */
337 YAZ_CHECK(tl_query(zh, "@attr 2=5 @attr gils 1=2040 @attr 4=109 49", 0));
339 /* N>=49, search attributes work */
340 YAZ_CHECK(tl_query(zh, "@attr 2=4 @attr gils 1=2040 @attr 4=109 49", 2));
342 /* N>48, search attributes work */
343 YAZ_CHECK(tl_query(zh, "@attr 2=5 @attr gils 1=2040 @attr 4=109 48", 2));
345 /* N<48, search attributes work */
346 YAZ_CHECK(tl_query(zh, "@attr 2=1 @attr gils 1=2040 @attr 4=109 48", 1));
348 /* N<=48, search attributes work */
349 YAZ_CHECK(tl_query(zh, "@attr 2=2 @attr gils 1=2040 @attr 4=109 48", 1));
351 /* N=41, get rec1 only */
352 YAZ_CHECK(tl_query(zh, "@attr 2=3 @attr gils 1=2040 @attr 4=109 41", 1));
354 /* N=49, get both records */
355 YAZ_CHECK(tl_query(zh, "@attr 2=3 @attr gils 1=2040 @attr 4=109 49", 2));
357 /* W=-120 get both records */
358 YAZ_CHECK(tl_query(zh, "@attr 2=3 @attr gils 1=2038 @attr 4=109 -120", 2));
360 /* W<-122 get only rec1 */
361 YAZ_CHECK(tl_query(zh, "@attr 2=1 @attr gils 1=2038 @attr 4=109 '-120' ", 1));
363 /* N=41 and N=49 get only rec2 */
364 YAZ_CHECK(tl_query(zh, "@attr 2=3 @attr gils 1=2040 @attr 4=109 \"41 49\" ", 1));
368 YAZ_CHECK(tl_query(zh, "@attr 1=30 @attr 4=5 @attr 2=3 {2107-09-19 00:00:00}", 1));
370 YAZ_CHECK(tl_query(zh, "@attr 1=30 @attr 4=5 @attr 2=1 {2107-09-19 00:00:00}", 0));
372 YAZ_CHECK(tl_query(zh, "@attr 1=30 @attr 4=5 @attr 2=2 {2107-09-19 00:00:00}", 1));
374 YAZ_CHECK(tl_query(zh, "@attr 1=30 @attr 4=5 @attr 2=4 {2107-09-19 00:00:00}", 1));
376 YAZ_CHECK(tl_query(zh, "@attr 1=30 @attr 4=5 @attr 2=5 {2107-09-19 00:00:00}", 0));
379 YAZ_CHECK(tl_close_down(zh, zs));
387 * c-file-style: "Stroustrup"
388 * indent-tabs-mode: nil
390 * vim: shiftwidth=4 tabstop=8 expandtab