From 3a2e312822aaaa3fee3dce2d988d88ab065feb8c 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 Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Nind --- 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 4413211849..632376d6e1 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1241,6 +1241,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=/ ) { @@ -1441,6 +1442,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/ ) { @@ -1453,6 +1455,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 @@ -1497,6 +1504,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 eed466049b..b5013ecf23 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -1019,6 +1019,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 1419759c85..75228d81fe 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 af01c0e88b..8b30203470 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 553ef59917..74df2ec259 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt @@ -268,7 +268,10 @@
    Location and availability
    -

    +

    + + +

    -- 2.11.0