New optional argument, startrecs, for cmd=search
[pazpar2-moved-to-github.git] / src / client.c
index b34cb60..e3b34cb 100644 (file)
@@ -74,6 +74,8 @@ struct client {
     char *cqlquery; // used for SRU targets only
     int hits;
     int record_offset;
+    int maxrecs;
+    int startrecs;
     int diagnostic;
     enum client_state state;
     struct show_raw *show_raw;
@@ -403,7 +405,7 @@ void client_search_response(struct client *cl)
     }
     else
     {
-        cl->record_offset = 0;
+        cl->record_offset = cl->startrecs;
         cl->hits = ZOOM_resultset_size(resultset);
         se->total_hits += cl->hits;
     }
@@ -497,6 +499,7 @@ void client_start_search(struct client *cl)
     const char *opt_maxrecs = session_setting_oneval(sdb, PZ_MAXRECS);
     const char *opt_sru = session_setting_oneval(sdb, PZ_SRU);
     const char *opt_sort = session_setting_oneval(sdb, PZ_SORT);
+    char maxrecs_str[24];
 
     assert(link);
 
@@ -517,16 +520,31 @@ void client_start_search(struct client *cl)
         ZOOM_connection_option_set(link, "elementSetName", opt_elements);
     if (*opt_requestsyn)
         ZOOM_connection_option_set(link, "preferredRecordSyntax", opt_requestsyn);
-    if (*opt_maxrecs)
-        ZOOM_connection_option_set(link, "count", opt_maxrecs);
+
+    if (!*opt_maxrecs)
+    {
+        sprintf(maxrecs_str, "%d", cl->maxrecs);
+        opt_maxrecs = maxrecs_str;
+    }
+    ZOOM_connection_option_set(link, "count", opt_maxrecs);
+
+
+    if (atoi(opt_maxrecs) > 20)
+        ZOOM_connection_option_set(link, "presentChunk", "20");
     else
-        ZOOM_connection_option_set(link, "count", "100");
+        ZOOM_connection_option_set(link, "presentChunk", opt_maxrecs);
+
+    if (cl->startrecs)
+    {
+        char startrecs_str[24];
+        sprintf(startrecs_str, "%d", cl->startrecs);
+        
+        ZOOM_connection_option_set(link, "start", startrecs_str);
+    }
 
     if (databaseName)
         ZOOM_connection_option_set(link, "databaseName", databaseName);
 
-    ZOOM_connection_option_set(link, "presentChunk", "20");
-        
     if (cl->cqlquery)
     {
         ZOOM_query q = ZOOM_query_create();
@@ -557,6 +575,8 @@ struct client *client_create(void)
     }
     else
         r = xmalloc(sizeof(struct client));
+    r->maxrecs = 100;
+    r->startrecs = 0;
     r->pquery = 0;
     r->cqlquery = 0;
     r->database = 0;
@@ -780,6 +800,16 @@ const char *client_get_url(struct client *cl)
     return client_get_database(cl)->database->url;
 }
 
+void client_set_maxrecs(struct client *cl, int v)
+{
+    cl->maxrecs = v;
+}
+
+void client_set_startrecs(struct client *cl, int v)
+{
+    cl->startrecs = v;
+}
+
 /*
  * Local variables:
  * c-basic-offset: 4