From cd751283c5deadf174d846f6ba5dba57d312941c Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Tue, 27 Oct 2020 12:21:32 +0100 Subject: [PATCH] Bug 26860: Add without items facet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Many libraries ask for a way to search biblio records without items. In order to clean the catalogue or acquire items. I propose to add a search limit and facet. Only in staff interface for start. I choose to use homebranch index, should always be defined on items. Looks like itemnumber index can not be used because of its configuration in ccl.properties. Test plan : 1) Check with both Zebra and Elasticsearch 2) Perform a search on staff interface returning some records with and some without items 3) Click on 'Limit to records without items' 4) Check you see only records without items 5) Click on 'Show all records' 6) Check you see all records again Signed-off-by: Séverine QUEUNE --- C4/Search.pm | 11 +++++++++++ Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 3 +++ catalogue/search.pl | 13 +++++++++++-- koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc | 11 +++++++++++ .../intranet-tmpl/prog/en/modules/catalogue/advsearch.tt | 5 ++++- 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index f2e73ee..fc23a4d 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1322,6 +1322,7 @@ sub buildQuery { } $q .= ' and '.join(' and ', @limits) if @limits; } + #TODO withoutitems limit return ( undef, $q, $q, "q=ccl=".uri_escape_utf8($q), $original_q, '', '', '', 'ccl' ); } if ( $query =~ /^cql=/ ) { @@ -1515,6 +1516,7 @@ sub buildQuery { # add limits my %group_OR_limits; my $availability_limit; + my $withoutitems_limit; foreach my $this_limit (@limits) { next unless $this_limit; if ( $this_limit =~ /available/ ) { @@ -1527,6 +1529,11 @@ sub buildQuery { $limit_cgi .= "&limit=available"; $limit_desc .= ""; } + elsif ( $this_limit =~ /withoutitems/ ) { + $withoutitems_limit = "( allrecords,AlwaysMatches='' not(homebranch,AlwaysMatches='') )"; + $limit_cgi .= "&limit=withoutitems"; + $limit_desc .= ""; + } # group_OR_limits, prefixed by mc- # OR every member of the group @@ -1571,6 +1578,10 @@ sub buildQuery { $limit .= " and " if ( $query || $limit ); $limit .= "($availability_limit)"; } + if ($withoutitems_limit) { + $limit .= " and " if ( $query || $limit ); + $limit .= "($withoutitems_limit)"; + } # Normalize the query and limit strings # This is flawed , means we can't search anything with : in it diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index edd0b1b..e60fc59 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -1012,6 +1012,9 @@ sub _fix_limit_special_cases { elsif ( $l =~ /^available$/ ) { push @new_lim, 'onloan:false'; } + elsif ( $l =~ /^withoutitems$/ ) { + push @new_lim, 'NOT homebranch:*'; + } else { my ( $field, $term ) = $l =~ /^\s*([\w,-]*?):(.*)/; $field =~ s/,phr$//; #We are quoting all the limits as phrase, this prevents from quoting again later diff --git a/catalogue/search.pl b/catalogue/search.pl index a5e0ecb..a93d9e8 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -382,13 +382,19 @@ if($params->{'multibranchlimit'}) { push @limits, $multibranch if ($multibranch ne '()'); } -my $available; +my ($available, $withoutitems); foreach my $limit(@limits) { if ($limit =~/available/) { $available = 1; } + if ($limit =~/withoutitems/) { + $withoutitems = 1; + } } -$template->param(available => $available); +$template->param( + available => $available, + withoutitems => $withoutitems, +); # append year limits if they exist my $limit_yr; @@ -578,6 +584,9 @@ for (my $i=0;$i<@servers;$i++) { my $limit_cgi_not_availablity = $limit_cgi; $limit_cgi_not_availablity =~ s/&limit=available//g; $template->param(limit_cgi_not_availablity => $limit_cgi_not_availablity); + my $limit_cgi_not_withoutitems = $limit_cgi; + $limit_cgi_not_withoutitems =~ s/&limit=withoutitems//g; + $template->param(limit_cgi_not_withoutitems => $limit_cgi_not_withoutitems); } $template->param(limit_cgi => $limit_cgi); $template->param(query_cgi => $query_cgi); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc index af01c0e..8b30203 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc @@ -17,6 +17,17 @@ [% END %] +
  • + Without items + +
  • [% IF ( related ) %]
  • (related searches: [% FOREACH relate IN related %][% relate.related_search | html %][% END %])
  • [% END %] [% FOREACH facets_loo IN facets_loop %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt index 673aa2d..3ef0676 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt @@ -264,7 +264,10 @@
    Location and availability
    -

    +

    + + +

    -- 2.1.4