* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: client.c,v 1.277 2005-05-03 12:30:13 adam Exp $
+ * $Id: client.c,v 1.281 2005-05-09 11:01:07 adam Exp $
*/
#include <stdio.h>
#endif
#if HAVE_XML2
+static char *encode_SRW_term(ODR o, const char *q)
+{
+ const char *in_charset = "ISO-8859-1";
+ WRBUF w = wrbuf_alloc();
+ yaz_iconv_t cd;
+ char *res;
+ if (outputCharset)
+ in_charset = outputCharset;
+ cd = yaz_iconv_open("UTF-8", in_charset);
+ if (!cd)
+ {
+ wrbuf_free(w, 1);
+ return odr_strdup(o, q);
+ }
+ wrbuf_iconv_write(w, cd, q, strlen(q));
+ if (wrbuf_len(w))
+ {
+ int len = wrbuf_len(w);
+ res = odr_strdupn(o, wrbuf_buf(w), len);
+ }
+ else
+ res = odr_strdup(o, q);
+ yaz_iconv_close(cd);
+ wrbuf_free(w, 1);
+ return res;
+}
+
+
static int send_SRW_scanRequest(const char *arg, int pos, int num)
{
Z_SRW_PDU *sr = 0;
{
case QueryType_CQL:
sr->u.scan_request->query_type = Z_SRW_query_type_cql;
- sr->u.scan_request->scanClause.cql = odr_strdup(out, arg);
+ sr->u.scan_request->scanClause.cql = encode_SRW_term(out, arg);
break;
case QueryType_Prefix:
sr->u.scan_request->query_type = Z_SRW_query_type_pqf;
- sr->u.scan_request->scanClause.pqf = odr_strdup(out, arg);
+ sr->u.scan_request->scanClause.pqf = encode_SRW_term(out, arg);
break;
default:
printf ("Only CQL and PQF supported in SRW\n");
{
case QueryType_CQL:
srw_sr->u.request->query_type = Z_SRW_query_type_cql;
- srw_sr->u.request->query.cql = odr_strdup(srw_sr_odr_out, arg);
+ srw_sr->u.request->query.cql = encode_SRW_term(srw_sr_odr_out, arg);
sr->u.request->query_type = Z_SRW_query_type_cql;
- sr->u.request->query.cql = odr_strdup(out, arg);
+ sr->u.request->query.cql = encode_SRW_term(srw_sr_odr_out, arg);
break;
case QueryType_Prefix:
srw_sr->u.request->query_type = Z_SRW_query_type_pqf;
- srw_sr->u.request->query.pqf = odr_strdup(srw_sr_odr_out, arg);
+ srw_sr->u.request->query.pqf = encode_SRW_term(srw_sr_odr_out, arg);
sr->u.request->query_type = Z_SRW_query_type_pqf;
- sr->u.request->query.pqf = odr_strdup(out, arg);
+ sr->u.request->query.pqf = encode_SRW_term(srw_sr_odr_out, arg);
break;
default:
printf ("Only CQL and PQF supported in SRW\n");
#if HAVE_GETTIMEOFDAY
-struct timeval tv_start, tv_end;
+struct timeval tv_start;
#endif
#if HAVE_XML2
int res;
char *netbuffer= 0;
int netbufferlen = 0;
+#if HAVE_GETTIMEOFDAY
+ int got_tv_end = 0;
+ struct timeval tv_end;
+#endif
Z_GDU *gdu;
while(conn)
close_session();
break;
}
+#if HAVE_GETTIMEOFDAY
+ if (got_tv_end == 0)
+ gettimeofday (&tv_end, 0); /* count first one only */
+ got_tv_end++;
+#endif
odr_reset(out);
odr_reset(in); /* release APDU from last round */
record_last = 0;
if (conn && !cs_more(conn))
break;
}
- if (conn)
- {
#if HAVE_GETTIMEOFDAY
- gettimeofday (&tv_end, 0);
+ if (got_tv_end)
+ {
#if 0
printf ("S/U S/U=%ld/%ld %ld/%ld",
(long) tv_start.tv_sec,
printf ("Elapsed: %.6f\n",
(double) tv_end.tv_usec / 1e6 + tv_end.tv_sec -
((double) tv_start.tv_usec / 1e6 + tv_start.tv_sec));
-#endif
}
+#endif
xfree (netbuffer);
}
printf(" 8=element, 9=subelement, 10=elementType, 11=byte.\n");
printf("\nExamples:\n");
printf(" Search for a and b in-order at most 3 words apart:\n");
- printf(" @prox 0 3 1 2 k 2\n");
+ printf(" @prox 0 3 1 2 k 2 a b\n");
printf(" Search for any order of a and b next to each other:\n");
- printf(" @prox 0 1 0 3 k 2\n");
+ printf(" @prox 0 1 0 3 k 2 a b\n");
}
return 1;
}