Bugzilla – Attachment 87905 Details for
Bug 22339
Elasticsearch - fixed field mappings should match MARC ranges
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22339: Fix search field mappings of MARC fixed fields
Bug-22339-Fix-search-field-mappings-of-MARC-fixed-.patch (text/plain), 9.32 KB, created by
Björn Nylén
on 2019-04-12 13:00:24 UTC
(
hide
)
Description:
Bug 22339: Fix search field mappings of MARC fixed fields
Filename:
MIME Type:
Creator:
Björn Nylén
Created:
2019-04-12 13:00:24 UTC
Size:
9.32 KB
patch
obsolete
>From a0d7575ae5134a72e5a1c01580d0f6b535b68a3a Mon Sep 17 00:00:00 2001 >From: Ere Maijala <ere.maijala@helsinki.fi> >Date: Thu, 14 Mar 2019 13:31:34 +0200 >Subject: [PATCH] Bug 22339: Fix search field mappings of MARC fixed fields >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >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> >--- > Koha/SearchEngine/Elasticsearch.pm | 6 +-- > admin/searchengine/elasticsearch/mappings.yaml | 24 +++++------ > installer/data/mysql/atomicupdate/bug_22339.perl | 55 ++++++++++++++++++++++++ > t/Koha/SearchEngine/Elasticsearch.t | 14 +++++- > 4 files changed, 83 insertions(+), 16 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_22339.perl > >diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm >index 3855ce4..e7a44c8 100644 >--- a/Koha/SearchEngine/Elasticsearch.pm >+++ b/Koha/SearchEngine/Elasticsearch.pm >@@ -607,8 +607,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. >@@ -623,7 +623,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]; >diff --git a/admin/searchengine/elasticsearch/mappings.yaml b/admin/searchengine/elasticsearch/mappings.yaml >index 8ead46b..a546c34 100644 >--- a/admin/searchengine/elasticsearch/mappings.yaml >+++ b/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: '' >diff --git a/installer/data/mysql/atomicupdate/bug_22339.perl b/installer/data/mysql/atomicupdate/bug_22339.perl >new file mode 100644 >index 0000000..187e936 >--- /dev/null >+++ b/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"; >+} >diff --git a/t/Koha/SearchEngine/Elasticsearch.t b/t/Koha/SearchEngine/Elasticsearch.t >index 1fe3ad1..4954179 100644 >--- a/t/Koha/SearchEngine/Elasticsearch.t >+++ b/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'); > >-- >2.1.4
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 22339
:
86597
|
87905
|
88706