#include <stdio.h>
#include <yaz/rpn2cql.h>
+#include <yaz/rpn2solr.h>
#include <yaz/pquery.h>
#include <yaz/options.h>
static void usage(void)
{
- fprintf(stderr, "usage\n cql2pqf [-n <n>] [-r] [-S] <properties> "
+ fprintf(stderr, "usage\n cql2pqf [-n <n>] [-r] [-s] [-S] <properties> "
"[<query>]\n");
+ fprintf(stderr, " -r reverse conversion (RPN to Solr/CQL)\n");
+ fprintf(stderr, " -s Solr instead of CQL\n");
+ fprintf(stderr, " -S strict CQL 2.0\n");
exit(1);
}
char *query = 0;
char *fname = 0;
int reverse = 0;
+ int solr = 0;
int verbose = 0;
int do_strict = 0;
int ret;
char *arg;
- while ((ret = options("n:rSv", argv, argc, &arg)) != -2)
+ while ((ret = options("n:rsSv", argv, argc, &arg)) != -2)
{
switch (ret)
{
case 'S':
do_strict = 1;
break;
+ case 's':
+ solr = 1;
+ break;
case 'v':
verbose = 1;
break;
usage();
}
}
- if (!fname)
- usage();
- if (!strcmp(fname, "-"))
- ct = cql_transform_create();
- else
- ct = cql_transform_open_fname(fname);
- if (!ct)
+ if (fname)
{
- fprintf(stderr, "failed to read properties %s\n", fname);
- exit(1);
+ ct = cql_transform_open_fname(fname);
+ if (!ct)
+ {
+ fprintf(stderr, "failed to read properties %s\n", fname);
+ exit(1);
+ }
}
+ else
+ ct = cql_transform_create();
if (reverse)
{
if (!query)
{
if (fgets(buf, sizeof buf, stdin))
+ {
+ if (*buf && buf[strlen(buf)-1] == '\n')
+ buf[strlen(buf)-1] = '\0';
query = buf;
+ }
}
if (query)
{
}
else
{
- int ret = cql_transform_rpn2cql_stream(ct, cql_fputs,
+ int ret = 0;
+ if (solr)
+ ret = solr_transform_rpn2solr_stream(ct, cql_fputs,
+ stdout, rpn);
+ else
+ ret = cql_transform_rpn2cql_stream(ct, cql_fputs,
stdout, rpn);
-
if (ret)
{
const char *addinfo;
if (r)
fprintf(stderr, "Syntax error\n");
+ else if (solr)
+ {
+ printf("CQL to Solr not supported (supported is reverse -r)\n");
+ }
else
{
r = cql_transform_FILE(ct, cql_parser_result(cp), stdout);