From 3aaade28f0ab9e15be787ef5d96fad7e6425506e 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 +++++++++++ .../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 72c81ec06c..185d715e5a 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1242,6 +1242,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 2a0775d386..74a3c4e3ec 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -1013,6 +1013,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 8ed6ff3181..fc7660162c 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -417,13 +417,19 @@ for ( my $i=0; $i<@limits; $i++ ) { } } -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; @@ -613,6 +619,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 a4d7c6d9d7..87f63b3874 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt @@ -280,7 +280,10 @@
    Location and availability
    -

    +

    + + +

    -- 2.32.0