2 * $Id: zoomtst5.c,v 1.10 2005-06-25 15:46:08 adam Exp $
4 * Asynchronous multi-target client doing search, sort and present
11 #include <yaz/xmalloc.h>
14 const char *my_callback (void *handle, const char *name)
16 if (!strcmp (name, "async"))
21 int main(int argc, char **argv)
25 ZOOM_connection z[500]; /* allow at most 500 connections */
26 ZOOM_resultset r[500]; /* and result sets .. */
30 o = ZOOM_options_create ();
33 fprintf (stderr, "usage:\n%s target1 .. targetN query sort\n",
40 /* function my_callback called when reading options .. */
41 ZOOM_options_set_callback (o, my_callback, 0);
43 /* get 20 (at most) records from beginning */
44 ZOOM_options_set (o, "count", "20");
46 ZOOM_options_set (o, "implementationName", "sortapp");
47 ZOOM_options_set (o, "preferredRecordSyntax", "usmarc");
48 ZOOM_options_set (o, "elementSetName", "B");
51 q = ZOOM_query_create ();
52 if (ZOOM_query_prefix (q, argv[argc-2]))
54 printf ("bad PQF: %s\n", argv[argc-2]);
57 if (ZOOM_query_sortby (q, argv[argc-1]))
59 printf ("bad sort spec: %s\n", argv[argc-1]);
62 /* connect - and search all */
63 for (i = 0; i<no; i++)
65 z[i] = ZOOM_connection_create (o);
66 ZOOM_connection_connect (z[i], argv[i+1], 0);
67 r[i] = ZOOM_connection_search (z[i], q);
71 while (ZOOM_event (no, z))
75 for (i = 0; i<no; i++)
78 const char *errmsg, *addinfo;
79 if ((error = ZOOM_connection_error(z[i], &errmsg, &addinfo)))
80 fprintf (stderr, "%s error: %s (%d) %s\n",
81 ZOOM_connection_option_get(z[i], "host"),
82 errmsg, error, addinfo);
85 /* OK, no major errors. Look at the result count */
87 printf ("%s: %d hits\n", ZOOM_connection_option_get(z[i], "host"),
88 ZOOM_resultset_size(r[i]));
89 /* go through first 20 records at target */
90 for (pos = 0; pos < 20; pos++)
93 const char *db, *syntax, *str;
96 rec = ZOOM_resultset_record (r[i], pos);
97 /* get database for record and record itself at pos */
99 db = ZOOM_record_get (rec, "database", 0);
100 str = ZOOM_record_get (rec, "xml", &len);
101 syntax = ZOOM_record_get (rec, "syntax", &len);
102 /* if rec is non-null, we got a record for display */
105 printf ("%d %s %s\n", pos+1, syntax,
106 (db ? db : "unknown"));
108 fwrite (str, 1, len, stdout);
115 /* destroy stuff and exit */
116 ZOOM_query_destroy (q);
117 for (i = 0; i<no; i++)
119 ZOOM_resultset_destroy (r[i]);
120 ZOOM_connection_destroy (z[i]);
122 ZOOM_options_destroy(o);
128 * indent-tabs-mode: nil
130 * vim: shiftwidth=4 tabstop=8 expandtab