1 /* $Id: zoomtst5.c,v 1.11 2006-04-21 10:28:08 adam Exp $ */
4 \brief Asynchronous multi-target client with sort
6 Asynchronous multi-target client doing search, sort and present
13 #include <yaz/xmalloc.h>
16 const char *my_callback (void *handle, const char *name)
18 if (!strcmp (name, "async"))
23 int main(int argc, char **argv)
27 ZOOM_connection z[500]; /* allow at most 500 connections */
28 ZOOM_resultset r[500]; /* and result sets .. */
32 o = ZOOM_options_create ();
35 fprintf (stderr, "usage:\n%s target1 .. targetN query sort\n",
42 /* function my_callback called when reading options .. */
43 ZOOM_options_set_callback (o, my_callback, 0);
45 /* get 20 (at most) records from beginning */
46 ZOOM_options_set (o, "count", "20");
48 ZOOM_options_set (o, "implementationName", "sortapp");
49 ZOOM_options_set (o, "preferredRecordSyntax", "usmarc");
50 ZOOM_options_set (o, "elementSetName", "B");
53 q = ZOOM_query_create ();
54 if (ZOOM_query_prefix (q, argv[argc-2]))
56 printf ("bad PQF: %s\n", argv[argc-2]);
59 if (ZOOM_query_sortby (q, argv[argc-1]))
61 printf ("bad sort spec: %s\n", argv[argc-1]);
64 /* connect - and search all */
65 for (i = 0; i<no; i++)
67 z[i] = ZOOM_connection_create (o);
68 ZOOM_connection_connect (z[i], argv[i+1], 0);
69 r[i] = ZOOM_connection_search (z[i], q);
73 while (ZOOM_event (no, z))
77 for (i = 0; i<no; i++)
80 const char *errmsg, *addinfo;
81 if ((error = ZOOM_connection_error(z[i], &errmsg, &addinfo)))
82 fprintf (stderr, "%s error: %s (%d) %s\n",
83 ZOOM_connection_option_get(z[i], "host"),
84 errmsg, error, addinfo);
87 /* OK, no major errors. Look at the result count */
89 printf ("%s: %ld hits\n", ZOOM_connection_option_get(z[i], "host"),
90 (long) ZOOM_resultset_size(r[i]));
91 /* go through first 20 records at target */
92 for (pos = 0; pos < 20; pos++)
95 const char *db, *syntax, *str;
98 rec = ZOOM_resultset_record (r[i], pos);
99 /* get database for record and record itself at pos */
101 db = ZOOM_record_get (rec, "database", 0);
102 str = ZOOM_record_get (rec, "xml", &len);
103 syntax = ZOOM_record_get (rec, "syntax", &len);
104 /* if rec is non-null, we got a record for display */
107 printf ("%d %s %s\n", pos+1, syntax,
108 (db ? db : "unknown"));
110 fwrite (str, 1, len, stdout);
117 /* destroy stuff and exit */
118 ZOOM_query_destroy (q);
119 for (i = 0; i<no; i++)
121 ZOOM_resultset_destroy (r[i]);
122 ZOOM_connection_destroy (z[i]);
124 ZOOM_options_destroy(o);
130 * indent-tabs-mode: nil
132 * vim: shiftwidth=4 tabstop=8 expandtab