From b8140a78464cae6dff9561fed8330bf5ce469d8b Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Mon, 5 Oct 2020 09:03:18 +0000 Subject: [PATCH] Bug 26608: Elasticsearch - add exact (ext) field type and use it for linked biblios Test plan: - Enable Elasticsearch engine, - Enable QueryAutoTruncate systempreference, - Show the detail od authority #1 (cgi-bin/koha/authorities/detail.pl?authid=1) - note the inconsistent count of linked biblio (and so the list), - Apply this patch, - Restart all, - repeat previous step, - Count and list of linked biblios should be ok. --- Koha/Authorities.pm | 8 +++++++- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 4 ++-- koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Koha/Authorities.pm b/Koha/Authorities.pm index 0145eb3..ebc28b3 100644 --- a/Koha/Authorities.pm +++ b/Koha/Authorities.pm @@ -25,6 +25,9 @@ use Koha::Database; use Koha::Authority; +use Koha::SearchEngine::Search; +use Koha::SearchEngine::QueryBuilder; + use base qw(Koha::Objects); =head1 NAME @@ -51,8 +54,11 @@ sub get_usage_count { my ( $class, $params ) = @_; my $authid = $params->{authid} || return; + my $builder = Koha::SearchEngine::QueryBuilder->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); my $searcher = Koha::SearchEngine::Search->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); - my ( $err, $result, $count ) = $searcher->simple_search_compat( 'an:' . $authid, 0, 0 ); + + my ($builderror, $query)= $builder->build_query_compat( undef, [$authid], ['an,ext'], [], []); + my ( $err, $result, $count ) = $searcher->simple_search_compat( $query, 0, 0 ); if( $err ) { warn "Error: $err from search for " . $authid; return; diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index edd0b1b..29da4d2 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -187,7 +187,7 @@ sub build_query_compat { while ( my ( $oand, $otor, $index ) = $ea->() ) { next if ( !defined($oand) || $oand eq '' ); $oand = $self->_clean_search_term($oand); - $oand = $self->_truncate_terms($oand) if ($truncate); + $oand = $self->_truncate_terms($oand) if ($truncate && $index->{type} ne 'ext'); push @search_params, { operand => $oand, # the search terms operator => defined($otor) ? uc $otor : undef, # AND and so on @@ -712,7 +712,7 @@ sub _convert_index_fields { my ( $self, @indexes ) = @_; my %index_type_convert = - ( __default => undef, phr => 'phrase', rtrn => 'right-truncate', 'st-year' => 'st-year' ); + ( __default => undef, phr => 'phrase', rtrn => 'right-truncate', 'st-year' => 'st-year', 'ext' => 'ext' ); # Convert according to our table, drop anything that doesn't convert. # If a field starts with mc- we save it as it's used (and removed) later diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt index 2afd642..2713bbd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt @@ -44,7 +44,7 @@
[% IF count %] - Used in [% count | html %] record(s) + Used in [% count | html %] record(s) [% ELSE %] This authority is not used in any records. [% END %] -- 2.7.4