zoom: one common search task
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 22 Jan 2014 14:07:26 +0000 (15:07 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 22 Jan 2014 14:07:26 +0000 (15:07 +0100)
This simplifies some things but require us to note if a result
set is live or not (live_set), so that we know if a search is
required. Eventually this will allow us to postpone search/retrieve
when caching is fully functional.

src/zoom-c.c
src/zoom-p.h
src/zoom-sru.c
src/zoom-z3950.c

index 8a9b344..241444f 100644 (file)
@@ -136,9 +136,6 @@ void ZOOM_connection_show_task(ZOOM_task task)
     case ZOOM_TASK_SEARCH:
         yaz_log(YLOG_LOG, "search p=%p", task);
         break;
-    case ZOOM_TASK_RETRIEVE:
-        yaz_log(YLOG_LOG, "retrieve p=%p", task);
-        break;
     case ZOOM_TASK_CONNECT:
         yaz_log(YLOG_LOG, "connect p=%p", task);
         break;
@@ -201,12 +198,6 @@ void ZOOM_connection_remove_task(ZOOM_connection c)
             xfree(task->u.search.elementSetName);
             xfree(task->u.search.schema);
             break;
-        case ZOOM_TASK_RETRIEVE:
-            resultset_destroy(task->u.retrieve.resultset);
-            xfree(task->u.retrieve.syntax);
-            xfree(task->u.retrieve.elementSetName);
-            xfree(task->u.retrieve.schema);
-            break;
         case ZOOM_TASK_CONNECT:
             break;
         case ZOOM_TASK_SCAN:
@@ -733,6 +724,7 @@ ZOOM_resultset ZOOM_resultset_create(void)
 #endif
     resultset_use(1);
     r->mc_key = 0;
+    r->live_set = 0;
     return r;
 }
 
@@ -992,19 +984,19 @@ static void ZOOM_resultset_retrieve(ZOOM_resultset r,
             c->reconnect_ok = 1;
         }
     }
-    task = ZOOM_connection_add_task(c, ZOOM_TASK_RETRIEVE);
-    task->u.retrieve.resultset = r;
-    task->u.retrieve.start = start;
-    task->u.retrieve.count = count;
+    task = ZOOM_connection_add_task(c, ZOOM_TASK_SEARCH);
+    task->u.search.resultset = r;
+    task->u.search.start = start;
+    task->u.search.count = count;
 
     syntax = ZOOM_options_get(r->options, "preferredRecordSyntax");
-    task->u.retrieve.syntax = syntax ? xstrdup(syntax) : 0;
+    task->u.search.syntax = syntax ? xstrdup(syntax) : 0;
     elementSetName = ZOOM_options_get(r->options, "elementSetName");
-    task->u.retrieve.elementSetName = elementSetName
+    task->u.search.elementSetName = elementSetName
         ? xstrdup(elementSetName) : 0;
 
     cp = ZOOM_options_get(r->options, "schema");
-    task->u.retrieve.schema = cp ? xstrdup(cp) : 0;
+    task->u.search.schema = cp ? xstrdup(cp) : 0;
 
     ZOOM_resultset_addref(r);
 
@@ -1502,12 +1494,6 @@ ZOOM_API(int)
             else
                 ret = ZOOM_connection_Z3950_send_search(c);
             break;
-        case ZOOM_TASK_RETRIEVE:
-            if (c->proto == PROTO_HTTP)
-                ret = ZOOM_connection_srw_send_search(c);
-            else
-                ret = send_Z3950_present(c);
-            break;
         case ZOOM_TASK_CONNECT:
             ret = do_connect(c);
             break;
