Fix issue that would disable the re-search when doing position sorting
authorDennis Schafroth <dennis@indexdata.com>
Thu, 23 Aug 2012 12:52:50 +0000 (14:52 +0200)
committerDennis Schafroth <dennis@indexdata.com>
Thu, 23 Aug 2012 12:52:50 +0000 (14:52 +0200)
src/session.c

index 6ac2276..e391b82 100644 (file)
@@ -664,27 +664,32 @@ void session_sort(struct session *se, const char *field, int increasing,
         session_leave(se);
         return;
     }
+    session_log(se, YLOG_DEBUG, "search_sort: field=%s increasing=%d position=%d must fetch",
+                field, increasing, position);
     if (position)
     {
+        yaz_log(YLOG_DEBUG, "Reset results due to position");
         session_clear_set(se, field, increasing, position);
     }
-
-    session_log(se, YLOG_DEBUG, "search_sort: field=%s increasing=%d position=%d must fetch",
-                field, increasing, position);
-    sr = nmem_malloc(se->nmem, sizeof(*sr));
-    sr->field = nmem_strdup(se->nmem, field);
-    sr->increasing = increasing;
-    sr->position = position;
-    sr->next = se->sorted_results;
-    se->sorted_results = sr;
-        
+    else {
+        sr = nmem_malloc(se->nmem, sizeof(*sr));
+        sr->field = nmem_strdup(se->nmem, field);
+        sr->increasing = increasing;
+        sr->position = position;
+        sr->next = se->sorted_results;
+        se->sorted_results = sr;
+    }
+    yaz_log(YLOG_DEBUG, "Restarting search for clients due to change in sort order");
+    
     for (l = se->clients_active; l; l = l->next)
     {
         struct client *cl = l->client;
         if (client_get_state(cl) == Client_Connecting ||
             client_get_state(cl) == Client_Idle ||
-            client_get_state(cl) == Client_Working)
+            client_get_state(cl) == Client_Working) {
+            yaz_log(YLOG_DEBUG, "Client %s: Restarting search due to change in sort order", client_get_id(cl));
             client_start_search(cl);
+        }
     }
     session_leave(se);
 }