1 /* $Id: t8.c,v 1.1 2004-10-01 15:36:41 heikki Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
5 This file is part of the Zebra server.
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
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
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 /* t8: test numeric attributes */
27 #include <yaz/pquery.h>
28 #include <idzebra/api.h>
32 /* read zebra.cfg from env var srcdir if it exists; otherwise current dir */
33 static ZebraService start_service()
36 char *srcdir = getenv("srcdir");
37 sprintf(cfg, "%.200s%szebragils.cfg",
38 srcdir ? srcdir : "", srcdir ? "/" : "");
39 return zebra_start(cfg);
42 static void insertdata(ZebraHandle zh)
46 " <title>My title</title>\n"
47 " <abstract>test record with single coordset, negatives</abstract>\n"
48 " <Spatial-Domain><Bounding-Coordinates>\n"
49 " <West-Bounding-Coordinate> -120 </West-Bounding-Coordinate>\n"
50 " <East-Bounding-Coordinate> -102 </East-Bounding-Coordinate>\n"
51 " <North-Bounding-Coordinate> 49 </North-Bounding-Coordinate>\n"
52 " <South-Bounding-Coordinate> 31 </South-Bounding-Coordinate>\n"
53 " </Bounding-Coordinates></Spatial-Domain>"
57 " <title>Another title</title>\n"
58 " <abstract>second test with two coord sets</abstract>\n"
59 " <Spatial-Domain><Bounding-Coordinates>\n"
60 " <West-Bounding-Coordinate> -120 </West-Bounding-Coordinate>\n"
61 " <East-Bounding-Coordinate> -102 </East-Bounding-Coordinate>\n"
62 " <North-Bounding-Coordinate> 49 </North-Bounding-Coordinate>\n"
63 " <South-Bounding-Coordinate> 31 </South-Bounding-Coordinate>\n"
64 " </Bounding-Coordinates>"
65 " <Bounding-Coordinates>\n"
66 " <West-Bounding-Coordinate> -125 </West-Bounding-Coordinate>\n"
67 " <East-Bounding-Coordinate> -108 </East-Bounding-Coordinate>\n"
68 " <North-Bounding-Coordinate> 41 </North-Bounding-Coordinate>\n"
69 " <South-Bounding-Coordinate> 25 </South-Bounding-Coordinate>\n"
70 " </Bounding-Coordinates></Spatial-Domain>"
73 zebra_select_database(zh, "Default");
75 zebra_begin_trans (zh, 1);
76 zebra_add_record (zh, rec1, strlen(rec1));
77 zebra_add_record (zh, rec2, strlen(rec2));
82 static void query( ZebraHandle zh, int lineno, char *qry, int expectedhits)
84 ODR odr_input = odr_createmem (ODR_DECODE);
85 YAZ_PQF_Parser parser = yaz_pqf_create();
89 int thistest=testno++;
92 logf(LOG_LOG,"Test %d (line %d): expecting %d",
93 thistest, lineno,expectedhits);
94 logf(LOG_LOG,"%s", qry);
96 query = yaz_pqf_parse(parser, odr_input, qry);
98 zebra_begin_trans (zh, 0);
101 logf(LOG_DEBUG,"calling search");
102 rc=zebra_search_RPN (zh, odr_input, query, "nameless", &hits);
103 logf(LOG_DEBUG,"search returned %d",rc);
105 printf("search returned %d",rc);
106 if (hits != expectedhits)
108 printf( "FAIL: Test %d (line %d):\n"
109 "got %d hits, expected %d\n"
111 thistest, lineno,hits, expectedhits, qry);
112 logf( LOG_FATAL, "FAIL: Test %d (line %d): got %d hits, expected %d\n",
113 thistest, lineno, hits,expectedhits);
117 zebra_end_trans (zh);
118 yaz_pqf_destroy(parser);
119 odr_destroy (odr_input);
120 logf(LOG_LOG,"Test %d ok",thistest);
124 int main(int argc, char **argv)
128 yaz_log_init_file("t8.log");
129 /* yaz_log_init_level(LOG_ALL); */
133 zs = start_service();
134 zh = zebra_open (zs);
138 #define Q(q,n) query(zh,__LINE__,q,n)
139 /* couple of simple queries just to see that we have indexed the stuff */
140 Q( "@attr 1=4 title",2 );
143 /* 1=2038: West-Bounding-Coordinate 2039: East: 2040: North: 2041 South*/
144 /* 4=109: numeric string */
145 /* 2=3: equal 2=1: less, 2=4: greater or equal 2=5 greater */
147 /* N>25, search attributes work */
148 Q( "@attr 2=4 @attr gils 1=2040 @attr 4=109 25",2);
150 /* N=41, get rec1 only */
151 Q( "@attr 2=3 @attr gils 1=2040 @attr 4=109 41",1);
153 /* N=49, get both records */
154 Q( "@attr 2=3 @attr gils 1=2040 @attr 4=109 49",2);
156 /* W=-120 get both records */
157 Q( "@attr 2=3 @attr gils 1=2038 @attr 4=109 -120",2);
159 /* W<-122 get only rec1 */
160 Q( "@attr 2=1 @attr gils 1=2038 @attr 4=109 '-120' ",1);
162 /* N=41 and N=49 get only rec2 */
163 Q( "@attr 2=3 @attr gils 1=2040 @attr 4=109 \"41 49\" ",1);
171 logf(LOG_LOG,"All tests OK");