Bug 42156: (QA follow-up) Register the new 'authid' search field on upgrade

Adding an entry to admin/searchengine/elasticsearch/mappings.yaml is only
picked up by fresh installs or when an administrator explicitly resets the
search mappings (rebuild_elasticsearch.pl -r). Existing installations would
otherwise never see the new 'authid' index in the admin UI nor have it
available as a matching index until they ran the reset.

This atomicupdate inserts:
 - a search_field row for 'authid' (type 'stdno', staff_client + opac on)
 - search_marc_map rows for authorities/marc21/001 and authorities/unimarc/001
   (INSERT IGNORE - the rows are shared with 'local-number' and usually
   already exist)
 - search_marc_to_field rows linking those MARC maps to the new field with
   sort on, matching mappings.yaml

It is a no-op if 'authid' is already present.

Administrators still need to rebuild the Elasticsearch index for the new
field to become queryable - this is noted with say_info at the end.

Test plan:
 1 - On an existing instance without the patch: note there is no 'authid'
     field under Administration > Search engine configuration (Elasticsearch)
     for authorities.
 2 - Apply the whole patchset.
 3 - perl installer/data/mysql/updatedatabase.pl
 4 - Re-check the search engine configuration: 'authid' appears for the
     authorities index, mapped to 001 for both MARC flavours.
 5 - Run the update again - confirm the "already exists, skipping" warning.
 6 - misc/search_tools/rebuild_elasticsearch.pl -r -v -a
 7 - Confirm a matching rule using index 'authid' now works.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2026-04-21 13:49:39 +01:00 committed by Lucas Gass
parent 9f1ae44cc7
commit 3a3797f3f5
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,66 @@
use Modern::Perl;
use Koha::Installer::Output qw(say_warning say_success say_info);
return {
bug_number => "42156",
description => "Add 'authid' Elasticsearch search field for authorities",
up => sub {
my ($args) = @_;
my ( $dbh, $out ) = @$args{qw(dbh out)};
my ($field_exists) = $dbh->selectrow_array(q{SELECT id FROM search_field WHERE name = 'authid'});
if ($field_exists) {
say_warning( $out, "Search field 'authid' already exists, skipping" );
return;
}
$dbh->do(
q{
INSERT INTO search_field (name, label, type, staff_client, opac)
VALUES ('authid', 'authid', 'stdno', 1, 1)
}
);
my $search_field_id = $dbh->last_insert_id( undef, undef, 'search_field', 'id' );
say_success( $out, "Added Elasticsearch search field 'authid'" );
for my $marc_type (qw( marc21 unimarc )) {
$dbh->do(
q{
INSERT IGNORE INTO search_marc_map (index_name, marc_type, marc_field)
VALUES ('authorities', ?, '001')
},
undef,
$marc_type,
);
my ($marc_map_id) = $dbh->selectrow_array(
q{
SELECT id FROM search_marc_map
WHERE index_name = 'authorities' AND marc_type = ? AND marc_field = '001'
},
undef,
$marc_type,
);
$dbh->do(
q{
INSERT IGNORE INTO search_marc_to_field
(search_marc_map_id, search_field_id, facet, suggestible, sort, search)
VALUES (?, ?, 0, 0, 1, 1)
},
undef,
$marc_map_id, $search_field_id,
);
say_success(
$out,
"Mapped authorities $marc_type 001 to search field 'authid'"
);
}
say_info(
$out,
"Rebuild the Elasticsearch index (misc/search_tools/rebuild_elasticsearch.pl -r -v -a) for the new field to take effect"
);
},
};