[open-ils-commits] r1113 - in servres/trunk/conifer: . integration (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Dec 17 11:36:40 EST 2010


Author: gfawcett
Date: 2010-12-17 11:36:37 -0500 (Fri, 17 Dec 2010)
New Revision: 1113

Modified:
   servres/trunk/conifer/integration/uwindsor.py
   servres/trunk/conifer/local_settings.py.example
Log:
skip record-cleaning stage if opensrf is used for search instead of z39.50

Modified: servres/trunk/conifer/integration/uwindsor.py
===================================================================
--- servres/trunk/conifer/integration/uwindsor.py	2010-12-17 15:59:02 UTC (rev 1112)
+++ servres/trunk/conifer/integration/uwindsor.py	2010-12-17 16:36:37 UTC (rev 1113)
@@ -12,6 +12,13 @@
 import uwindsor_campus_info
 from memoization import memoize
 
+# USE_Z3950: if True, use Z39.50 for catalogue search; if False, use OpenSRF.
+# Don't set this value directly here: rather, if there is a valid Z3950_CONFIG
+# settings in local_settings.py, then Z39.50 will be used.
+
+USE_Z3950 = getattr(settings, 'Z3950_CONFIG', None) is not None
+
+
 def department_course_catalogue():
     """
     Return a list of rows representing all known, active courses and
@@ -104,20 +111,21 @@
         numhits = len(results)
     else:
         # query is an actual query
-        superpage = E1('open-ils.search.biblio.multiclass.query',
-               {"org_unit":106,"depth":1,"limit":limit,"offset":start-1,"visibility_limit":3000,
-                "default_class":"keyword"},
-               query, 1)
-        ids = [id for (id,) in superpage['ids']]
-        results = []
-        for rec in E1('open-ils.supercat.record.object.retrieve', ids):
-            marc = unicode(rec['marc'], 'utf-8')
-            tree = M.marcxml_to_records(marc)[0]
-            results.append(tree)
-        numhits = int(superpage['count'])
-        # # query is an actual Z39.50 query
-        # cat_host, cat_port, cat_db = settings.Z3950_CONFIG
-        # results, numhits = PZ.search(cat_host, cat_port, cat_db, query, start, limit)
+        if USE_Z3950:
+            cat_host, cat_port, cat_db = settings.Z3950_CONFIG
+            results, numhits = PZ.search(cat_host, cat_port, cat_db, query, start, limit)
+        else:                   # use opensrf
+            superpage = E1('open-ils.search.biblio.multiclass.query',
+                   {"org_unit":106,"depth":1,"limit":limit,"offset":start-1,"visibility_limit":3000,
+                    "default_class":"keyword"},
+                   query, 1)
+            ids = [id for (id,) in superpage['ids']]
+            results = []
+            for rec in E1('open-ils.supercat.record.object.retrieve', ids):
+                marc = unicode(rec['marc'], 'utf-8')
+                tree = M.marcxml_to_records(marc)[0]
+                results.append(tree)
+            numhits = int(superpage['count'])
     return results, numhits
 
 def bib_id_to_marcxml(bib_id):
@@ -148,23 +156,29 @@
         return ('http://windsor.concat.ca/opac/en-US'
                 '/skin/default/xml/rdetail.xml?r=%s&l=1&d=0' % bib_id)
 
-def get_better_copy_of_marc(marc_string):
-    """
-    This function takes a MARCXML record and returns either the same
-    record, or another instance of the same record from a different
-    source. 
+if USE_Z3950:
+    # only if we are using Z39.50 for catalogue search. Results including
+    # accented characters are often seriously messed up. (Try searching for
+    # "montreal").
+    def get_better_copy_of_marc(marc_string):
+        """
+        This function takes a MARCXML record and returns either the same
+        record, or another instance of the same record from a different
+        source. 
 
-    This is a hack. There is currently at least one Z39.50 server that
-    returns a MARCXML record with broken character encoding. This
-    function declares a point at which we can work around that server.
-    """
-    bib_id = marc_to_bib_id(marc_string)
-    better = bib_id_to_marcxml(bib_id)
-    # don't return the "better" record if there's no 901c in it...
-    if better and ('901c' in M.marcxml_to_dictionary(better)):
-        return better
-    return ET.fromstring(marc_string)
- 
+        This is a hack. There is currently at least one Z39.50 server that
+        returns a MARCXML record with broken character encoding. This
+        function declares a point at which we can work around that server.
+        """
+
+        print marc_string
+        bib_id = marc_to_bib_id(marc_string)
+        better = bib_id_to_marcxml(bib_id)
+        # don't return the "better" record if there's no 901c in it...
+        if better and ('901c' in M.marcxml_to_dictionary(better)):
+            return better
+        return ET.fromstring(marc_string)
+
 def marcxml_to_url(marc_string):
     """
     Given a MARC record, return either a URL (representing the

Modified: servres/trunk/conifer/local_settings.py.example
===================================================================
--- servres/trunk/conifer/local_settings.py.example	2010-12-17 15:59:02 UTC (rev 1112)
+++ servres/trunk/conifer/local_settings.py.example	2010-12-17 16:36:37 UTC (rev 1113)
@@ -50,6 +50,10 @@
 EVERGREEN_GATEWAY_SERVER = 'www.concat.ca'
 Z3950_CONFIG             = ('zed.concat.ca', 210, 'OWA')  #OWA,OSUL,CONIFER
 
+# Note, in the UWindsor integration, commenting out Z3950_CONFIG or setting it
+# equal to None will result in OpenSRF being used for catalogue search instead
+# of Z39.50.
+
 #----------------------------------------------------------------------
 # INTEGRATION_MODULE: name of a module to import after the database
 # models have been initialized. This can be used for defining 'hook'



More information about the open-ils-commits mailing list