From fb4ae0240d3f121281100e9a483c42e0f5577d15 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 20 Oct 2009 13:54:07 +0200 Subject: [PATCH] New setting: pz:pqf_strftime This setting does all what pqf_prefix does but more. It uses strftime conversions and reserves %% for the original PQF. --- doc/pazpar2_conf.xml | 17 +++++++++++++++++ src/client.c | 22 +++++++++++++++++++++- src/settings.c | 1 + src/settings.h | 1 + test/z3950_indexdata_com_marc.xml | 1 + 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/doc/pazpar2_conf.xml b/doc/pazpar2_conf.xml index b0d9a3b..9782efb 100644 --- a/doc/pazpar2_conf.xml +++ b/doc/pazpar2_conf.xml @@ -962,6 +962,23 @@ + pz:pqf_strftime + + + Allows you to extend a query with dates and operators. + The provided string allows certain substitutions and serves as a + format string. + The special two character sequence '%%' gets converted to the + original query. Other characters leading with the percent sign are + conversions supported by strftime. + All other characters are copied verbatim. For example, the string + @and @attr 1=30 @attr 2=3 %Y %% + would search for current year combined with the original PQF (%%). + + + + + pz:sort diff --git a/src/client.c b/src/client.c index 2cd05aa..22d1073 100644 --- a/src/client.c +++ b/src/client.c @@ -695,6 +695,7 @@ int client_parse_query(struct client *cl, const char *query) CCL_bibset ccl_map = prepare_cclmap(cl); const char *sru = session_setting_oneval(sdb, PZ_SRU); const char *pqf_prefix = session_setting_oneval(sdb, PZ_PQF_PREFIX); + const char *pqf_strftime = session_setting_oneval(sdb, PZ_PQF_STRFTIME); if (!ccl_map) return -1; @@ -715,7 +716,26 @@ int client_parse_query(struct client *cl, const char *query) wrbuf_puts(se->wrbuf, pqf_prefix); wrbuf_puts(se->wrbuf, " "); } - ccl_pquery(se->wrbuf, cn); + if (!pqf_strftime || !*pqf_strftime) + ccl_pquery(se->wrbuf, cn); + else + { + time_t cur_time = time(0); + struct tm *tm = localtime(&cur_time); + char tmp_str[300]; + const char *cp = tmp_str; + + /* see man strftime(3) for things .. In particular %% gets converted + to %.. And That's our original query .. */ + strftime(tmp_str, sizeof(tmp_str)-1, pqf_strftime, tm); + for (; *cp; cp++) + { + if (cp[0] == '%') + ccl_pquery(se->wrbuf, cn); + else + wrbuf_putc(se->wrbuf, cp[0]); + } + } xfree(cl->pquery); cl->pquery = xstrdup(wrbuf_cstr(se->wrbuf)); diff --git a/src/settings.c b/src/settings.c index db5d7ce..34159eb 100644 --- a/src/settings.c +++ b/src/settings.c @@ -67,6 +67,7 @@ static char *hard_settings[] = { "pz:pqf_prefix", "pz:sort", "pz:recordfilter", + "pz:pqf_strftime", 0 }; diff --git a/src/settings.h b/src/settings.h index e1c575e..44ebd6d 100644 --- a/src/settings.h +++ b/src/settings.h @@ -40,6 +40,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define PZ_PQF_PREFIX 17 #define PZ_SORT 18 #define PZ_RECORDFILTER 19 +#define PZ_PQF_STRFTIME 20 struct setting { diff --git a/test/z3950_indexdata_com_marc.xml b/test/z3950_indexdata_com_marc.xml index 26b7bf5..65a3289 100644 --- a/test/z3950_indexdata_com_marc.xml +++ b/test/z3950_indexdata_com_marc.xml @@ -21,6 +21,7 @@ + -- 1.7.10.4