Browse Source

Bug 22339: Fix search field mappings of MARC fixed fields

Fixes handling of /0 selector in addition to several fixed field positions. Note that ff7-01-02 is in fact 00-01 in Zebra and that has been replicated here.

Test plan:
1. Before applying a patch, check from Elasticsearch (e.g. localhost:9200/koha_biblios/_search?q=_id:123) what is indexed in Elasticsearch for a record for date-entered-on-file, ff7-00, ff7-01, ff7-02 and lleader.
2. Apply the patch, update database and save the record again.
3. Verify that the contents of the forementioned fields is now correct in Elasticsearch.
4. Verify that tests pass:  prove -v t/Koha/SearchEngine/Elasticsearch.t

Signed-off-by: Björn Nylén <bjorn.nylen@ub.lu.se>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
19.05.x
Ere Maijala 3 years ago
committed by Nick Clemens
parent
commit
0047ede37e
  1. 6
      Koha/SearchEngine/Elasticsearch.pm
  2. 24
      admin/searchengine/elasticsearch/mappings.yaml
  3. 55
      installer/data/mysql/atomicupdate/bug_22339.perl
  4. 14
      t/Koha/SearchEngine/Elasticsearch.t

6
Koha/SearchEngine/Elasticsearch.pm

@ -610,8 +610,8 @@ An optional range as a string in the format "<START>-<END>" or "<START>",
where "<START>" and "<END>" are integers specifying a range that will be used
for extracting a substring from MARC data as Elasticsearch field target value.
The first character position is "1", and the range is inclusive,
so "1-3" means the first three characters of MARC data.
The first character position is "0", and the range is inclusive,
so "0-2" means the first three characters of MARC data.
If only "<START>" is provided only one character at position "<START>" will
be extracted.
@ -626,7 +626,7 @@ sub _field_mappings {
my @mappings;
my $substr_args = undef;
if ($range) {
if (defined $range) {
# TODO: use value_callback instead?
my ($start, $end) = map(int, split /-/, $range, 2);
$substr_args = [$start];

24
admin/searchengine/elasticsearch/mappings.yaml

@ -1758,12 +1758,12 @@ biblios:
label: date-entered-on-file
mappings:
- facet: ''
marc_field: '008_/1-5'
marc_field: '008_/0-5'
marc_type: marc21
sort: ~
suggestible: ''
- facet: ''
marc_field: '008_/1-5'
marc_field: '008_/0-5'
marc_type: normarc
sort: ~
suggestible: ''
@ -1869,12 +1869,12 @@ biblios:
label: ff7-00
mappings:
- facet: ''
marc_field: 007_/1
marc_field: 007_/0
marc_type: marc21
sort: ~
suggestible: ''
- facet: ''
marc_field: 007_/1
marc_field: 007_/0
marc_type: normarc
sort: ~
suggestible: ''
@ -1883,12 +1883,12 @@ biblios:
label: ff7-01
mappings:
- facet: ''
marc_field: 007_/2
marc_field: 007_/1
marc_type: marc21
sort: ~
suggestible: ''
- facet: ''
marc_field: 007_/2
marc_field: 007_/1
marc_type: normarc
sort: ~
suggestible: ''
@ -1897,12 +1897,12 @@ biblios:
label: ff7-01-02
mappings:
- facet: ''
marc_field: 007_/1-2
marc_field: 007_/0-1
marc_type: marc21
sort: ~
suggestible: ''
- facet: ''
marc_field: 007_/1-2
marc_field: 007_/0-1
marc_type: normarc
sort: ~
suggestible: ''
@ -1911,12 +1911,12 @@ biblios:
label: ff7-02
mappings:
- facet: ''
marc_field: 007_/3
marc_field: 007_/2
marc_type: marc21
sort: ~
suggestible: ''
- facet: ''
marc_field: 007_/3
marc_field: 007_/2
marc_type: normarc
sort: ~
suggestible: ''
@ -2586,12 +2586,12 @@ biblios:
label: llength
mappings:
- facet: ''
marc_field: leader_/1-5
marc_field: leader_/0-4
marc_type: marc21
sort: ~
suggestible: ''
- facet: ''
marc_field: leader_/1-5
marc_field: leader_/0-4
marc_type: normarc
sort: ~
suggestible: ''

55
installer/data/mysql/atomicupdate/bug_22339.perl

@ -0,0 +1,55 @@
$DBversion = 'XXX'; # will be replaced by the RM
if( CheckVersion( $DBversion ) ) {
$dbh->do( q|
UPDATE search_marc_map SET marc_field='007_/0'
WHERE marc_type IN ('marc21', 'normarc') AND marc_field='007_/1' AND id IN
(SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN
(SELECT id FROM search_field WHERE label='ff7-00')
)
|);
$dbh->do( q|
UPDATE search_marc_map SET marc_field='007_/1'
WHERE marc_type IN ('marc21', 'normarc') AND marc_field='007_/2' AND id IN
(SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN
(SELECT id FROM search_field WHERE label='ff7-01')
)
|);
$dbh->do( q|
UPDATE search_marc_map SET marc_field='007_/2'
WHERE marc_type IN ('marc21', 'normarc') AND marc_field='007_/3' AND id IN
(SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN
(SELECT id FROM search_field WHERE label='ff7-02')
)
|);
# N.B. ff7-01-02 really is 00-01!
$dbh->do( q|
UPDATE search_marc_map SET marc_field='007_/0-1'
WHERE marc_type IN ('marc21', 'normarc') AND marc_field='007_/1-2' AND id IN
(SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN
(SELECT id FROM search_field WHERE label='ff7-01-02')
)
|);
$dbh->do( q|
UPDATE search_marc_map SET marc_field='008_/0-5'
WHERE marc_type IN ('marc21', 'normarc') AND marc_field='008_/1-5' AND id IN
(SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN
(SELECT id FROM search_field WHERE label='date-entered-on-file')
)
|);
$dbh->do( q|
UPDATE search_marc_map SET marc_field='leader_/0-4'
WHERE marc_type IN ('marc21', 'normarc') AND marc_field='leader_/1-5' AND id IN
(SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN
(SELECT id FROM search_field WHERE label='llength')
)
|);
# Always end with this (adjust the bug info)
SetVersion( $DBversion );
print "Upgrade to $DBversion done (Bug 22339 - Fix search field mappings of MARC fixed fields)\n";
}

14
t/Koha/SearchEngine/Elasticsearch.t

@ -117,7 +117,7 @@ subtest 'get_elasticsearch_mappings() tests' => sub {
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub {
plan tests => 49;
plan tests => 50;
t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
@ -239,6 +239,15 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
marc_type => 'marc21',
marc_field => 'leader_/6-7',
},
{
name => 'ff7-00',
type => 'string',
facet => 0,
suggestible => 0,
sort => 0,
marc_type => 'marc21',
marc_field => '007_/0',
},
);
my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch');
@ -268,6 +277,7 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
$marc_record_1->leader(' cam 22 a 4500');
$marc_record_1->append_fields(
MARC::Field->new('001', '123'),
MARC::Field->new('007', 'ku'),
MARC::Field->new('020', '', '', a => '1-56619-909-3'),
MARC::Field->new('100', '', '', a => 'Author 1'),
MARC::Field->new('110', '', '', a => 'Corp Author'),
@ -301,6 +311,8 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
is_deeply($docs->[0][1]->{control_number}, ['123'], 'First record control number should be set correctly');
is_deeply($docs->[0][1]->{'ff7-00'}, ['k'], 'First record ff7-00 should be set correctly');
is(scalar @{$docs->[0][1]->{author}}, 2, 'First document author field should contain two values');
is_deeply($docs->[0][1]->{author}, ['Author 1', 'Corp Author'], 'First document author field should be set correctly');

Loading…
Cancel
Save