Fixed bug #944: Allow extraction of multiple records per ES update.
[idzebra-moved-to-github.git] / index / zebrasrv.c
index 47e21cf..0980f8e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zebrasrv.c,v 1.8 2007-01-17 13:51:36 adam Exp $
+/* $Id: zebrasrv.c,v 1.11 2007-03-13 13:46:11 adam Exp $
    Copyright (C) 1995-2007
    Index Data ApS
 
@@ -262,7 +262,7 @@ static void search_terms(ZebraHandle zh, bend_search_rr *r)
 }
 
 
-static int busy_handler(void *client_data)
+static int break_handler(void *client_data)
 {
     bend_association assoc =(bend_association) client_data;    
     if (!bend_assoc_is_alive(assoc))
@@ -283,7 +283,7 @@ int bend_search(void *handle, bend_search_rr *r)
         zebra_result (zh, &r->errcode, &r->errstring);
         return 0;
     }
-    zebra_set_busy_handler(zh, busy_handler, r->association);
+    zebra_set_break_handler(zh, break_handler, r->association);
     yaz_log (YLOG_DEBUG, "ResultSet '%s'", r->setname);
     switch (r->query->which)
     {
@@ -309,7 +309,7 @@ int bend_search(void *handle, bend_search_rr *r)
     default:
         r->errcode = YAZ_BIB1_QUERY_TYPE_UNSUPP;
     }
-    zebra_set_busy_handler(zh, 0, 0);
+    zebra_set_break_handler(zh, 0, 0);
     return 0;
 }
 
@@ -712,7 +712,6 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr)
                                }
                                break;
                            case 2:
-                           case 4:
                                r = zebra_update_record(
                                    zh,
                                    0, /* recordType */
@@ -721,7 +720,8 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr)
                                    0, /* fname */
                                    (const char *) rec->u.octet_aligned->buf,
                                    rec->u.octet_aligned->len,
-                                   1);
+                                   0  /* force_update=0: action is a replace, so abort update if no corresponding record exists */
+                                   );
                                if (r == ZEBRA_FAIL)
                                {
                                    rr->errcode =
@@ -746,6 +746,24 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr)
                                    rr->errstring = "delete_record failed";
                                }
                                break;
+                           case 4:
+                               r = zebra_update_record(
+                                   zh,
+                                   0, /* recordType */
+                                   sysno,
+                                   0, /* match */
+                                   0, /* fname */
+                                   (const char *) rec->u.octet_aligned->buf,
+                                   rec->u.octet_aligned->len,
+                                   1  /* force_update=1: action is a specialUpdate, so allow replace or insert */
+                                   );
+                               if (r == ZEBRA_FAIL)
+                               {
+                                   rr->errcode =
+                                       YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED;
+                                   rr->errstring = "update_record failed";
+                               }
+                               break;
                            }                           
                        }
                     }
@@ -776,7 +794,7 @@ static void bend_start (struct statserv_options_block *sob)
        zebra_stop((ZebraService) sob->handle);
     res_set(default_res, "profilePath", DEFAULT_PROFILE_PATH);
     res_set(default_res, "modulePath", DEFAULT_MODULE_PATH);
-    sob->handle = zebra_start(sob->configname);
+    sob->handle = zebra_start_res(sob->configname, default_res, 0);
     res_close(default_res);
     if (!sob->handle)
     {