From 6be6ff4f1bd549a4c3b9f5567babcf440615ac11 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Mon, 22 Apr 2024 05:03:34 +0000 Subject: [PATCH] Bug 36616: Add option to authority cataloguing plugin to show established headings only This enhancement adds a Yes/No dropdown option to the authority cataloguing plugin for showing established headings only. These are headings where the 008/09 is set to 'a' or 'f' (established) or '|' (not coded). When set to Yes, non-established headings will not show in the authority search results so can't be chosen to link to the bibliographic record. This also adds a system preference LinkEstablishedHeadings to determine whether the Yes/No dropdown should be enabled or disabled by default. This works for both Zebra and Elasticsearch. To test: 1) Apply patches and install database updates and restart services 2) Go to Koha Administration -> system preferences. Search for LinkEstablishedHeadings. This should be disabled by default. 3) Create two PERSO_NAME authority records. Give them similar names so you'd expect them to come up in a search together i.e. name one "James 1" and the second "James 2". For "James 1" set the 008/09 to 'a' and for "James 2" set the 008/09 to 'b'. 4) Go to Cataloguing and click New record 5) Go to tab 1 and tag 100. Click the plugin editor for 100$a Personal name. 6) Notice the "Established headings only" dropdown is set to No because LinkEstablishedHeadings is disabled. 7) Search for "James" and keep "Established headings only" set to No. Confirm both of your James records show in the results. 8) Change the "Established headings only" to Yes and search again. Confirm only "James 1" shows in the results. 9) Change the LinkEstablishedHeadings system preference to "Only established headings, as indicated by the 008/09" and save. 10) Repeat steps 4 and 5. Confirm the "Established headings only" dropdown is set to Yes by default. 11) If you did the above test plan with Zebra as the search enginge (as set by SearchEngine system preference), test again with Elasticsearch. The steps and outcomes should be the same. 12) Confirm tests pass - t/Koha/SearchEngine/Zebra/QueryBuilder.t - t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t Sponsored-by: Education Services Australia SCIS --- C4/AuthoritiesMarc.pm | 17 ++++++++++++-- .../Elasticsearch/QueryBuilder.pm | 22 ++++++++++++++---- Koha/SearchEngine/Zebra/QueryBuilder.pm | 1 + Koha/SearchEngine/Zebra/Search.pm | 2 +- authorities/auth_finder.pl | 5 +++- .../prog/en/includes/auth-finder-search.inc | 15 ++++++++++++ t/Koha/SearchEngine/Zebra/QueryBuilder.t | 3 ++- .../SearchEngine/Elasticsearch/QueryBuilder.t | 23 ++++++++++++++++--- 8 files changed, 75 insertions(+), 13 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index b595230c5d3..ee3cb1ad6f9 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -108,14 +108,14 @@ sub GetAuthMARCFromKohaField { (\@finalresult, $nbresults)= &SearchAuthorities($tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode, - $sortby[, $skipmetadata]) + $sortby[, $skipmetadata, $est_headings]) returns ref to array result and count of results returned =cut sub SearchAuthorities { - my ($tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode,$sortby,$skipmetadata) = @_; + my ($tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode,$sortby,$skipmetadata,$est_headings) = @_; # warn Dumper($tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode,$sortby); my $dbh=C4::Context->dbh; $sortby="" unless $sortby; @@ -139,6 +139,19 @@ sub SearchAuthorities { while ($n>1){$query= "\@or ".$query;$n--;} } } + ## optionally search for established headings + if ($est_headings) { + $query = "\@and " . $query; + my $n = 0; + my @est_values = ( 'a', 'f', '|' ); + foreach my $v (@est_values) { + $query .= " \@attr 1=Kind-of-record \@attr 5=100 " . $v; + $n++; + } + if ( $n > 1 ) { + while ( $n > 1 ) { $query = "\@or " . $query; $n--; } + } + } my $dosearch; my $and=" \@and " ; diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index ac161e50fd7..7759438db58 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -468,15 +468,26 @@ sub build_authorities_query { my $elastic_query = {}; $elastic_query->{bool}->{must} = \@query_parts; + # further filter the results + my @filters; + # Filter by authtypecode if set - if ($search->{authtypecode}) { - $elastic_query->{bool}->{filter} = { - term => { - "authtype.raw" => $search->{authtypecode} + if ( $search->{authtypecode} ) { + push @filters, { term => { "authtype.raw" => $search->{authtypecode} } }; + } + + # Filter by establishing headings if set + # terms supports an array of values + if ( $search->{est_headings} ) { + push @filters, { + terms => { + "kind-of-record.raw" => [ 'a', 'f', '|' ], } }; } + $elastic_query->{bool}->{filter} = \@filters; + my $query = { query => $elastic_query }; @@ -575,7 +586,7 @@ our $thesaurus_to_value = { sub build_authorities_query_compat { my ( $self, $marclist, $and_or, $excluding, $operator, $value, - $authtypecode, $orderby ) + $authtypecode, $orderby, $est_headings ) = @_; # This turns the old-style many-options argument form into a more @@ -619,6 +630,7 @@ sub build_authorities_query_compat { my %search = ( searches => \@searches, authtypecode => $authtypecode, + est_headings => $est_headings, ); $search{sort} = \%sort if %sort; my $query = $self->build_authorities_query( \%search ); diff --git a/Koha/SearchEngine/Zebra/QueryBuilder.pm b/Koha/SearchEngine/Zebra/QueryBuilder.pm index 8b8d3473e7f..72e9ac5a5d6 100644 --- a/Koha/SearchEngine/Zebra/QueryBuilder.pm +++ b/Koha/SearchEngine/Zebra/QueryBuilder.pm @@ -103,6 +103,7 @@ sub build_authorities_query { value => $_[4], authtypecode => $_[5], orderby => $_[6], + est_headings => $_[7], }; } diff --git a/Koha/SearchEngine/Zebra/Search.pm b/Koha/SearchEngine/Zebra/Search.pm index 1d504d384fd..8ac5bb117b8 100644 --- a/Koha/SearchEngine/Zebra/Search.pm +++ b/Koha/SearchEngine/Zebra/Search.pm @@ -105,7 +105,7 @@ sub search_auth_compat { my @params = ( @{$q}{ 'marclist', 'and_or', 'excluding', 'operator', 'value' }, $startfrom - 1, - $resperpage, @{$q}{ 'authtypecode', 'orderby' }, $skipmetadata + $resperpage, @{$q}{ 'authtypecode', 'orderby' }, $skipmetadata, @{$q}{'est_headings'} ); C4::AuthoritiesMarc::SearchAuthorities(@params); } diff --git a/authorities/auth_finder.pl b/authorities/auth_finder.pl index 1603fbbc31f..b38a376caf6 100755 --- a/authorities/auth_finder.pl +++ b/authorities/auth_finder.pl @@ -67,6 +67,7 @@ if ( $op eq "do_search" ) { my $orderby = $query->param('orderby') || ''; my $startfrom = $query->param('startfrom') || 0; my $resultsperpage = $query->param('resultsperpage') || 20; + my $est_headings = $query->param('est_headings') || undef; my $builder = Koha::SearchEngine::QueryBuilder->new( { index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); @@ -74,8 +75,9 @@ if ( $op eq "do_search" ) { { index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); my $search_query = $builder->build_authorities_query_compat( \@marclist, \@and_or, \@excluding, \@operator, - \@value, $authtypecode, $orderby + \@value, $authtypecode, $orderby, $est_headings ); + $template->param( search_query => $search_query ) if C4::Context->preference('DumpSearchQueryTemplate'); my $offset = $startfrom * $resultsperpage; my ( $results, $total ) = @@ -176,6 +178,7 @@ if ( $op eq "do_search" ) { operator_main => ( @operator > 1 && $operator[1] ) ? $operator[1] : '', operator_match => ( @operator > 2 && $operator[2] ) ? $operator[2] : '', operator_any => ( @operator > 3 && $operator[3] ) ? $operator[3] : '', + est_headings => $est_headings, ); } else { diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/auth-finder-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/auth-finder-search.inc index fe94cf0f8b0..9bc487ed0a7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/auth-finder-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/auth-finder-search.inc @@ -117,6 +117,21 @@
+
  • + + +