Enable org_unit-scoped SRU searches
authordbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 1 May 2009 00:30:44 +0000 (00:30 +0000)
committerdbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 1 May 2009 00:30:44 +0000 (00:30 +0000)
http://example.com/opac/extras/sru/SHORTNAME will set a search scope
of SHORTNAME if the search string does not already contain a site:
parameter

Combined with simple2zoom configuration, this gives us the ability to
surface different Z39.50 "databases" that correspond to various org_units.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@13026 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm

index 6679f71..9e6ee71 100644 (file)
@@ -1599,10 +1599,20 @@ sub sru_search {
     my $req = SRU::Request->newFromCGI( $cgi );
     my $resp = SRU::Response->newFromRequest( $req );
 
+    # Find the org_unit shortname, if passed as part of the URL
+    # http://example.com/opac/extras/sru/SHORTNAME
+    my $url = $cgi->path_info;
+    my ($shortname) = $url =~ m#/?(.*)#;
+
     if ( $resp->type eq 'searchRetrieve' ) {
                my $cql_query = $req->query;
                my $search_string = $req->cql->toEvergreen;
 
+               # Ensure the search string overrides the default site
+        if ($shortname and $search_string !~ m#site:#) {
+                $search_string .= " site:$shortname";
+        }
+
         my $offset = $req->startRecord;
         $offset-- if ($offset);
         $offset ||= 0;
@@ -1762,3 +1772,5 @@ sub sru_search {
 }
 
 1;
+
+# vim: noet:ts=4:sw=4