index a2cab30..5d4ee61 100644 (file)
@@ -143,6 +143,7 @@ struct ZOOM_resultset_p {
     int num_facets;
     char **facets_names;
     WRBUF mc_key;
+    int live_set;
 };
 
 struct facet_term_p {
@@ -192,15 +193,6 @@ struct ZOOM_task_p {
             char *schema;
             int recv_search_fired;
         } search;
-#define ZOOM_TASK_RETRIEVE 2
-        struct {
-            int start;
-            ZOOM_resultset resultset;
-            int count;
-            char *syntax;
-            char *elementSetName;
-            char *schema;
-        } retrieve;
 #define ZOOM_TASK_CONNECT 3
 #define ZOOM_TASK_SCAN 4
         struct {
index 4e8807b..8f5feb0 100644 (file)
@@ -171,12 +171,6 @@ zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c)
             facet_list = yaz_pqf_parse_facet_list(c->odr_out, facets);
         schema = c->tasks->u.search.schema;
         break;
-    case ZOOM_TASK_RETRIEVE:
-        resultset = c->tasks->u.retrieve.resultset;
-        schema = c->tasks->u.retrieve.schema;
-
-        start = &c->tasks->u.retrieve.start;
-        count = &c->tasks->u.retrieve.count;
 
         if (*start >= resultset->size)
             return zoom_complete;
@@ -187,8 +181,8 @@ zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c)
         {
             ZOOM_record rec =
                 ZOOM_record_cache_lookup(resultset, i + *start,
-                                         c->tasks->u.retrieve.syntax,
-                                         c->tasks->u.retrieve.elementSetName,
+                                         c->tasks->u.search.syntax,
+                                         c->tasks->u.search.elementSetName,
                                          schema);
             if (!rec)
                 break;
@@ -292,14 +286,6 @@ static zoom_ret handle_srw_response(ZOOM_connection c,
         if (res->facetList)
             ZOOM_handle_facet_list(resultset, res->facetList);
         break;
-    case ZOOM_TASK_RETRIEVE:
-        resultset = c->tasks->u.retrieve.resultset;
-        start = &c->tasks->u.retrieve.start;
-        count = &c->tasks->u.retrieve.count;
-        syntax = c->tasks->u.retrieve.syntax;
-        elementSetName = c->tasks->u.retrieve.elementSetName;
-        schema = c->tasks->u.retrieve.schema;
-        break;
     default:
         return zoom_complete;
     }
index a16a809..8a1d393 100644 (file)
@@ -639,8 +639,8 @@ zoom_ret ZOOM_connection_Z3950_send_search(ZOOM_connection c)
     int lslb, ssub, mspn;
     const char *syntax;
     const char *schema;
-    Z_APDU *apdu = zget_APDU(c->odr_out, Z_APDU_searchRequest);
-    Z_SearchRequest *search_req = apdu->u.searchRequest;
+    Z_APDU *apdu;
+    Z_SearchRequest *search_req;
     const char *elementSetName;
     const char *smallSetElementSetName;
     const char *mediumSetElementSetName;
@@ -650,6 +650,11 @@ zoom_ret ZOOM_connection_Z3950_send_search(ZOOM_connection c)
     assert(c->tasks->which == ZOOM_TASK_SEARCH);
 
     r = c->tasks->u.search.resultset;
+    if (r->live_set)
+        return send_Z3950_present(c);
+
+    apdu = zget_APDU(c->odr_out, Z_APDU_searchRequest);
+    search_req = apdu->u.searchRequest;
 
     yaz_log(c->log_details, "%p ZOOM_connection_send_search set=%p", c, r);
 
@@ -1273,6 +1278,7 @@ static void handle_Z3950_search_response(ZOOM_connection c,
     handle_facet_result(c, resultset, sr->additionalSearchInfo);
 
     resultset->size = *sr->resultCount;
+    resultset->live_set = 1;
 
 #if HAVE_LIBMEMCACHED_MEMCACHED_H
     if (c->mc_st)
@@ -1346,15 +1352,6 @@ static void handle_Z3950_records(ZOOM_connection c, Z_Records *sr,
         elementSetName = c->tasks->u.search.elementSetName;
         schema =  c->tasks->u.search.schema;
         break;
-    case ZOOM_TASK_RETRIEVE:
-        resultset = c->tasks->u.retrieve.resultset;
-        start = &c->tasks->u.retrieve.start;
-        count = &c->tasks->u.retrieve.count;
-        syntax = c->tasks->u.retrieve.syntax;
-        elementSetName = c->tasks->u.retrieve.elementSetName;
-        schema =  c->tasks->u.retrieve.schema;
-        break;
-    default:
         return;
     }
     if (sr && sr->which == Z_Records_NSD)
@@ -1487,14 +1484,6 @@ zoom_ret send_Z3950_present(ZOOM_connection c)
         elementSetName = c->tasks->u.search.elementSetName;
         schema =  c->tasks->u.search.schema;
         break;
-    case ZOOM_TASK_RETRIEVE:
-        resultset = c->tasks->u.retrieve.resultset;
-        start = &c->tasks->u.retrieve.start;
-        count = &c->tasks->u.retrieve.count;
-        syntax = c->tasks->u.retrieve.syntax;
-        elementSetName = c->tasks->u.retrieve.elementSetName;
-        schema = c->tasks->u.retrieve.schema;
-        break;
     default:
         return zoom_complete;
     }