- printf ("connect <zurl>\n");
- printf ("search <pqf>\n");
- printf ("show [<start> [<count>]\n");
- printf ("quit\n");
- printf ("close <zurl>\n");
- printf ("set <option> [<value>]\n");
- printf ("get <option>\n");
- printf ("\n");
- printf ("options:\n");
- printf (" start\n");
- printf (" count\n");
- printf (" databaseName\n");
- printf (" preferredRecordSyntax\n");
- printf (" proxy\n");
- printf (" elementSetName\n");
- printf (" maximumRecordSize\n");
- printf (" preferredRecordSize\n");
- printf (" async\n");
- printf (" piggyback\n");
- printf (" group\n");
- printf (" user\n");
- printf (" pass\n");
- printf (" implementationName\n");
- printf (" charset\n");
- printf (" lang\n");
+ const char *query_str = *args;
+ ZOOM_query query = ZOOM_query_create();
+ int i, number;
+ int ret = 0;
+ ZOOM_scanset *s = 0;
+ struct zoom_db *db;
+
+ while (*query_str == ' ')
+ query_str++;
+
+ if (memcmp(query_str, "cql:", 4) == 0)
+ {
+ ZOOM_query_cql(query, query_str + 4);
+ }
+ else if (ZOOM_query_prefix(query, query_str))
+ {
+ printf("Bad PQF: %s\n", query_str);
+ ZOOM_query_destroy(query);
+ return 1;
+ }
+
+ for (number = 0, db = sh->list; db; db = db->next)
+ if (db->con)
+ number++;
+
+ s = xmalloc(sizeof(*s) * number);
+
+ for (i = 0, db = sh->list; db; db = db->next)
+ if (db->con)
+ s[i++] = ZOOM_connection_scan1(db->con, query);
+
+ ZOOM_query_destroy(query);
+
+ process_events(sh);
+
+ for (i = 0, db = sh->list; db; db = db->next)
+ {
+ int error;
+ const char *errmsg, *addinfo, *dset;
+ /* display errors if any */
+ if (!db->con)
+ continue;
+ if ((error = ZOOM_connection_error_x(db->con, &errmsg, &addinfo,
+ &dset)))
+ {
+ printf("%s error: %s (%s:%d) %s\n",
+ ZOOM_connection_option_get(db->con, "host"), errmsg,
+ dset, error, addinfo);
+ ret = 1;
+ }
+ if (s[i])
+ {
+ size_t p, sz = ZOOM_scanset_size(s[i]);
+ for (p = 0; p < sz; p++)
+ {
+ size_t occ = 0;
+ size_t len = 0;
+ const char *term = ZOOM_scanset_display_term(s[i], p,
+ &occ, &len);
+ printf("%.*s %lld\n", (int) len, term, (long long int) occ);
+ }
+ ZOOM_scanset_destroy(s[i]);
+ }
+ i++;
+ }
+ xfree(s);
+ return ret;
+}
+
+static int cmd_sortby(struct zoom_sh *sh, const char **args)
+{
+ WRBUF strategy;
+ const char *criteria;
+ if (!(strategy = next_token_new_wrbuf(args)))
+ {
+ printf("missing argument argument: strategy and criteria\n");
+ return 1;
+ }
+ criteria = *args;
+ while (*criteria == ' ')
+ criteria++;
+ wrbuf_destroy(sh->strategy);
+ sh->strategy = strategy;
+
+ wrbuf_rewind(sh->criteria);
+ wrbuf_puts(sh->criteria, criteria);
+ return 0;
+}
+
+static int cmd_sort(struct zoom_sh *sh, const char **args)
+{
+ const char *sort_spec = *args;
+ int ret = 0;
+ struct zoom_db *db;
+
+ while (*sort_spec == ' ')
+ sort_spec++;
+
+ for (db = sh->list; db; db = db->next)
+ if (db->res)
+ ZOOM_resultset_sort(db->res, "yaz", sort_spec);
+ process_events(sh);
+ return ret;
+}
+
+static int cmd_help(struct zoom_sh *sh, const char **args)
+{
+ printf("connect <zurl>\n");
+ printf("search <pqf>\n");
+ printf("sortby <strategy> <criteria>\n");
+ printf("show [<start> [<count> [<type]]]\n");
+ printf("facets\n");
+ printf("scan <term>\n");
+ printf("quit\n");
+ printf("close <zurl>\n");
+ printf("ext <type>\n");
+ printf("set <option> [<value>]\n");
+ printf("get <option>\n");
+ printf("shell cmdline\n");
+ printf("\n");
+ printf("options:\n");
+ printf(" start\n");
+ printf(" count\n");
+ printf(" databaseName\n");
+ printf(" preferredRecordSyntax\n");
+ printf(" proxy\n");
+ printf(" elementSetName\n");
+ printf(" maximumRecordSize\n");
+ printf(" preferredRecordSize\n");
+ printf(" async\n");
+ printf(" piggyback\n");
+ printf(" group\n");
+ printf(" user\n");
+ printf(" password\n");
+ printf(" implementationName\n");
+ printf(" charset\n");
+ printf(" lang\n");
+ printf(" timeout\n");
+ printf(" facets\n");
+ printf(" extraArgs\n");
+ printf(" suggestions\n");
+ return 0;