1 /* $Id: t4.c,v 1.17 2005-05-11 12:39:37 adam Exp $
2 Copyright (C) 1995-2005
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 /* t4 - insert a small pile of records, search and fetch them */
27 const char *myrec[] = {
29 " <title>My title</title>\n"
33 #define NUMBER_TO_FETCH_MAX 1000
35 int main(int argc, char **argv)
38 int number_to_be_inserted = 5;
39 int number_to_fetch = 5;
41 ZebraService zs = start_up(0, argc, argv);
42 ZebraHandle zh = zebra_open(zs);
46 zebra_begin_trans (zh, 1);
47 for (i = 0; i< number_to_be_inserted-1; i++)
48 { /* -1 since already inserted one in init_data */
49 zebra_add_record(zh, myrec[0], strlen(myrec[0]));
55 zs = start_service("");
57 zebra_select_database(zh, "Default");
58 zebra_set_resource(zh, "sortmax", "3"); /* make small sort boundary */
63 ZebraRetrievalRecord retrievalRecord[NUMBER_TO_FETCH_MAX];
66 ODR odr_input = odr_createmem(ODR_DECODE);
67 ODR odr_output = odr_createmem(ODR_DECODE);
68 YAZ_PQF_Parser parser = yaz_pqf_create();
69 Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, "@attr 1=4 my");
72 sprintf(setname, "s%d", i+1);
73 ret = zebra_search_RPN(zh, odr_input, query, setname, &hits);
76 int code = zebra_errCode(zh);
77 yaz_log(YLOG_WARN, "Unexpected error code=%d", code);
80 if (hits != number_to_be_inserted)
82 yaz_log(YLOG_WARN, "Unexpected hit count " ZINT_FORMAT
83 "(should be %d)", hits, number_to_be_inserted);
87 yaz_pqf_destroy(parser);
89 odr_destroy(odr_input);
91 zebra_begin_trans(zh, 1);
93 for (j = 0; j < number_to_fetch; j++)
94 retrievalRecord[j].position = j+1;
96 ret = zebra_records_retrieve(zh, odr_output, setname, 0,
97 VAL_TEXT_XML, number_to_fetch,
101 int code = zebra_errCode(zh);
102 yaz_log(YLOG_FATAL, "zebra_records_retrieve returned error %d",
107 for (j = 0; j < number_to_fetch; j++)
109 if (!retrievalRecord[j].buf)
111 yaz_log(YLOG_FATAL, "No record buf at position %d", j);
114 if (!retrievalRecord[j].len)
116 yaz_log(YLOG_FATAL, "No record len at position %d", j);
120 odr_destroy(odr_output);
126 return close_down(zh, zs, 0);