zoom: set ZOOM options WRT retrieval before search
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 15 Aug 2011 13:55:04 +0000 (15:55 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 15 Aug 2011 13:55:04 +0000 (15:55 +0200)
This is to ensure that records that we get back by piggyback have the
greatest chance of being "identical" and cached properly for following
present.

src/filter_zoom.cpp

index 5f647da..533da78 100644 (file)
@@ -114,6 +114,15 @@ namespace metaproxy_1 {
                                                   int *error,
                                                   char **addinfo,
                                                   ODR odr);
+
+
+            void prepare_elements(BackendPtr b,
+                                  Odr_oid *preferredRecordSyntax,
+                                  const char *element_set_name,
+                                  bool &enable_pz2_retrieval,
+                                  bool &enable_pz2_transform,
+                                  bool &assume_marc8_charset);
+
             Z_Records *get_records(Odr_int start,
                                    Odr_int number_to_present,
                                    int *error,
@@ -751,7 +760,8 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
         b->set_option("apdulog", "1");
 
     if (sptr->piggyback)
-        b->set_option("count", "10");
+        b->set_option("count", "1"); /* some SRU servers INSIST on getting
+                                        maximumRecords > 0 */
     b->set_option("piggyback", sptr->piggyback ? "1" : "0");
 
     std::string authentication = sptr->authentication;
@@ -914,31 +924,14 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
     return b;
 }
 
-Z_Records *yf::Zoom::Frontend::get_records(Odr_int start,
-                                           Odr_int number_to_present,
-                                           int *error,
-                                           char **addinfo,
-                                           Odr_int *number_of_records_returned,
-                                           ODR odr,
-                                           BackendPtr b,
-                                           Odr_oid *preferredRecordSyntax,
-                                           const char *element_set_name)
-{
-    *number_of_records_returned = 0;
-    Z_Records *records = 0;
-    bool enable_pz2_retrieval = false; // whether target profile is used
-    bool enable_pz2_transform = false; // whether XSLT is used as well
-    bool assume_marc8_charset = false;
-
-    if (start < 0 || number_to_present <= 0)
-        return records;
-    
-    if (number_to_present > 10000)
-        number_to_present = 10000;
-    
-    ZOOM_record *recs = (ZOOM_record *)
-        odr_malloc(odr, (size_t) number_to_present * sizeof(*recs));
+void yf::Zoom::Frontend::prepare_elements(BackendPtr b,
+                                          Odr_oid *preferredRecordSyntax,
+                                          const char *element_set_name,
+                                          bool &enable_pz2_retrieval,
+                                          bool &enable_pz2_transform,
+                                          bool &assume_marc8_charset)
 
+{
     char oid_name_str[OID_STR_MAX];
     const char *syntax_name = 0;
     
@@ -959,9 +952,10 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start,
     
     if (enable_pz2_retrieval)
     {
-        if (b->sptr->request_syntax.length())
+        std::string configured_request_syntax = b->sptr->request_syntax;
+        if (configured_request_syntax.length())
         {
-            syntax_name = b->sptr->request_syntax.c_str();
+            syntax_name = configured_request_syntax.c_str();
             const Odr_oid *syntax_oid = 
                 yaz_string_to_oid(yaz_oid_std(), CLASS_RECSYN, syntax_name);
             if (!oid_oidcmp(syntax_oid, yaz_oid_recsyn_usmarc)
@@ -973,6 +967,9 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start,
         syntax_name =
             yaz_oid_to_string_buf(preferredRecordSyntax, 0, oid_name_str);
 
+    if (b->sptr->sru.length())
+        syntax_name = "XML";
+
     b->set_option("preferredRecordSyntax", syntax_name);
 
     if (enable_pz2_retrieval)
@@ -984,6 +981,39 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start,
 
     b->set_option("elementSetName", element_set_name);
 
+}
+
+Z_Records *yf::Zoom::Frontend::get_records(Odr_int start,
+                                           Odr_int number_to_present,
+                                           int *error,
+                                           char **addinfo,
+                                           Odr_int *number_of_records_returned,
+                                           ODR odr,
+                                           BackendPtr b,
+                                           Odr_oid *preferredRecordSyntax,
+                                           const char *element_set_name)
+{
+    *number_of_records_returned = 0;
+    Z_Records *records = 0;
+    bool enable_pz2_retrieval = false; // whether target profile is used
+    bool enable_pz2_transform = false; // whether XSLT is used as well
+    bool assume_marc8_charset = false;
+
+    prepare_elements(b, preferredRecordSyntax,
+                     element_set_name,
+                     enable_pz2_retrieval,
+                     enable_pz2_transform,
+                     assume_marc8_charset);
+
+    if (start < 0 || number_to_present <=0)
+        return records;
+    
+    if (number_to_present > 10000)
+        number_to_present = 10000;
+
+    ZOOM_record *recs = (ZOOM_record *)
+        odr_malloc(odr, (size_t) number_to_present * sizeof(*recs));
+
     b->present(start, number_to_present, recs, error, addinfo, odr);
 
     int i = 0;
@@ -1167,7 +1197,7 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start,
     }
     return records;
 }
-    
+
 struct cql_node *yf::Zoom::Impl::convert_cql_fields(struct cql_node *cn,
                                                     ODR odr)
 {
@@ -1334,6 +1364,14 @@ void yf::Zoom::Frontend::handle_search(mp::Package &package)
 
     b->set_option("setname", "default");
 
+    bool enable_pz2_retrieval = false;
+    bool enable_pz2_transform = false;
+    bool assume_marc8_charset = false;
+    prepare_elements(b, sr->preferredRecordSyntax, 0 /*element_set_name */,
+                     enable_pz2_retrieval,
+                     enable_pz2_transform,
+                     assume_marc8_charset);
+
     Odr_int hits = 0;
     Z_Query *query = sr->query;
     WRBUF ccl_wrbuf = 0;