1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2009 Index Data
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
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
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
20 /* insert a small pile of records, search and fetch them */
24 const char *myrec[] = {
26 " <title>My title</title>\n"
30 #define NUMBER_TO_FETCH_MAX 1000
32 static void tst(int argc, char **argv)
35 int number_to_be_inserted = 5;
36 int number_to_fetch = 5;
38 ZebraService zs = tl_start_up(0, argc, argv);
39 ZebraHandle zh = zebra_open(zs, 0);
41 YAZ_CHECK(tl_init_data(zh, myrec));
43 YAZ_CHECK(zebra_begin_trans (zh, 1) == ZEBRA_OK);
45 for (i = 0; i< number_to_be_inserted-1; i++)
46 { /* -1 since already inserted one in init_data */
47 zebra_add_record(zh, myrec[0], strlen(myrec[0]));
49 YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK);
54 zs = tl_zebra_start("");
55 zh = zebra_open(zs, 0);
56 YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK);
57 zebra_set_resource(zh, "sortmax", "3"); /* make small sort boundary */
62 ZebraRetrievalRecord retrievalRecord[NUMBER_TO_FETCH_MAX];
65 ODR odr_input = odr_createmem(ODR_DECODE);
66 ODR odr_output = odr_createmem(ODR_DECODE);
67 YAZ_PQF_Parser parser = yaz_pqf_create();
68 Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, "@attr 1=4 my");
71 sprintf(setname, "s%d", i+1);
72 ret = zebra_search_RPN(zh, odr_input, query, setname, &hits);
75 int code = zebra_errCode(zh);
76 yaz_log(YLOG_WARN, "Unexpected error code=%d", code);
79 if (hits != number_to_be_inserted)
81 yaz_log(YLOG_WARN, "Unexpected hit count " ZINT_FORMAT
82 "(should be %d)", hits, number_to_be_inserted);
86 yaz_pqf_destroy(parser);
88 odr_destroy(odr_input);
90 YAZ_CHECK(zebra_begin_trans(zh, 1) == ZEBRA_OK);
92 for (j = 0; j < number_to_fetch; j++)
93 retrievalRecord[j].position = j+1;
95 ret = zebra_records_retrieve(zh, odr_output, setname, 0,
96 yaz_oid_recsyn_xml, number_to_fetch,
100 int code = zebra_errCode(zh);
101 yaz_log(YLOG_FATAL, "zebra_records_retrieve returned error %d",
106 for (j = 0; j < number_to_fetch; j++)
108 if (!retrievalRecord[j].buf)
110 yaz_log(YLOG_FATAL, "No record buf at position %d", j);
113 if (!retrievalRecord[j].len)
115 yaz_log(YLOG_FATAL, "No record len at position %d", j);
119 odr_destroy(odr_output);
121 YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK);
124 YAZ_CHECK(tl_close_down(zh, zs));
132 * c-file-style: "Stroustrup"
133 * indent-tabs-mode: nil
135 * vim: shiftwidth=4 tabstop=8 expandtab