From: Adam Dickmeiss Date: Wed, 4 May 2011 15:22:23 +0000 (+0200) Subject: CQL: start work on cql_sortby_to_sortkeys X-Git-Tag: v4.2.0~32 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=4d827d4162155ab4514acb05dd2a1a38c29f4bcf;p=yaz-moved-to-github.git CQL: start work on cql_sortby_to_sortkeys --- diff --git a/include/yaz/cql.h b/include/yaz/cql.h index c9df2ac..83b6217 100644 --- a/include/yaz/cql.h +++ b/include/yaz/cql.h @@ -386,6 +386,37 @@ int cql_strcmp(const char *s1, const char *s2); YAZ_EXPORT int cql_strncmp(const char *s1, const char *s2, size_t n); +/** \brief converts CQL sortby to sortkeys (ala versions 1.1) + \param cn CQL tree + \param pr print function + \param client_data data to be passed to pr function + + This will take CQL_NODE_SORT entries and conver them to + + path,schema,ascending,caseSensitive,missingValue + items.. + + One for each sort keys. Where + + path is string index for sorting + + schema is schema for sort index + + ascending is a boolean (0=false, 1=true). Default is true. + + caseSensitive is a boolean. Default is false. + + missingValue is a string and one of 'abort', 'highValue', 'lowValue', + or 'omit'. Default is 'highValue'. + + See also + http://www.loc.gov/standards/sru/sru1-1archive/search-retrieve-operation.html#sort +*/ +YAZ_EXPORT +int cql_sortby_to_sortkeys(struct cql_node *cn, + void (*pr)(const char *buf, void *client_data), + void *client_data); + YAZ_END_CDECL #endif diff --git a/src/Makefile.am b/src/Makefile.am index 5aeb22c..31343c5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -94,7 +94,8 @@ libyaz_la_SOURCES=version.c options.c log.c \ grs1disp.c zgdu.c soap.c srw.c srwutil.c uri.c solr.c \ opacdisp.c cclfind.c ccltoken.c cclerrms.c cclqual.c cclptree.c cclp.h \ cclqfile.c cclstr.c cclxmlconfig.c ccl_stop_words.c \ - cql.y cqlstdio.c cqltransform.c cqlutil.c xcqlutil.c cqlstring.c rpn2cql.c \ + cql.y cqlstdio.c cqltransform.c cqlutil.c xcqlutil.c cqlstring.c \ + cql_sortkeys.c rpn2cql.c \ rpn2solr.c solrtransform.c \ cqlstrer.c querytowrbuf.c \ tcpdchk.c \ diff --git a/src/cql_sortkeys.c b/src/cql_sortkeys.c new file mode 100644 index 0000000..cdbdf7e --- /dev/null +++ b/src/cql_sortkeys.c @@ -0,0 +1,86 @@ +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2011 Index Data + * See the file LICENSE for details. + */ +/** + * \file cql_sortkeys.c + * \brief CQL sortkeys utilities + * + */ +#if HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +static void pr_n(void (*pr)(const char *buf, void *client_data), + const char *buf, int len, void *client_data) +{ + char tmp[4]; + int left = len; + + while (left > 0) + { + if (left >= sizeof(tmp)) + { + memcpy(tmp, buf, sizeof(tmp)-1); + tmp[sizeof(tmp)-1] = '\0'; + left = left - (sizeof(tmp)-1); + } + else + { + strcpy(tmp, buf); + left = 0; + } + pr(client_data, tmp); + } +} + +int cql_sortby_to_sortkeys(struct cql_node *cn, + void (*pr)(const char *buf, void *client_data), + void *client_data) +{ + if (cn && cn->which == CQL_NODE_SORT) + { + for (; cn; cn = cn->u.sort.next) + { + int ascending = 1; + int caseSensitive = 0; + const char *missingValue = 0; + const char *indx = cn->u.sort.index; + + if (indx) + { + const char *s = strchr(indx, '.'); + if (s) + { + pr(s+1, client_data); + pr(",", client_data); + pr_n(pr, indx, s - indx, client_data); + } + else + { + pr(indx, client_data); + pr(",", client_data); + } + pr(",", client_data); + } + if (cn->u.sort.next) + pr(" ", client_data); + } + } +} + +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/win/makefile b/win/makefile index 05269e8..89827cb 100644 --- a/win/makefile +++ b/win/makefile @@ -503,6 +503,7 @@ MISC_OBJS= \ $(OBJDIR)\xmlerror.obj \ $(OBJDIR)\mime.obj \ $(OBJDIR)\cql.obj \ + $(OBJDIR)\cql_sortkeys.obj \ $(OBJDIR)\cqlstdio.obj \ $(OBJDIR)\cqlstring.obj \ $(OBJDIR)\cqltransform.obj \