Bugzilla – Attachment 166747 Details for
Bug 36616
Ability to stop Complex See Reference authority records from being linked to bibliographic records
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36616: Add option to authority cataloguing plugin to show established headings only
Bug-36616-Add-option-to-authority-cataloguing-plug.patch (text/plain), 12.69 KB, created by
Aleisha Amohia
on 2024-05-15 01:50:13 UTC
(
hide
)
Description:
Bug 36616: Add option to authority cataloguing plugin to show established headings only
Filename:
MIME Type:
Creator:
Aleisha Amohia
Created:
2024-05-15 01:50:13 UTC
Size:
12.69 KB
patch
obsolete
>From 6be6ff4f1bd549a4c3b9f5567babcf440615ac11 Mon Sep 17 00:00:00 2001 >From: Aleisha Amohia <aleishaamohia@hotmail.com> >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 @@ > <input id="value_any" style="width:400px;" type="text" name="value_any" value="[% value_any | html %]" /> > <div id="yvaluecontainermarclist"></div> > </li> >+ <li> >+ <label for="est_headings">Established headings only: </label> >+ <select name="est_headings" id="est_headings"> >+ [% IF !est_headings AND op == 'do_search' %] >+ <option value="1">Yes</option> >+ <option value="" selected="selected">No</option> >+ [% ELSIF Koha.Preference('LinkEstablishedHeadings') OR est_headings %] >+ <option value="1" selected="selected">Yes</option> >+ <option value="">No</option> >+ [% ELSE %] >+ <option value="1">Yes</option> >+ <option value="" selected="selected">No</option> >+ [% END %] >+ </select> >+ </li> > <li> > <label for="orderby">Sort by: </label> > <select name="orderby" id="orderby"> >diff --git a/t/Koha/SearchEngine/Zebra/QueryBuilder.t b/t/Koha/SearchEngine/Zebra/QueryBuilder.t >index 6dca03263d0..221cdbba809 100755 >--- a/t/Koha/SearchEngine/Zebra/QueryBuilder.t >+++ b/t/Koha/SearchEngine/Zebra/QueryBuilder.t >@@ -27,7 +27,7 @@ subtest 'build_authorities_query' => sub { > > my @test_search = ( > ['mainmainentry'], ['and'], [''], ['contains'], ['any'], '', >- 'HeadingAsc' >+ 'HeadingAsc', 1 > ); > my $expected_result = { > marclist => ['mainmainentry'], >@@ -37,6 +37,7 @@ subtest 'build_authorities_query' => sub { > value => ['any'], > authtypecode => '', > orderby => 'HeadingAsc', >+ est_headings => 1, > }; > my $built_search = > Koha::SearchEngine::Zebra::QueryBuilder->build_authorities_query( @test_search ); >diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >index c8c774d6e12..fa433b0db91 100755 >--- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >+++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >@@ -105,7 +105,7 @@ $se->mock( 'get_elasticsearch_mappings', sub { > > subtest 'build_authorities_query_compat() tests' => sub { > >- plan tests => 72; >+ plan tests => 73; > > my $qb; > >@@ -192,13 +192,30 @@ subtest 'build_authorities_query_compat() tests' => sub { > ); > > # Authorities type >- $query = $qb->build_authorities_query_compat( [ 'mainentry' ], undef, undef, ['contains'], [$search_term], 'AUTH_TYPE', 'asc' ); >+ $query = $qb->build_authorities_query_compat( >+ ['mainentry'], undef, undef, ['contains'], [$search_term], 'AUTH_TYPE', >+ 'asc' >+ ); > is_deeply( > $query->{query}->{bool}->{filter}, >- { term => { 'authtype.raw' => 'AUTH_TYPE' } }, >+ [ { term => { 'authtype.raw' => 'AUTH_TYPE' } } ], > "authorities type code is used as filter" > ); > >+ # established headings filter, authtype filter is still there >+ $query = $qb->build_authorities_query_compat( >+ ['mainentry'], undef, undef, ['contains'], [$search_term], 'AUTH_TYPE', >+ 'asc', 1 >+ ); >+ is_deeply( >+ $query->{query}->{bool}->{filter}, >+ [ >+ { term => { 'authtype.raw' => 'AUTH_TYPE' } }, >+ { terms => { 'kind-of-record.raw' => [ 'a', 'f', '|' ] } } >+ ], >+ "both kind-of-record code and authorities type code are used as filters" >+ ); >+ > # Authorities marclist check > warning_like { > $query = $qb->build_authorities_query_compat( [ 'tomas','mainentry' ], undef, undef, ['contains'], [$search_term,$search_term], 'AUTH_TYPE', 'asc' ) >-- >2.39.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36616
:
165248
|
165249
|
166033
|
166746
|
166747
|
167185
|
167186
|
167365
|
167366
|
172125