Fixed bug #1628: show command returns zero hits when searching a slow target.
[pazpar2-moved-to-github.git] / src / client.c
index 197c121..f42ec23 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: client.c,v 1.21 2007-09-19 13:00:01 adam Exp $
+/* $Id: client.c,v 1.23 2007-09-20 08:13:27 adam Exp $
    Copyright (c) 2006-2007, Index Data.
 
 This file is part of Pazpar2.
@@ -101,7 +101,8 @@ static const char *client_states[] = {
     "Client_Error",
     "Client_Failed",
     "Client_Disconnected",
-    "Client_Stopped"
+    "Client_Stopped",
+    "Client_Continue"
 };
 
 static struct client *client_freelist = 0;
@@ -612,7 +613,13 @@ void client_search_response(struct client *cl, Z_APDU *a)
     if (*r->searchStatus)
     {
        cl->hits = *r->resultCount;
-        se->total_hits += cl->hits;
+        if (cl->hits < 0)
+        {
+            yaz_log(YLOG_WARN, "Target %s returns hit count %d",
+                    cl->database->database->url, cl->hits);
+        }
+        else
+            se->total_hits += cl->hits;
         if (r->presentStatus && !*r->presentStatus && r->records)
         {
             yaz_log(YLOG_DEBUG, "Records in search response %s", 
@@ -811,7 +818,7 @@ void client_continue(struct client *cl)
     if (cl->state == Client_Connected) {
         client_init_request(cl);
     }
-    if (cl->state == Client_Idle)
+    if (cl->state == Client_Continue || cl->state == Client_Idle)
     {
         struct session *se = client_get_session(cl);
         if (cl->requestid != se->requestid && cl->pquery) {
@@ -827,6 +834,8 @@ void client_continue(struct client *cl)
             cl->records < cl->hits) {
             client_send_present(cl);
         }
+        else
+            client_set_state(cl, Client_Idle);
     }
 }
 
@@ -971,7 +980,8 @@ void client_set_session(struct client *cl, struct session *se)
 
 int client_is_active(struct client *cl)
 {
-    if (cl->connection && (cl->state == Client_Connecting ||
+    if (cl->connection && (cl->state == Client_Continue ||
+                           cl->state == Client_Connecting ||
                            cl->state == Client_Initializing ||
                            cl->state == Client_Searching ||
                            cl->state == Client_Presenting))