/* This file is part of Pazpar2.
- Copyright (C) 2006-2012 Index Data
+ Copyright (C) 2006-2013 Index Data
Pazpar2 is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
char *addinfo; // diagnostic info for most resent error
Odr_int hits;
int record_offset;
+ int show_stat_no;
int filtered; // When using local:, this will count the number of filtered records.
int maxrecs;
int startrecs;
}
}
-void client_record_response(struct client *cl)
+void client_record_response(struct client *cl, int *got_records)
{
struct connection *co = cl->connection;
ZOOM_connection link = connection_get_link(co);
else
{
client_record_ingest(cl);
+ *got_records = 1;
}
}
}
return strategy_plus_sort;
}
+void client_update_show_stat(struct client *cl, int cmd)
+{
+ if (cmd == 0)
+ cl->show_stat_no = 0;
+ else if (cmd == 1)
+ cl->show_stat_no++;
+}
+
+int client_fetch_more(struct client *cl)
+{
+ struct session_database *sdb = client_get_database(cl);
+ const char *str;
+ int extend_recs = 0;
+ int number;
+
+ yaz_log(YLOG_LOG, "cl=%s show_stat_no=%d got=%d",
+ client_get_id(cl), cl->show_stat_no, cl->record_offset);
+ if (cl->show_stat_no < cl->record_offset)
+ return 0;
+ yaz_log(YLOG_LOG, "cl=%s Trying to get more", client_get_id(cl));
+
+ str = session_setting_oneval(sdb, PZ_EXTENDRECS);
+ if (str && *str)
+ extend_recs = atoi(str);
+
+ if (extend_recs > cl->hits)
+ extend_recs = cl->hits;
+
+ number = extend_recs - cl->record_offset;
+ if (number > 0)
+ {
+ ZOOM_resultset set = cl->resultset;
+ struct connection *co = client_get_connection(cl);
+
+ str = session_setting_oneval(sdb, PZ_REQUESTSYNTAX);
+ ZOOM_resultset_option_set(set, "preferredRecordSyntax", str);
+ str = session_setting_oneval(sdb, PZ_ELEMENTS);
+ if (str && *str)
+ ZOOM_resultset_option_set(set, "elementSetName", str);
+
+ ZOOM_resultset_records(set, 0, cl->record_offset, number);
+ client_set_state(cl, Client_Working);
+ connection_continue(co);
+ return 1;
+ }
+ else
+ {
+ yaz_log(YLOG_LOG, "cl=%s. OK no more in total set", client_get_id(cl));
+ }
+ return 0;
+}
+
int client_parse_init(struct client *cl, int same_search)
{
cl->same_search = same_search;
for (s = sdb->settings[PZ_LIMITMAP]; s; s = s->next)
{
const char *p = strchr(s->name + 3, ':');
- if (p && !strcmp(p + 1, name) && s->value &&
- !strncmp(s->value, "local:", 6))
+ if (p && !strcmp(p + 1, name) && s->value)
{
- const char *cp = s->value + 6;
- while (*cp == ' ')
- cp++;
-
- nmem_strsplit_escape2(nmem, "|", value, values,
- num, 1, '\\', 1);
- (*l)++;
- return *cp ? cp : name;
+ int j, cnum;
+ char **cvalues;
+ nmem_strsplit_escape2(nmem, ",", s->value, &cvalues,
+ &cnum, 1, '\\', 1);
+ for (j = 0; j < cnum; j++)
+ {
+ const char *cvalue = cvalues[j];
+ while (*cvalue == ' ')
+ cvalue++;
+ if (!strncmp(cvalue, "local:", 6))
+ {
+ const char *cp = cvalue + 6;
+ while (*cp == ' ')
+ cp++;
+ nmem_strsplit_escape2(nmem, "|", value, values,
+ num, 1, '\\', 1);
+ (*l)++;
+ return *cp ? cp : name;
+ }
+ }
}
}
}
static int apply_limit(struct session_database *sdb,
facet_limits_t facet_limits,
- WRBUF w_pqf, CCL_bibset ccl_map)
+ WRBUF w_pqf, CCL_bibset ccl_map,
+ struct conf_service *service)
{
int ret = 0;
int i = 0;
{
struct setting *s = 0;
nmem_reset(nmem_tmp);
+ /* name="pz:limitmap:author" value="rpn:@attr 1=4|local:other" */
for (s = sdb->settings[PZ_LIMITMAP]; s; s = s->next)
{
const char *p = strchr(s->name + 3, ':');
{
char **values = 0;
int i, num = 0;
+ char **cvalues = 0;
+ int j, cnum = 0;
nmem_strsplit_escape2(nmem_tmp, "|", value, &values,
&num, 1, '\\', 1);
- if (!strncmp(s->value, "rpn:", 4))
- {
- const char *pqf = s->value + 4;
+ nmem_strsplit_escape2(nmem_tmp, ",", s->value, &cvalues,
+ &cnum, 1, '\\', 1);
- wrbuf_puts(w_pqf, "@and ");
- wrbuf_puts(w_pqf, pqf);
- wrbuf_puts(w_pqf, " ");
- for (i = 0; i < num; i++)
- {
- if (i < num - 1)
- wrbuf_puts(w_pqf, "@or ");
- yaz_encode_pqf_term(w_pqf, values[i],
- strlen(values[i]));
- }
- }
- else if (!strncmp(s->value, "ccl:", 4))
+ for (j = 0; ret == 0 && j < cnum; j++)
{
- const char *ccl = s->value + 4;
- WRBUF ccl_w = wrbuf_alloc();
- for (i = 0; i < num; i++)
+ const char *cvalue = cvalues[j];
+ while (*cvalue == ' ')
+ cvalue++;
+ if (!strncmp(cvalue, "rpn:", 4))
{
- int cerror, cpos;
- struct ccl_rpn_node *cn;
-
- wrbuf_rewind(ccl_w);
- wrbuf_puts(ccl_w, ccl);
- wrbuf_puts(ccl_w, "=\"");
- wrbuf_puts(ccl_w, values[i]);
- wrbuf_puts(ccl_w, "\"");
-
- cn = ccl_find_str(ccl_map, wrbuf_cstr(ccl_w),
- &cerror, &cpos);
- if (cn)
+ const char *pqf = cvalue + 4;
+ wrbuf_puts(w_pqf, "@and ");
+ wrbuf_puts(w_pqf, pqf);
+ wrbuf_puts(w_pqf, " ");
+ for (i = 0; i < num; i++)
{
- if (i == 0)
- wrbuf_printf(w_pqf, "@and ");
-
- /* or multiple values.. could be bad if last CCL
- parse fails, but this is unlikely to happen */
if (i < num - 1)
- wrbuf_printf(w_pqf, "@or ");
- ccl_pquery(w_pqf, cn);
- ccl_rpn_delete(cn);
+ wrbuf_puts(w_pqf, "@or ");
+ yaz_encode_pqf_term(w_pqf, values[i],
+ strlen(values[i]));
}
}
- wrbuf_destroy(ccl_w);
- }
- else if (!strncmp(s->value, "local:", 6)) {
- /* no operation */
- }
- else
- {
- yaz_log(YLOG_WARN, "Target %s: Bad limitmap '%s'",
- sdb->database->id, s->value);
- ret = -1; /* bad limitmap */
+ else if (!strncmp(cvalue, "ccl:", 4))
+ {
+ const char *ccl = cvalue + 4;
+ WRBUF ccl_w = wrbuf_alloc();
+ for (i = 0; i < num; i++)
+ {
+ int cerror, cpos;
+ struct ccl_rpn_node *cn;
+ wrbuf_rewind(ccl_w);
+ wrbuf_puts(ccl_w, ccl);
+ wrbuf_puts(ccl_w, "=\"");
+ wrbuf_puts(ccl_w, values[i]);
+ wrbuf_puts(ccl_w, "\"");
+
+ cn = ccl_find_str(ccl_map, wrbuf_cstr(ccl_w),
+ &cerror, &cpos);
+ if (cn)
+ {
+ if (i == 0)
+ wrbuf_printf(w_pqf, "@and ");
+
+ /* or multiple values.. could be bad if last
+ CCL parse fails, but this is unlikely to
+ happen */
+ if (i < num - 1)
+ wrbuf_printf(w_pqf, "@or ");
+ ccl_pquery(w_pqf, cn);
+ ccl_rpn_delete(cn);
+ }
+ }
+ wrbuf_destroy(ccl_w);
+ }
+ else if (!strncmp(cvalue, "local:", 6)) {
+ /* no operation */
+ }
+ else
+ {
+ yaz_log(YLOG_WARN, "Target %s: Bad limitmap '%s'",
+ sdb->database->id, cvalue);
+ ret = -1; /* bad limitmap */
+ }
+ break;
}
- break;
}
}
if (!s)
{
- yaz_log(YLOG_WARN, "Target %s: limit %s used, but no limitmap defined",
- (sdb->database ? sdb->database->id : "<no id>"), name);
+ int i;
+ for (i = 0; i < service->num_metadata; i++)
+ {
+ struct conf_metadata *md = service->metadata + i;
+ if (!strcmp(md->name, name) && md->limitcluster)
+ {
+ yaz_log(YLOG_LOG, "limitcluster in use for %s",
+ md->name);
+ break;
+ }
+ }
+ if (i == service->num_metadata)
+ {
+ yaz_log(YLOG_WARN, "Target %s: limit %s used, but no limitmap defined",
+ (sdb->database ? sdb->database->id : "<no id>"), name);
+ }
}
}
nmem_destroy(nmem_tmp);
// return -1 on query error
// return -2 on limit error
int client_parse_query(struct client *cl, const char *query,
- facet_limits_t facet_limits,
- CCL_bibset bibset)
+ facet_limits_t facet_limits)
{
struct session *se = client_get_session(cl);
+ struct conf_service *service = se->service;
struct session_database *sdb = client_get_database(cl);
struct ccl_rpn_node *cn;
int cerror, cpos;
ODR odr_out;
- CCL_bibset ccl_map = prepare_cclmap(cl, bibset);
+ CCL_bibset ccl_map = prepare_cclmap(cl, service->ccl_bibset);
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);
wrbuf_puts(w_pqf, " ");
}
- if (apply_limit(sdb, facet_limits, w_pqf, ccl_map))
+ if (apply_limit(sdb, facet_limits, w_pqf, ccl_map, service))
{
ccl_qual_rm(&ccl_map);
return -2;