1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
10 #include <yaz/xmalloc.h>
13 const char *my_callback(void *handle, const char *name)
15 if (!strcmp(name, "async"))
20 int main(int argc, char **argv)
24 ZOOM_connection z[500]; /* allow at most 500 connections */
25 ZOOM_resultset r[500]; /* and result sets .. */
29 o = ZOOM_options_create();
32 fprintf(stderr, "usage:\n%s target1 .. targetN query strategy sort\n",
39 /* function my_callback called when reading options .. */
40 ZOOM_options_set_callback(o, my_callback, 0);
42 /* get 20 (at most) records from beginning */
43 ZOOM_options_set(o, "count", "20");
45 ZOOM_options_set(o, "implementationName", "sortapp");
46 ZOOM_options_set(o, "preferredRecordSyntax", "usmarc");
47 ZOOM_options_set(o, "elementSetName", "B");
50 q = ZOOM_query_create();
51 if (strncmp("cql:", argv[argc-3], 4) == 0)
53 if (ZOOM_query_cql(q, argv[argc-3] + 4))
55 printf("bad CQL: %s\n", argv[argc-3] + 4);
59 else if (ZOOM_query_prefix(q, argv[argc-3]))
61 printf("bad PQF: %s\n", argv[argc-3]);
64 if (ZOOM_query_sortby2(q, argv[argc-2], argv[argc-1]))
66 printf("bad sort spec: %s\n", argv[argc-1]);
69 /* connect - and search all */
70 for (i = 0; i < no; i++)
72 z[i] = ZOOM_connection_create(o);
73 ZOOM_connection_connect(z[i], argv[i+1], 0);
74 r[i] = ZOOM_connection_search(z[i], q);
78 while (ZOOM_event(no, z))
82 for (i = 0; i < no; i++)
85 const char *errmsg, *addinfo;
86 if ((error = ZOOM_connection_error(z[i], &errmsg, &addinfo)))
87 fprintf(stderr, "%s error: %s (%d) %s\n",
88 ZOOM_connection_option_get(z[i], "host"),
89 errmsg, error, addinfo);
92 /* OK, no major errors. Look at the result count */
94 printf("%s: %ld hits\n", ZOOM_connection_option_get(z[i], "host"),
95 (long) ZOOM_resultset_size(r[i]));
96 /* go through first 20 records at target */
97 for (pos = 0; pos < 20; pos++)
100 const char *db, *syntax, *str;
101 int record_len, syntax_len;
103 rec = ZOOM_resultset_record(r[i], pos);
104 /* get database for record and record itself at pos */
106 db = ZOOM_record_get(rec, "database", 0);
107 str = ZOOM_record_get(rec, "xml", &record_len);
108 syntax = ZOOM_record_get(rec, "syntax", &syntax_len);
109 /* if rec is non-null, we got a record for display */
112 printf("%d %s %s\n", pos+1, syntax,
113 (db ? db : "unknown"));
116 if (fwrite(str, 1, record_len, stdout) !=
118 printf("write to stdout failed\n");
126 /* destroy stuff and exit */
127 ZOOM_query_destroy(q);
128 for (i = 0; i < no; i++)
130 ZOOM_resultset_destroy(r[i]);
131 ZOOM_connection_destroy(z[i]);
133 ZOOM_options_destroy(o);
139 * c-file-style: "Stroustrup"
140 * indent-tabs-mode: nil
142 * vim: shiftwidth=4 tabstop=8 expandtab