1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2011 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 safari filter
31 "1234\n" /* ID first record */
32 /* chunk owner seq idx term */
33 "00024338 125060 0 1 any the\n"
34 "00024338 125060 0 2 any art\n"
35 "00024338 125060 0 3 any mand\n"
36 "s 00024338 125060 0 3 ti a b c\n"
38 "5678\n" /* other record - same owner id */
39 "00024339 125060 0 1 any den\n"
40 "00024339 125060 0 2 any gamle\n"
41 "00024339 125060 0 3 any mand\n"
42 "s 00024339 125060 0 3 ti d e f\n"
44 "5678\n" /* same record chunk id as before .. */
45 "00024339 125060 0 1 any the\n"
46 "00024339 125060 0 2 any gamle\n"
47 "00024339 125060 0 3 any mand\n"
48 "s 00024339 125060 0 3 ti g h i\n"
50 "1000\n" /* separate record */
51 "00024339 125061 0 1 any the\n"
52 "00024339 125061 0 2 any gamle\n"
53 "00024339 125061 0 3 any mand\n"
54 "w 00024339 125661 0 4 any Hello\n" /* index type given */
55 "s 00024339 125061 0 3 ti j k l\n"
57 "1001\n" /* separate record */
58 "00024340 125062 0 1 any the\n"
59 "00024340 125062 0 1 any the\n" /* DUP KEY, bug #432 */
60 "00024340 125062 0 2 any old\n"
61 "00024340 125062 0 3 any mand\n"
62 "s 00024340 125062 0 3 ti m n o\n"
64 "1002\n" /* segment testing record */
65 "00024341 125062 0 1 title a\n"
66 "00024341 125062 0 2 title b\n"
68 "00024341 125062 1 1024 title b\n"
69 "00024341 125062 1 1025 title c\n"
70 "00024341 125062 1 1026 title d\n"
71 "00024341 125062 1 1027 title e\n"
72 "00024341 125062 1 1028 title f\n"
74 "00024341 125062 2 2048 title g\n"
75 "00024341 125062 2 2049 title c\n"
81 static void tst(int argc, char **argv)
85 ZebraService zs = tl_start_up("test_safari.cfg", argc, argv);
87 ZebraHandle zh = zebra_open(zs, 0);
89 YAZ_CHECK(tl_init_data(zh, myrec));
91 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any the", 3));
92 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any den", 0));
93 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and the art", 1));
94 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and den gamle", 0));
95 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and the gamle", 1));
96 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and the of", 0));
98 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @prox 0 3 1 2 k 2 the gamle", 1));
99 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @prox 0 3 1 2 k 2 den gamle", 0));
100 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @prox 0 3 1 2 k 2 the art", 1));
101 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @prox 0 3 1 2 k 2 den gamle", 0));
102 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @prox 0 3 1 2 k 2 old mand", 1));
104 YAZ_CHECK(tl_query(zh, "@attr 1=any hello", 1));
106 /* verify that we get these records exactly */
110 YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 3, ids));
112 YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "R", yaz_oid_recsyn_sutrs,
113 myrec[0]), ZEBRA_OK);
114 YAZ_CHECK_EQ(tl_fetch_compare(zh, 2, "R", yaz_oid_recsyn_sutrs,
115 myrec[2]), ZEBRA_OK);
116 YAZ_CHECK_EQ(tl_fetch_compare(zh, 3, "R", yaz_oid_recsyn_sutrs,
117 myrec[4]), ZEBRA_OK);
118 YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::any:0",
120 "<record xmlns=\"http://www.indexdata.com/zebra/\">\n"
121 " <facet type=\"0\" index=\"any\">\n"
122 " <term coccur=\"4\" occur=\"3\">mand</term>\n"
123 " <term coccur=\"4\" occur=\"3\">the</term>\n"
124 " <term coccur=\"1\" occur=\"1\">art</term>\n"
125 " <term coccur=\"2\" occur=\"1\">gamle</term>\n"
126 " <term coccur=\"1\" occur=\"1\">old</term>\n"
128 "</record>\n"), ZEBRA_OK);
129 YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::any:0:2",
131 "<record xmlns=\"http://www.indexdata.com/zebra/\">\n"
132 " <facet type=\"0\" index=\"any\">\n"
133 " <term coccur=\"4\" occur=\"3\">mand</term>\n"
134 " <term coccur=\"4\" occur=\"3\">the</term>\n"
136 "</record>\n"), ZEBRA_OK);
139 YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::ti:s",
141 "<record xmlns=\"http://www.indexdata.com/zebra/\">\n"
142 " <facet type=\"s\" index=\"ti\">\n"
143 " <term coccur=\"1\" occur=\"1\">a b c</term>\n"
144 " <term coccur=\"1\" occur=\"1\">j k l</term>\n"
145 " <term coccur=\"1\" occur=\"1\">m n o</term>\n"
147 "</record>\n"), ZEBRA_OK);
149 /* limit to 125061 */
152 zebra_set_limit(zh, 0, limits);
154 YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 1, ids));
156 /* limit to 125060, 125061 */
160 zebra_set_limit(zh, 0, limits);
163 YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 2, ids));
165 /* all except 125062 */
168 zebra_set_limit(zh, 1, limits);
172 YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 2, ids));
175 zebra_set_limit(zh, 1, 0);
176 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any mand", 3));
179 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title a", 1));
180 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title b", 1));
181 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title c", 1));
183 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and a b", 1));
184 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and a c", 1));
186 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and c d", 1));
187 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and b f", 1));
188 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and f g", 0));
189 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and g f", 0));
190 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and d g", 0));
191 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and g c", 0));
192 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and c g", 0));
193 YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and c c", 1));
195 YAZ_CHECK(tl_close_down(zh, zs));
202 * c-file-style: "Stroustrup"
203 * indent-tabs-mode: nil
205 * vim: shiftwidth=4 tabstop=8 expandtab