Reformat: delete trailing whitespace
[idzebra-moved-to-github.git] / test / api / test_safari.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1994-2011 Index Data
3
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
7 version.
8
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
12 for more details.
13
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
17
18 */
19
20 /** \file
21     \brief test safari filter
22  */
23
24 #if HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 #include "testlib.h"
28
29 const char *myrec[] =
30 {
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"
37     ,
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"
43     ,
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"
49     ,
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"
56     ,
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"
63     ,
64     "1002\n"  /* segment testing record */
65     "00024341 125062 0 1 title a\n"
66     "00024341 125062 0 2 title b\n"
67
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"
73
74     "00024341 125062 2 2048 title g\n"
75     "00024341 125062 2 2049 title c\n"
76     ,
77
78     0
79 };
80
81 static void tst(int argc, char **argv)
82 {
83     zint ids[3];
84     zint limits[3];
85     ZebraService zs = tl_start_up("test_safari.cfg", argc, argv);
86
87     ZebraHandle zh = zebra_open(zs, 0);
88
89     YAZ_CHECK(tl_init_data(zh, myrec));
90
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));
97
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));
103
104     YAZ_CHECK(tl_query(zh, "@attr 1=any hello", 1));
105
106     /* verify that we get these records exactly */
107     ids[0] = 24338;
108     ids[1] = 24339;
109     ids[2] = 24340;
110     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 3, ids));
111
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",
119                                   yaz_oid_recsyn_xml,
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"
127                                   "  </facet>\n"
128                                   "</record>\n"), ZEBRA_OK);
129     YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::any:0:2",
130                                   yaz_oid_recsyn_xml,
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"
135                                   "  </facet>\n"
136                                   "</record>\n"), ZEBRA_OK);
137
138
139     YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::ti:s",
140                                   yaz_oid_recsyn_xml,
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"
146                                   "  </facet>\n"
147                                   "</record>\n"), ZEBRA_OK);
148
149     /* limit to 125061 */
150     limits[0] = 125061;
151     limits[1] = 0;
152     zebra_set_limit(zh, 0, limits);
153     ids[0] = 24339;
154     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 1, ids));
155
156     /* limit to 125060, 125061 */
157     limits[0] = 125061;
158     limits[1] = 125060;
159     limits[2] = 0;
160     zebra_set_limit(zh, 0, limits);
161     ids[0] = 24338;
162     ids[1] = 24339;
163     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 2, ids));
164
165     /* all except 125062 */
166     limits[0] = 125062;
167     limits[1] = 0;
168     zebra_set_limit(zh, 1, limits);
169
170     ids[0] = 24338;
171     ids[1] = 24339;
172     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 2, ids));
173
174     /* no limit */
175     zebra_set_limit(zh, 1, 0);
176     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any mand", 3));
177
178     /* test segments */
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));
182
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));
185
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));
194
195     YAZ_CHECK(tl_close_down(zh, zs));
196 }
197
198 TL_MAIN
199 /*
200  * Local variables:
201  * c-basic-offset: 4
202  * c-file-style: "Stroustrup"
203  * indent-tabs-mode: nil
204  * End:
205  * vim: shiftwidth=4 tabstop=8 expandtab
206  */
207