From: Adam Dickmeiss Date: Fri, 6 May 2011 12:56:51 +0000 (+0200) Subject: cql_sortby_to_sortkeys: handle modifiers. X-Git-Tag: v4.2.0~31 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=dd993ee2910a754d46b2223c06b09abdd61caceb;p=yaz-moved-to-github.git cql_sortby_to_sortkeys: handle modifiers. And add cql_sortby_to_sortkeys_buf. --- diff --git a/include/yaz/cql.h b/include/yaz/cql.h index 83b6217..2ec9776 100644 --- a/include/yaz/cql.h +++ b/include/yaz/cql.h @@ -417,6 +417,16 @@ int cql_sortby_to_sortkeys(struct cql_node *cn, void (*pr)(const char *buf, void *client_data), void *client_data); +/** \brief converts CQL sortby to sortkeys .. + \param cn CQL tree + \param out result buffer + \param max size of buffer (allocated) + \retval 0 OK + \retval -1 ERROR +*/ +YAZ_EXPORT +int cql_sortby_to_sortkeys_buf(struct cql_node *cn, char *out, int max); + YAZ_END_CDECL #endif diff --git a/src/cql_sortkeys.c b/src/cql_sortkeys.c index cdbdf7e..2ef3740 100644 --- a/src/cql_sortkeys.c +++ b/src/cql_sortkeys.c @@ -40,17 +40,52 @@ static void pr_n(void (*pr)(const char *buf, void *client_data), } } +static int cql_sort_modifiers(struct cql_node *cn, + void (*pr)(const char *buf, void *client_data), + void *client_data) +{ + int ascending = 1; + int caseSensitive = 0; + const char *missingValue = "highValue"; + for (; cn; cn = cn->u.st.modifiers) + { + const char *indx = cn->u.st.index; + if (!strcmp(indx, "ignoreCase")) + caseSensitive = 0; + else if (!strcmp(indx, "respectCase")) + caseSensitive = 1; + else if (!strcmp(indx, "ascending")) + ascending = 1; + else if (!strcmp(indx, "descending")) + ascending = 0; + else if (!strcmp(indx, "missingOmit")) + missingValue = "omit"; + else if (!strcmp(indx, "missingFail")) + missingValue = "abort"; + else if (!strcmp(indx, "missingLow")) + missingValue = "lowValue"; + else if (!strcmp(indx, "missingHigh")) + missingValue = "highValue"; + else + return -1; + } + pr(ascending ? "1" : "0", client_data); + pr(",", client_data); + pr(caseSensitive ? "1" : "0", client_data); + pr(",", client_data); + pr(missingValue, client_data); + return 0; +} + int cql_sortby_to_sortkeys(struct cql_node *cn, void (*pr)(const char *buf, void *client_data), void *client_data) { + int r = 0; 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) @@ -68,11 +103,29 @@ int cql_sortby_to_sortkeys(struct cql_node *cn, pr(",", client_data); } pr(",", client_data); + r = cql_sort_modifiers(cn->u.sort.modifiers, pr, client_data); + if (r) + break; + if (cn->u.sort.next) + pr(" ", client_data); } - if (cn->u.sort.next) - pr(" ", client_data); } } + return r; +} + +int cql_sortby_to_sortkeys_buf(struct cql_node *cn, char *out, int max) +{ + struct cql_buf_write_info info; + int r; + + info.off = 0; + info.max = max; + info.buf = out; + r = cql_sortby_to_sortkeys(cn, cql_buf_write_handler, &info); + if (info.off >= 0) + info.buf[info.off] = '\0'; + return r; } /*