}
my $site;
- my $org = $cgi->param('loc');
+ my $org = $ctx->{search_ou};
if (defined($org) and $org ne '' and ($org ne $ctx->{aou_tree}->()->id) and not $query =~ /site\(\S+\)/) {
$site = $ctx->{get_aou}->($org)->shortname;
$query .= " site($site)";
$depth = $org->ou_type->depth;
}
$query .= " depth($depth)";
+ } else {
+ $depth = $ctx->{get_aou}->($org)->ou_type->depth;
}
$logger->info("tpac: site=$site, depth=$depth, query=$query");
my $page = $cgi->param('page') || 0;
my @facets = $cgi->param('facet');
my $limit = $self->_get_search_limit;
- my $loc = $cgi->param('loc') || $ctx->{aou_tree}->()->id;
+ $ctx->{search_ou} = $self->_get_search_lib();
my $offset = $page * $limit;
my $metarecord = $cgi->param('metarecord');
my $results;
$results = $U->simplereq(
'open-ils.search',
'open-ils.search.biblio.metarecord_to_records',
- $metarecord, {org => $loc, depth => $depth}
+ $metarecord, {org => $ctx->{search_ou}, depth => $depth}
);
# force the metarecord result blob to match the format of regular search results
} else {
$sname = 'opac.patron.jump_to_details_on_single_hit';
- $org = ($ctx->{user}) ?
- $ctx->{user}->home_ou :
- $ctx->{physical_loc} ||
- $self->ctx->{aou_tree}->()->id;
+ $org = $self->_get_search_lib();
}
return undef unless
# loc, limit and offset
my $page = $self->cgi->param("page") || 0;
my $limit = $self->_get_search_limit;
- my $org_unit = $self->cgi->param("loc") || $self->ctx->{aou_tree}->()->id;
+ $self->ctx->{search_ou} = $self->_get_search_lib();
my $offset = $page * $limit;
$self->ctx->{records} = [];
my $ses = OpenSRF::AppSession->create('open-ils.search');
my $req = $ses->request(
'open-ils.search.biblio.marc',
- {searches => $query, org_unit => $org_unit},
+ {searches => $query, org_unit => $self->ctx->{search_ou}},
$limit, $offset, $timeout);
my $resp = $req->recv($timeout);
return $marc_xml;
}
+sub _get_search_lib {
+ my $self = shift;
+
+ # loc param takes precedence
+ my $loc = $self->cgi->param('loc');
+ return $loc if $loc;
+
+ if ($self->ctx->{user}) {
+ # See if the user has a search library preference
+ my $lset = $self->editor->search_actor_user_setting({
+ usr => $self->ctx->{user}->id,
+ name => 'opac.default_search_location'
+ })->[0];
+ return OpenSRF::Utils::JSON->JSON2perl($lset->value) if $lset;
+
+ # Otherwise return the user's home library
+ return $self->ctx->{user}->home_ou;
+ }
+
+ if ($self->cgi->param('physical_loc')) {
+ return $self->cgi->param('physical_loc');
+ }
+
+ return $self->ctx->{aou_tree}->()->id;
+}
+
1;