3ae923172c636dbd1ffbeee0f1ebc6fa945a4feb
[idzebra-moved-to-github.git] / test / api / safari1.c
1 /* $Id: safari1.c,v 1.23 2007-12-05 09:55:10 adam Exp $
2    Copyright (C) 1995-2007
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
21 */
22
23 /* safari1 - insert a few Safari records */
24
25 #include "testlib.h"
26
27 const char *myrec[] = 
28 {
29     "1234\n"  /* ID first record */
30     /* chunk owner seq idx term */
31     "00024338 125060 0 1 any the\n"
32     "00024338 125060 0 2 any art\n"
33     "00024338 125060 0 3 any mand\n"
34     ,
35     "5678\n"  /* other record - same owner id */
36     "00024339 125060 0 1 any den\n"
37     "00024339 125060 0 2 any gamle\n"
38     "00024339 125060 0 3 any mand\n"
39     ,
40     "5678\n"  /* same record chunk id as before .. */
41     "00024339 125060 0 1 any the\n"
42     "00024339 125060 0 2 any gamle\n"
43     "00024339 125060 0 3 any mand\n"
44     ,
45     "1000\n"  /* separate record */
46     "00024339 125061 0 1 any the\n"
47     "00024339 125061 0 2 any gamle\n"
48     "00024339 125061 0 3 any mand\n"
49     "w 00024339 125661 0 4 any Hello\n"
50     ,
51     "1001\n"  /* separate record */
52     "00024340 125062 0 1 any the\n"
53     "00024340 125062 0 1 any the\n" /* DUP KEY, bug #432 */
54     "00024340 125062 0 2 any old\n"
55     "00024340 125062 0 3 any mand\n"
56     ,
57     "1002\n"  /* segment testing record */
58     "00024341 125062 0 1 title a\n"
59     "00024341 125062 0 2 title b\n"
60
61     "00024341 125062 1 1024 title b\n"
62     "00024341 125062 1 1025 title c\n"
63     "00024341 125062 1 1026 title d\n"
64     "00024341 125062 1 1027 title e\n"
65     "00024341 125062 1 1028 title f\n"
66
67     "00024341 125062 2 2048 title g\n"
68     "00024341 125062 2 2049 title c\n"
69     ,
70
71     0
72 };
73
74 static void tst(int argc, char **argv)
75 {
76     zint ids[3];
77     zint limits[3];
78     ZebraService zs = tl_start_up("safari.cfg", argc, argv);
79     
80     ZebraHandle zh = zebra_open(zs, 0);
81
82     YAZ_CHECK(tl_init_data(zh, myrec));
83
84     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any the", 3));
85     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any den", 0));
86     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and the art", 1));
87     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and den gamle", 0));
88     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and the gamle", 1));
89     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and the of", 0));
90
91     YAZ_CHECK(tl_query(zh, "@attr 1=any hello", 1));
92
93     /* verify that we get these records exactly */
94     ids[0] = 24338;
95     ids[1] = 24339;
96     ids[2] = 24340;
97     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 3, ids));
98
99     YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "R", yaz_oid_recsyn_sutrs,
100                                   myrec[0]), ZEBRA_OK);
101     YAZ_CHECK_EQ(tl_fetch_compare(zh, 2, "R", yaz_oid_recsyn_sutrs,
102                                   myrec[2]), ZEBRA_OK);
103     YAZ_CHECK_EQ(tl_fetch_compare(zh, 3, "R", yaz_oid_recsyn_sutrs,
104                                   myrec[4]), ZEBRA_OK);
105     YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::any:0", 
106                                   yaz_oid_recsyn_xml,
107                                   "<facets>\n"
108                                   "  <facet type=\"0\" index=\"any\">\n"
109                                   "    <term coccur=\"4\" occur=\"3\">mand</term>\n"
110                                   "    <term coccur=\"4\" occur=\"3\">the</term>\n"
111                                   "    <term coccur=\"1\" occur=\"1\">art</term>\n"
112                                   "    <term coccur=\"2\" occur=\"1\">gamle</term>\n"
113                                   "    <term coccur=\"1\" occur=\"1\">old</term>\n"
114                                   "  </facet>\n"
115                                   "</facets>\n"), ZEBRA_OK);
116     YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::any:0:2", 
117                                   yaz_oid_recsyn_xml,
118                                   "<facets>\n"
119                                   "  <facet type=\"0\" index=\"any\">\n"
120                                   "    <term coccur=\"4\" occur=\"3\">mand</term>\n"
121                                   "    <term coccur=\"4\" occur=\"3\">the</term>\n"
122                                   "  </facet>\n"
123                                   "</facets>\n"), ZEBRA_OK);
124
125     /* limit to 125061 */
126     limits[0] = 125061;
127     limits[1] = 0;
128     zebra_set_limit(zh, 0, limits);
129     ids[0] = 24339;
130     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 1, ids));
131
132     /* limit to 125060, 125061 */
133     limits[0] = 125061;
134     limits[1] = 125060;
135     limits[2] = 0;
136     zebra_set_limit(zh, 0, limits);
137     ids[0] = 24338;
138     ids[1] = 24339;
139     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 2, ids));
140
141     /* all except 125062 */
142     limits[0] = 125062;
143     limits[1] = 0;
144     zebra_set_limit(zh, 1, limits);
145
146     ids[0] = 24338;
147     ids[1] = 24339;
148     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 2, ids));
149
150     /* no limit */
151     zebra_set_limit(zh, 1, 0);
152     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any mand", 3));
153
154     /* test segments */
155     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title a", 1));
156     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title b", 1));
157     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title c", 1));
158
159     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and a b", 1));
160     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and a c", 1));
161     
162     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and c d", 1));
163     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and b f", 1));
164     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and f g", 0));
165     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and g f", 0));
166     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and d g", 0));
167     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and g c", 0));
168     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and c g", 0));
169     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and c c", 1));
170
171     YAZ_CHECK(tl_close_down(zh, zs));
172 }
173
174 TL_MAIN
175 /*
176  * Local variables:
177  * c-basic-offset: 4
178  * indent-tabs-mode: nil
179  * End:
180  * vim: shiftwidth=4 tabstop=8 expandtab
181  */
182