Work on fetch more
[pazpar2-moved-to-github.git] / src / client.c
index 0618d3a..5f05633 100644 (file)
@@ -1,5 +1,5 @@
 /* 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
@@ -762,6 +762,24 @@ static const char *get_strategy_plus_sort(struct client *l, const char *field)
     return strategy_plus_sort;
 }
 
+int client_fetch_more(struct client *cl)
+{
+    int extra = cl->hits - cl->record_offset;
+    if (extra > 0)
+    {
+        ZOOM_resultset set = cl->resultset;
+        int max_extra = 10;
+
+        if (extra > max_extra)
+            extra = max_extra;
+
+        ZOOM_resultset_records(set, 0, cl->record_offset, extra);
+        client_set_state(cl, Client_Working);
+        return 1;
+    }
+    return 0;
+}
+
 int client_parse_init(struct client *cl, int same_search)
 {
     cl->same_search = same_search;
@@ -1174,7 +1192,8 @@ const char *client_get_facet_limit_local(struct client *cl,
 
 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;
@@ -1268,8 +1287,22 @@ static int apply_limit(struct session_database *sdb,
         }
         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);
@@ -1283,15 +1316,15 @@ static int apply_limit(struct session_database *sdb,
 // 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);
@@ -1313,7 +1346,7 @@ int client_parse_query(struct client *cl, const char *query,
         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;