GFS: bail out of fetch if last_in_set is set
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 20 Dec 2012 10:35:58 +0000 (11:35 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 20 Dec 2012 10:48:49 +0000 (11:48 +0100)
Until now, last_in_set, was only used as to indicate that
next-result-set-position should be set to zero.
http://www.loc.gov/z3950/agency/markup/04.html#Next-result-set-position
Based on patch from Ashley Sanders.

src/seshigh.c

index 2555823..5a6a26f 100644 (file)
@@ -671,7 +671,7 @@ static int retrieve_fetch(association *assoc, bend_fetch_rr *rr)
 static int srw_bend_fetch(association *assoc, int pos,
                           Z_SRW_searchRetrieveRequest *srw_req,
                           Z_SRW_record *record,
 static int srw_bend_fetch(association *assoc, int pos,
                           Z_SRW_searchRetrieveRequest *srw_req,
                           Z_SRW_record *record,
-                          const char **addinfo)
+                          const char **addinfo, int *last_in_set)
 {
     bend_fetch_rr rr;
     ODR o = assoc->encode;
 {
     bend_fetch_rr rr;
     ODR o = assoc->encode;
@@ -730,6 +730,8 @@ static int srw_bend_fetch(association *assoc, int pos,
 
     retrieve_fetch(assoc, &rr);
 
 
     retrieve_fetch(assoc, &rr);
 
+    *last_in_set = rr.last_in_set;
+
     if (rr.errcode && rr.surrogate_flag)
     {
         int code = yaz_diag_bib1_to_srw(rr.errcode);
     if (rr.errcode && rr.surrogate_flag)
     {
         int code = yaz_diag_bib1_to_srw(rr.errcode);
@@ -1088,6 +1090,7 @@ static void srw_bend_search(association *assoc,
                         for (i = 0; i<number; i++)
                         {
                             int errcode;
                         for (i = 0; i<number; i++)
                         {
                             int errcode;
+                            int last_in_set = 0;
                             const char *addinfo = 0;
 
                             srw_res->records[j].recordPacking = packing;
                             const char *addinfo = 0;
 
                             srw_res->records[j].recordPacking = packing;
@@ -1096,7 +1099,7 @@ static void srw_bend_search(association *assoc,
                             yaz_log(YLOG_DEBUG, "srw_bend_fetch %d", i+start);
                             errcode = srw_bend_fetch(assoc, i+start, srw_req,
                                                      srw_res->records + j,
                             yaz_log(YLOG_DEBUG, "srw_bend_fetch %d", i+start);
                             errcode = srw_bend_fetch(assoc, i+start, srw_req,
                                                      srw_res->records + j,
-                                                     &addinfo);
+                                                     &addinfo, &last_in_set);
                             if (errcode)
                             {
                                 yaz_add_srw_diagnostic(assoc->encode,
                             if (errcode)
                             {
                                 yaz_add_srw_diagnostic(assoc->encode,
@@ -1109,6 +1112,8 @@ static void srw_bend_search(association *assoc,
                             }
                             if (srw_res->records[j].recordData_buf)
                                 j++;
                             }
                             if (srw_res->records[j].recordData_buf)
                                 j++;
+                            if (last_in_set)
+                                break;
                         }
                         srw_res->num_records = j;
                         if (!j)
                         }
                         srw_res->num_records = j;
                         if (!j)
@@ -2595,6 +2600,8 @@ static Z_Records *pack_records(association *a, char *setname, Odr_int start,
             return 0;
         reclist->records[reclist->num_records] = thisrec;
         reclist->num_records++;
             return 0;
         reclist->records[reclist->num_records] = thisrec;
         reclist->num_records++;
+        if (freq.last_in_set)
+            break;
     }
     *num = reclist->num_records;
     return records;
     }
     *num = reclist->num_records;
     return records;