Omit CVS Id. Update copyright year.
[idzebra-moved-to-github.git] / test / api / safari1.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1995-2008 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 /* safari1 - insert a few Safari records */
21
22 #include "testlib.h"
23
24 const char *myrec[] = 
25 {
26     "1234\n"  /* ID first record */
27     /* chunk owner seq idx term */
28     "00024338 125060 0 1 any the\n"
29     "00024338 125060 0 2 any art\n"
30     "00024338 125060 0 3 any mand\n"
31     ,
32     "5678\n"  /* other record - same owner id */
33     "00024339 125060 0 1 any den\n"
34     "00024339 125060 0 2 any gamle\n"
35     "00024339 125060 0 3 any mand\n"
36     ,
37     "5678\n"  /* same record chunk id as before .. */
38     "00024339 125060 0 1 any the\n"
39     "00024339 125060 0 2 any gamle\n"
40     "00024339 125060 0 3 any mand\n"
41     ,
42     "1000\n"  /* separate record */
43     "00024339 125061 0 1 any the\n"
44     "00024339 125061 0 2 any gamle\n"
45     "00024339 125061 0 3 any mand\n"
46     "w 00024339 125661 0 4 any Hello\n"
47     ,
48     "1001\n"  /* separate record */
49     "00024340 125062 0 1 any the\n"
50     "00024340 125062 0 1 any the\n" /* DUP KEY, bug #432 */
51     "00024340 125062 0 2 any old\n"
52     "00024340 125062 0 3 any mand\n"
53     ,
54     "1002\n"  /* segment testing record */
55     "00024341 125062 0 1 title a\n"
56     "00024341 125062 0 2 title b\n"
57
58     "00024341 125062 1 1024 title b\n"
59     "00024341 125062 1 1025 title c\n"
60     "00024341 125062 1 1026 title d\n"
61     "00024341 125062 1 1027 title e\n"
62     "00024341 125062 1 1028 title f\n"
63
64     "00024341 125062 2 2048 title g\n"
65     "00024341 125062 2 2049 title c\n"
66     ,
67
68     0
69 };
70
71 static void tst(int argc, char **argv)
72 {
73     zint ids[3];
74     zint limits[3];
75     ZebraService zs = tl_start_up("safari.cfg", argc, argv);
76     
77     ZebraHandle zh = zebra_open(zs, 0);
78
79     YAZ_CHECK(tl_init_data(zh, myrec));
80
81     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any the", 3));
82     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any den", 0));
83     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and the art", 1));
84     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and den gamle", 0));
85     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and the gamle", 1));
86     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and the of", 0));
87
88     YAZ_CHECK(tl_query(zh, "@attr 1=any hello", 1));
89
90     /* verify that we get these records exactly */
91     ids[0] = 24338;
92     ids[1] = 24339;
93     ids[2] = 24340;
94     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 3, ids));
95
96     YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "R", yaz_oid_recsyn_sutrs,
97                                   myrec[0]), ZEBRA_OK);
98     YAZ_CHECK_EQ(tl_fetch_compare(zh, 2, "R", yaz_oid_recsyn_sutrs,
99                                   myrec[2]), ZEBRA_OK);
100     YAZ_CHECK_EQ(tl_fetch_compare(zh, 3, "R", yaz_oid_recsyn_sutrs,
101                                   myrec[4]), ZEBRA_OK);
102     YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::any:0", 
103                                   yaz_oid_recsyn_xml,
104                                   "<facets>\n"
105                                   "  <facet type=\"0\" index=\"any\">\n"
106                                   "    <term coccur=\"4\" occur=\"3\">mand</term>\n"
107                                   "    <term coccur=\"4\" occur=\"3\">the</term>\n"
108                                   "    <term coccur=\"1\" occur=\"1\">art</term>\n"
109                                   "    <term coccur=\"2\" occur=\"1\">gamle</term>\n"
110                                   "    <term coccur=\"1\" occur=\"1\">old</term>\n"
111                                   "  </facet>\n"
112                                   "</facets>\n"), ZEBRA_OK);
113     YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::any:0:2", 
114                                   yaz_oid_recsyn_xml,
115                                   "<facets>\n"
116                                   "  <facet type=\"0\" index=\"any\">\n"
117                                   "    <term coccur=\"4\" occur=\"3\">mand</term>\n"
118                                   "    <term coccur=\"4\" occur=\"3\">the</term>\n"
119                                   "  </facet>\n"
120                                   "</facets>\n"), ZEBRA_OK);
121
122     /* limit to 125061 */
123     limits[0] = 125061;
124     limits[1] = 0;
125     zebra_set_limit(zh, 0, limits);
126     ids[0] = 24339;
127     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 1, ids));
128
129     /* limit to 125060, 125061 */
130     limits[0] = 125061;
131     limits[1] = 125060;
132     limits[2] = 0;
133     zebra_set_limit(zh, 0, limits);
134     ids[0] = 24338;
135     ids[1] = 24339;
136     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 2, ids));
137
138     /* all except 125062 */
139     limits[0] = 125062;
140     limits[1] = 0;
141     zebra_set_limit(zh, 1, limits);
142
143     ids[0] = 24338;
144     ids[1] = 24339;
145     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 2, ids));
146
147     /* no limit */
148     zebra_set_limit(zh, 1, 0);
149     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any mand", 3));
150
151     /* test segments */
152     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title a", 1));
153     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title b", 1));
154     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title c", 1));
155
156     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and a b", 1));
157     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and a c", 1));
158     
159     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and c d", 1));
160     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and b f", 1));
161     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and f g", 0));
162     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and g f", 0));
163     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and d g", 0));
164     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and g c", 0));
165     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and c g", 0));
166     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and c c", 1));
167
168     YAZ_CHECK(tl_close_down(zh, zs));
169 }
170
171 TL_MAIN
172 /*
173  * Local variables:
174  * c-basic-offset: 4
175  * indent-tabs-mode: nil
176  * End:
177  * vim: shiftwidth=4 tabstop=8 expandtab
178  */
179