From: Bill Erickson Date: Tue, 27 Dec 2011 18:45:02 +0000 (-0500) Subject: TPac: improve search depth extraction X-Git-Tag: sprint4-merge-nov22~4701 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=f49146ec6b6c0e54056a911a0f21e2d5c80a38b5;p=working%2FEvergreen.git TPac: improve search depth extraction Improves how we determine the depth of a search. The Order of operations: 1. Depth encoded within the search query, e.g. depth(2) 2. CGI depth param 3. Default is to match the depth of the searched org unit Signed-off-by: Bill Erickson Signed-off-by: Dan Scott --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm index 0db757bd28..77cfb38ce3 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm @@ -108,14 +108,26 @@ sub _prepare_biblio_search { $site ||= $ctx->{aou_tree}->()->shortname; } - my $depth; - if (defined($cgi->param('depth')) and not $query =~ /depth\(\d+\)/) { - $depth = defined $cgi->param('depth') ? - $cgi->param('depth') : $ctx->{get_aou}->($site)->ou_type->depth; + if ($query =~ /depth\(\d+\)/) { + + # depth is encoded in the search query + ($depth) = ($query =~ /depth\((\d+)\)/); + + } else { + + if (defined $cgi->param('depth')) { + $depth = $cgi->param('depth'); + } else { + # no depth specified. match the depth to the search org + my ($org) = grep { $_->shortname eq $site } @{$ctx->{aou_list}->()}; + $depth = $org->ou_type->depth; + } $query .= " depth($depth)"; } + $logger->info("tpac: site=$site, depth=$depth, query=$query"); + return ($query, $site, $depth); } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index 1199d9ae38..92cea9700b 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -114,6 +114,13 @@ sub init_ro_object_cache { return $cache{map}{aou}{$org_id}; }; + # Returns a flat list of aou objects. often easier to manage than a tree. + $ro_object_subs->{aou_list} = sub { + $ro_object_subs->{aou_tree}->(); # force the org tree to load + return [ values %{$cache{map}{aou}} ]; + }; + + # turns an ISO date into something TT can understand $ro_object_subs->{parse_datetime} = sub { my $date = shift;