1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2008 Index Data
3 * See the file LICENSE for details.
8 #include <yaz/xmalloc.h>
12 static void display_records (const char *tname, ZOOM_resultset r)
14 /* OK, no major errors. Look at the result count */
16 printf ("%s: %ld hits\n", tname, (long) ZOOM_resultset_size(r));
17 /* go through all records at target */
18 for (pos = 0; pos < 4; pos++)
20 ZOOM_record rec = ZOOM_resultset_record (r, pos);
23 /* get database for record and record itself at pos */
24 const char *db = ZOOM_record_get (rec, "database", 0);
26 const char *render = ZOOM_record_get (rec, "render", &len);
27 /* if rec is non-null, we got a record for display */
30 printf ("%d %s\n", pos+1, (db ? db : "unknown"));
32 fwrite (render, 1, len, stdout);
39 int main(int argc, char **argv)
43 ZOOM_connection z[500]; /* allow at most 500 connections */
44 ZOOM_resultset r1[500]; /* and result sets .. */
45 ZOOM_resultset r2[500]; /* and result sets .. */
49 o = ZOOM_options_create ();
52 fprintf (stderr, "usage:\n%s target1 .. targetN query1 query2\n",
59 ZOOM_options_set (o, "async", "1");
61 /* get 3 (at most) records from beginning */
62 ZOOM_options_set (o, "count", "3");
64 ZOOM_options_set (o, "preferredRecordSyntax", "sutrs");
65 ZOOM_options_set (o, "elementSetName", "B");
68 q = ZOOM_query_create ();
69 if (ZOOM_query_prefix (q, argv[argc-2]))
71 printf ("bad PQF: %s\n", argv[argc-2]);
74 /* connect - and search all */
75 for (i = 0; i<no; i++)
77 z[i] = ZOOM_connection_create (o);
78 ZOOM_connection_connect (z[i], argv[i+1], 0);
79 r1[i] = ZOOM_connection_search (z[i], q);
81 if (ZOOM_query_prefix (q, argv[argc-1]))
83 printf ("bad prefix query: %s\n", argv[argc-1]);
86 /* queue second search */
87 for (i = 0; i<no; i++)
88 r2[i] = ZOOM_connection_search (z[i], q);
90 /* fetch 5th record from first result set as well */
91 for (i = 0; i<no; i++)
92 ZOOM_resultset_records (r1[i], 0, 4, 1);
95 while (ZOOM_event (no, z))
99 for (i = 0; i<no; i++)
102 const char *errmsg, *addinfo;
103 if ((error = ZOOM_connection_error(z[i], &errmsg, &addinfo)))
104 fprintf (stderr, "%s error: %s (%d) %s\n",
105 ZOOM_connection_option_get(z[i], "host"),
106 errmsg, error, addinfo);
109 display_records (ZOOM_connection_option_get(z[i], "host"), r1[i]);
110 display_records (ZOOM_connection_option_get(z[i], "host"), r2[i]);
113 /* destroy stuff and exit */
114 ZOOM_query_destroy (q);
115 for (i = 0; i<no; i++)
117 ZOOM_connection_destroy (z[i]);
118 ZOOM_resultset_destroy (r1[i]);
119 ZOOM_resultset_destroy (r2[i]);
121 ZOOM_options_destroy(o);
127 * indent-tabs-mode: nil
129 * vim: shiftwidth=4 tabstop=8 expandtab