Bug 39589: Auto-skip to the next page and note hidden results when a page is fully filtered
When every result on a page is hidden (OpacHiddenItemsHidesRecord), rather than leaving the patron on a dead-end "not available" page, look ahead a bounded number of pages (3) for one with visible results and redirect there directly. The lookahead is capped so a library with many consecutive hidden pages doesn't turn a single search into a long chain of extra search-engine queries; RSS/atom/opensearchdescription requests are left alone since redirecting a feed reader makes no sense. Whenever a hidden page was skipped over (whether we found a visible page to land on, or exhausted the lookahead and fell back to the "not available" message), show a caveat next to the results count so the "Your search returned N results" figure doesn't read as contradicting what the patron can actually see - this was raised as a sign-off concern on the original patch (comment 4). Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
parent
a8523740b0
commit
bfc6866200
|
|
@ -159,6 +159,10 @@
|
|||
[% END # / IF total %]
|
||||
[% END # / IF searchdesc %]
|
||||
|
||||
[% IF ( total && some_results_hidden ) %]
|
||||
<p class="alert alert-info">Some results are hidden due to library policy.</p>
|
||||
[% END %]
|
||||
|
||||
<div id="userresults">
|
||||
[% IF ( DidYouMean ) %]
|
||||
<div id="didyoumean">Not what you expected? Check for <a href="/cgi-bin/koha/svc/suggestion?render=standalone&q=[% querystring | uri %]">suggestions</a></div>
|
||||
|
|
|
|||
|
|
@ -664,7 +664,59 @@ for ( my $i = 0 ; $i < @servers ; $i++ ) {
|
|||
$results_hashref->{$server}->{"RECORDS"}, $variables
|
||||
);
|
||||
unless (@newresults) {
|
||||
$template->param( no_page_results => 1 );
|
||||
|
||||
# This page has hits, but every one of them is hidden from the OPAC
|
||||
# (OpacHiddenItemsHidesRecord). Rather than showing a dead end, look
|
||||
# a few pages ahead for one with something to show and jump straight
|
||||
# there. The lookahead is capped so a library with many consecutive
|
||||
# hidden pages doesn't turn this search into a long chain of extra
|
||||
# search-engine queries.
|
||||
my $found_offset;
|
||||
my $skipped_hidden_page = 0;
|
||||
my $lookahead_offset = $offset;
|
||||
for ( 1 .. 3 ) {
|
||||
$lookahead_offset += $results_per_page;
|
||||
last if $lookahead_offset >= $hits;
|
||||
|
||||
my $lookahead_results_hashref;
|
||||
my $itemtypes_nocategory =
|
||||
{ map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
|
||||
eval {
|
||||
( $error, $lookahead_results_hashref, undef ) = $searcher->search_compat(
|
||||
$query, $simple_query, \@sort_by, \@servers, $results_per_page, $lookahead_offset,
|
||||
undef, $itemtypes_nocategory, $query_type, $scan, 1
|
||||
);
|
||||
};
|
||||
my @lookahead_results = searchResults(
|
||||
$search_context, $query_desc, $hits, $results_per_page, $lookahead_offset, $scan,
|
||||
$lookahead_results_hashref->{$server}->{"RECORDS"}, $variables
|
||||
);
|
||||
if (@lookahead_results) {
|
||||
$found_offset = $lookahead_offset;
|
||||
last;
|
||||
}
|
||||
$skipped_hidden_page = 1;
|
||||
}
|
||||
|
||||
if ( defined $found_offset
|
||||
&& $format ne 'rss'
|
||||
&& $format ne 'opensearchdescription'
|
||||
&& $format ne 'atom' )
|
||||
{
|
||||
$cgi->param( offset => $found_offset );
|
||||
$cgi->param( hidden_notice => 1 );
|
||||
print $cgi->redirect( '/cgi-bin/koha/opac-search.pl?' . $cgi->query_string() );
|
||||
exit;
|
||||
}
|
||||
|
||||
$template->param(
|
||||
no_page_results => 1,
|
||||
some_results_hidden => $skipped_hidden_page,
|
||||
);
|
||||
}
|
||||
|
||||
if ( $cgi->param('hidden_notice') ) {
|
||||
$template->param( some_results_hidden => 1 );
|
||||
}
|
||||
|
||||
my $art_req_itypes;
|
||||
|
|
|
|||
Loading…
Reference in New Issue