use org unit shortname for site param; capture site/depth in search builder to pass...
authorberick <berick@esilibrary.com>
Fri, 15 Apr 2011 20:11:40 +0000 (16:11 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 20 Jul 2011 18:34:31 +0000 (14:34 -0400)
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm

index 1cae862..5c6046d 100644 (file)
@@ -77,17 +77,27 @@ sub _prepare_biblio_search {
         }
     }
 
-    my $site = $cgi->param('loc');
-    if (defined($site) and $site ne '' and ($site ne $ctx->{aou_tree}->()->id) and not $query =~ /site\(\d+\)/) {
+    my $site;
+    my $org = $cgi->param('loc');
+    if (defined($org) and $org ne '' and ($org ne $ctx->{aou_tree}->()->id) and not $query =~ /site\(\S+\)/) {
+        $site = $ctx->{find_aou}->($org)->shortname;
         $query .= " site($site)";
     }
+
+    if(!$site) {
+        ($site) = ($query =~ /site\(([^\)]+)\)/);
+        $site ||= $ctx->{aou_tree}->()->shortname;
+    }
+
+
+    my $depth;
     if (defined($cgi->param('depth')) and not $query =~ /depth\(\d+\)/) {
-        my $depth = defined $cgi->param('depth') ?
+        $depth = defined $cgi->param('depth') ?
             $cgi->param('depth') : $ctx->{find_aou}->($site)->ou_type->depth;
         $query .= " depth($depth)";
     }
 
-    return $query;
+    return ($query, $site, $depth);
 }
 
 # context additions: 
@@ -104,9 +114,11 @@ sub load_rresults {
     my $page = $cgi->param('page') || 0;
     my $facet = $cgi->param('facet');
     my $limit = $cgi->param('limit') || 10; # TODO user settings
+    my $loc = $cgi->param('loc');
     my $offset = $page * $limit;
 
-    my $query = _prepare_biblio_search($cgi, $ctx);
+    my ($query, $site, $depth) = _prepare_biblio_search($cgi, $ctx);
+
     # Limit and offset will stay here. Everything else should be part of
     # the query string, not special args.
     my $args = {'limit' => $limit, 'offset' => $offset};
@@ -140,7 +152,13 @@ sub load_rresults {
     return Apache2::Const::OK if @$rec_ids == 0;
 
     my ($facets, @data) = $self->get_records_and_facets(
-        $rec_ids, $results->{facet_key}, {flesh => '{holdings_xml,mra}'});
+        $rec_ids, $results->{facet_key}, 
+        {
+            flesh => '{holdings_xml,mra}',
+            site => $site,
+            depth => $depth
+        }
+    );
 
     # shove recs into context in search results order
     for my $rec_id (@$rec_ids) {
index e951fef..456f9c3 100644 (file)
@@ -149,7 +149,7 @@ sub get_records_and_facets {
     my ($self, $rec_ids, $facet_key, $unapi_args) = @_;
 
     $unapi_args ||= {};
-    $unapi_args->{loc} ||= $self->ctx->{aou_tree}->()->shortname;
+    $unapi_args->{site} ||= $self->ctx->{aou_tree}->()->shortname;
     $unapi_args->{depth} ||= $self->ctx->{aou_tree}->()->ou_type->depth;
     $unapi_args->{flesh_depth} ||= 5;
 
@@ -171,7 +171,7 @@ sub get_records_and_facets {
          {from => [
             'unapi.bre', $_, 'marcxml','record', 
             $unapi_args->{flesh}, 
-            $unapi_args->{loc}, 
+            $unapi_args->{site}, 
             $unapi_args->{depth}, 
             $unapi_args->{flesh_depth}, 
         ]}