From 77b1f62a4019f5cab9ad89a13768b651e0810329 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Fri, 3 Nov 2017 13:21:22 +0100 Subject: [PATCH] Bug 19575: Use canonical field names and resolve aliased fields Adjust elastic search mappings to more closely match Zebra equivalents resolving serveral issues with coded Zebra searches in templates, and sorting of search results in UI. --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 135 ++++++++++++++++----- Koha/SearchEngine/Elasticsearch/Search.pm | 10 +- admin/searchengine/elasticsearch/mappings.yaml | 96 +++++++-------- ...ical-field-names-and-resolve-aliased-fields.sql | 20 +++ 4 files changed, 174 insertions(+), 87 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_19575-use-canonical-field-names-and-resolve-aliased-fields.sql diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index cdd0fc6bd1..fd3501eeda 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -112,13 +112,13 @@ sub build_query { # See _convert_facets in Search.pm for how these get turned into # things that Koha can use. $res->{aggregations} = { - author => { terms => { field => "author__facet" } }, - subject => { terms => { field => "subject__facet" } }, - itype => { terms => { field => "itype__facet" } }, + Author => { terms => { field => "Author__facet" } }, + Subject => { terms => { field => "Subject__facet" } }, + itype => { terms => { field => "itype__facet" } }, location => { terms => { field => "location__facet" } }, 'su-geo' => { terms => { field => "su-geo__facet" } }, - se => { terms => { field => "se__facet" } }, - ccode => { terms => { field => "ccode__facet" } }, + 'Title-series' => { terms => { field => "Title-series__facet" } }, + ccode => { terms => { field => "ccode__facet" } }, }; my $display_library_facets = C4::Context->preference('DisplayLibraryFacets'); @@ -477,16 +477,20 @@ sub _convert_sort_fields { # Turn the sorting into something we care about. my %sort_field_convert = ( - acqdate => 'acqdate', - author => 'author', - call_number => 'callnum', + acqdate => 'Date-of-acquisition', + author => 'Author', + call_number => 'Local-classification', popularity => 'issues', relevance => undef, # default - title => 'title', - pubdate => 'pubdate', + title => 'Title', + pubdate => 'Date-of-publication', + ); + my %sort_order_convert = ( + dsc => 'desc', + asc => 'asc', + az => 'asc', + za => 'desc', ); - my %sort_order_convert = - ( qw( dsc desc ), qw( asc asc ), qw( az asc ), qw( za desc ) ); # Convert the fields and orders, drop anything we don't know about. grep { $_->{field} } map { @@ -513,20 +517,97 @@ types. =cut our %index_field_convert = ( - 'kw' => '_all', - 'ti' => 'title', - 'au' => 'author', - 'su' => 'subject', - 'nb' => 'isbn', - 'se' => 'title-series', - 'callnum' => 'callnum', - 'itype' => 'itype', - 'ln' => 'ln', - 'branch' => 'homebranch', - 'fic' => 'lf', - 'mus' => 'rtype', - 'aud' => 'ta', - 'hi' => 'Host-Item-Number', + 'kw' => '_all', + 'ab' => 'Abstract', + 'au' => 'Author', + 'lcn' => 'Local-classification', + 'callnum' => 'Local-classification', + 'ln' => 'language', + 'Record-type' => 'rtype', + 'mc-rtype' => 'rtype', + 'mus' => 'rtype', + 'ctype' => 'Content-type', + 'lc-card' => 'LC-card-number', + 'sn' => 'Local-number', + 'yr' => 'Date-of-publication', + 'pubdate' => 'Date-of-publication', + 'acqdate' => 'Date-of-acquisition', + 'Date-time-last-modified' => 'Date/time-last-modified', + 'dtlm' => 'Date/time-last-modified', + 'diss' => 'Dissertation-information', + 'ean' => 'EAN', + 'nb' => 'ISBN', + 'isbn' => 'ISBN', + 'ns' => 'ISSN', + 'issn' => 'ISSN', + 'Music-number' => 'Identifier-publisher-for-music', + 'Number-music-publisher' => 'Identifier-publisher-for-music', + 'music' => 'Identifier-publisher-for-music', + 'ident' => 'Identifier-standard', + 'name' => 'Name', + 'cpn' => 'Corporate-name', + 'cfn' => 'Conference-name', + 'pl' => 'Place-publication', + 'pn' => 'Personal-name', + 'pb' => 'Publisher', + 'pv' => 'Provider', + 'nt' => 'Note', + 'notes' => 'Note', + 'rcn' => 'Record-control-number', + 'su' => 'Subject', + 'su-to' => 'Subject', + #'su-geo' => 'Subject', + 'su-ut' => 'Subject', + 'ti' => 'Title', + 'se' => 'Title-series', + 'ut' => 'Title-uniform', + 'an' => 'Authority-Number', + 'Koha-Auth-Number' => 'Authority-Number', + 'at' => 'authtype', + 'he' => 'Heading', + 'rank' => 'relevance', + 'phr' => 'st-phrase', + 'wrdl' => 'st-word-list', + 'rt' => 'right-Truncation', + 'rtrn' => 'right-Truncation', + 'ltrn' => 'left-Truncation', + 'rltrn' => 'left-and-right', + 'mc-itemtype' => 'itemtype', + 'mc-ccode' => 'ccode', + 'branch' => 'homebranch', + 'mc-loc' => 'location', + 'stocknumber' => 'Number-local-acquisition', + 'inv' => 'Number-local-acquisition', + 'bc' => 'barcode', + 'mc-itype' => 'itype', + 'aub' => 'Author-personal-bibliography', + 'auo' => 'Author-in-order', + 'ff8-22' => 'ta', + 'aud' => 'ta', + 'audience' => 'ta', + 'Frequency-code' => 'ff8-18', + 'Illustration-code' => 'ff8-18-21', + 'Regularity-code' => 'ff8-19', + 'Type-Of-Serial' => 'ff8-21', + 'format' => 'ff8-23', + 'Conference-code' => 'ff8-29', + 'Festschrift-indicator' => 'ff8-30', + 'Index-indicator' => 'ff8-31', + 'fiction' => 'lf', + 'fic' => 'lf', + 'Literature-Code' => 'lf', + 'biography' => 'bio', + 'ff8-34' => 'bio', + 'Biography-Code' => 'bio', + 'l-format' => 'ff7-01-02', + 'lex' => 'lexile-number', + 'video-mt' => 'Video-mt', + 'Graphic-type' => 'Graphics-type', + 'Graphic-support' => 'Graphics-support', + 'item' => 'Item', + 'hi' => 'Host-Item-Number', + 'itu' => 'Index-term-uncontrolled', + 'itg' => 'Index-term-genre', ); sub _convert_index_fields { @@ -547,7 +628,7 @@ sub _convert_index_fields { $f =~ s/^mc-//; } my $r = { - field => $index_field_convert{$f}, + field => exists $index_field_convert{$f} ? $index_field_convert{$f} : $f, type => $index_type_convert{ $t // '__default' } }; $r->{field} = ($mc . $r->{field}) if $mc && $r->{field}; diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm index 4d584f7906..d9226a59a6 100644 --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ b/Koha/SearchEngine/Elasticsearch/Search.pm @@ -425,13 +425,13 @@ sub _convert_facets { # things that zebra uses. # TODO let the library define the order using the interface. my %type_to_label = ( - author => { order => 1, label => 'Authors', }, - itype => { order => 2, label => 'ItemTypes', }, + Author => { order => 1, label => 'Authors', }, + itype => { order => 2, label => 'ItemTypes', }, location => { order => 3, label => 'Location', }, 'su-geo' => { order => 4, label => 'Places', }, - se => { order => 5, label => 'Series', }, - subject => { order => 6, label => 'Topics', }, - ccode => { order => 7, label => 'CollectionCodes',}, + 'Title-series' => { order => 5, label => 'Series', }, + Subject => { order => 6, label => 'Topics', }, + ccode => { order => 7, label => 'CollectionCodes',}, holdingbranch => { order => 8, label => 'HoldingLibrary' }, homebranch => { order => 9, label => 'HomeLibrary' } ); diff --git a/admin/searchengine/elasticsearch/mappings.yaml b/admin/searchengine/elasticsearch/mappings.yaml index 4c164896ee..d14a556d73 100644 --- a/admin/searchengine/elasticsearch/mappings.yaml +++ b/admin/searchengine/elasticsearch/mappings.yaml @@ -577,8 +577,8 @@ biblios: sort: ~ suggestible: '' type: string - acqdate: - label: acqdate + Date-of-acquisition: + label: Date-of-acquisition mappings: - facet: '' marc_field: 952d @@ -596,8 +596,8 @@ biblios: sort: ~ suggestible: '' type: date - an: - label: an + Authority-Number: + label: Authority-Number mappings: - facet: '' marc_field: '1009' @@ -1120,8 +1120,8 @@ biblios: sort: ~ suggestible: '' type: number - author: - label: author + Author: + label: Author mappings: - facet: '1' marc_field: 100a @@ -1141,12 +1141,12 @@ biblios: - facet: 0 marc_field: 245c marc_type: marc21 - sort: 0 + sort: ~ suggestible: 0 - facet: 1 marc_field: 700a marc_type: marc21 - sort: 0 + sort: ~ suggestible: 1 - facet: '1' marc_field: 100a @@ -1166,12 +1166,12 @@ biblios: - facet: 0 marc_field: 245c marc_type: normarc - sort: 0 + sort: ~ suggestible: 0 - facet: 1 marc_field: 700a marc_type: normarc - sort: 0 + sort: ~ suggestible: 1 - facet: '1' marc_field: 200f @@ -1186,12 +1186,12 @@ biblios: - facet: 1 marc_field: 700a marc_type: unimarc - sort: 0 + sort: ~ suggestible: 1 - facet: 0 marc_field: '701' marc_type: unimarc - sort: 0 + sort: ~ suggestible: 0 type: string bgf-number: @@ -1241,20 +1241,6 @@ biblios: sort: ~ suggestible: '' type: '' - bnb-card-number: - label: bnb-card-number - mappings: - - facet: '' - marc_field: '015' - marc_type: marc21 - sort: ~ - suggestible: '' - - facet: '' - marc_field: '015' - marc_type: normarc - sort: ~ - suggestible: '' - type: '' ccode: label: collection-code mappings: @@ -1274,8 +1260,8 @@ biblios: sort: ~ suggestible: '' type: '' - control-number: - label: control-number + Control-number: + label: Control-number mappings: - facet: '' marc_field: '001' @@ -1481,8 +1467,8 @@ biblios: sort: ~ suggestible: '' type: string - identifier-standard: - label: identifier-standard + Identifier-standard: + label: Identifier-standard mappings: - facet: '' marc_field: '010' @@ -1550,8 +1536,8 @@ biblios: sort: ~ suggestible: '' type: '' - isbn: - label: isbn + ISBN: + label: ISBN mappings: - facet: '' marc_field: 020a @@ -1655,8 +1641,8 @@ biblios: sort: ~ suggestible: '' type: string - lc-cardnumber: - label: lc-cardnumber + LC-card-number: + label: LC-card-number mappings: - facet: '' marc_field: '010' @@ -1678,7 +1664,7 @@ biblios: marc_type: unimarc sort: ~ suggestible: '' - type: '' + type: '' lf: label: lf mappings: @@ -1712,8 +1698,8 @@ biblios: sort: ~ suggestible: '' type: '' - ln: - label: ln + language: + label: language mappings: - facet: '' marc_field: 008_/35-37 @@ -1731,8 +1717,8 @@ biblios: sort: ~ suggestible: '' type: '' - local-classification: - label: local-classification + Local-classification: + label: Local-classification mappings: - facet: '' marc_field: 952o @@ -1877,8 +1863,8 @@ biblios: sort: ~ suggestible: '' type: boolean - pl: - label: pl + Place-publication: + label: Place-publication mappings: - facet: '' marc_field: 008_/15-17 @@ -1891,8 +1877,8 @@ biblios: sort: ~ suggestible: '' type: '' - place: - label: place + Place-of-publication: + label: Place-of-publication mappings: - facet: '1' marc_field: 260a @@ -1910,8 +1896,8 @@ biblios: sort: ~ suggestible: '' type: string - pubdate: - label: pubdate + Date-of-publication: + label: Date-of-publication mappings: - facet: '' marc_field: 008_/7-10 @@ -1929,8 +1915,8 @@ biblios: sort: ~ suggestible: '' type: '' - publisher: - label: publisher + Publisher: + label: Publisher mappings: - facet: '1' marc_field: 260b @@ -1948,8 +1934,8 @@ biblios: sort: ~ suggestible: '' type: string - record-source: - label: record-source + Record-source: + label: Record-source mappings: - facet: '' marc_field: 008_/39 @@ -1976,8 +1962,8 @@ biblios: sort: ~ suggestible: '' type: '' - se: - label: se + Title-series: + label: Title-series mappings: - facet: '1' marc_field: 440a @@ -2024,8 +2010,8 @@ biblios: sort: ~ suggestible: '' type: string - subject: - label: subject + Subject: + label: Subject mappings: - facet: '1' marc_field: 600a @@ -2286,8 +2272,8 @@ biblios: sort: ~ suggestible: '' type: '' - title: - label: title + Title: + label: Title mappings: - facet: '' marc_field: '130' diff --git a/installer/data/mysql/atomicupdate/bug_19575-use-canonical-field-names-and-resolve-aliased-fields.sql b/installer/data/mysql/atomicupdate/bug_19575-use-canonical-field-names-and-resolve-aliased-fields.sql new file mode 100644 index 0000000000..da4d7cf99e --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_19575-use-canonical-field-names-and-resolve-aliased-fields.sql @@ -0,0 +1,20 @@ +UPDATE `search_field` SET `name` = 'Date-of-publication', `label` = 'Date-of-publication' WHERE `name` = 'pubdate'; +UPDATE `search_field` SET `name` = 'Title-series', `label` = 'Title-series' WHERE `name` = 'se'; +UPDATE `search_field` SET `name` = 'Identifier-standard', `label` = 'Identifier-standard' WHERE `name` = 'identifier-standard'; +UPDATE `search_field` SET `name` = 'Author', `label` = 'Author' WHERE `name` = 'author'; +UPDATE `search_field` SET `name` = 'Control-number', `label` = 'Control-number' WHERE `name` = 'control-number'; +UPDATE `search_field` SET `name` = 'Place-publication', `label` = 'Place-publication' WHERE `name` = 'pl'; +UPDATE `search_field` SET `name` = 'Place-of-publication', `label` = 'Place-of-publication' WHERE `name` = 'place'; +UPDATE `search_field` SET `name` = 'Date-of-acquisition', `label` = 'Date-of-acquisition' WHERE `name` = 'acqdate'; +UPDATE `search_field` SET `name` = 'ISBN', `label` = 'ISBN' WHERE `name` = 'isbn'; +UPDATE `search_field` SET `name` = 'BNB-card-number', `label` = 'BNB-card-number' WHERE `name` = 'bnb-card-number'; +UPDATE `search_field` SET `name` = 'Authority-Number', `label` = 'Authority-Number' WHERE `name` = 'an'; +UPDATE `search_field` SET `name` = 'language', `label` = 'language' WHERE `name` = 'ln'; +UPDATE `search_field` SET `name` = 'Subject', `label` = 'Subject' WHERE `name` = 'subject'; +UPDATE `search_field` SET `name` = 'Publisher', `label` = 'Publisher' WHERE `name` = 'publisher'; +UPDATE `search_field` SET `name` = 'Record-source', `label` = 'Record-source' WHERE `name` = 'record-source'; +UPDATE `search_field` SET `name` = 'Title', `label` = 'Title' WHERE `name` = 'title'; +UPDATE `search_field` SET `name` = 'Local-classification', `label` = 'Local-classification' WHERE `name` = 'local-classification'; +DELETE FROM `search_field` WHERE `name` = 'bnb-card-number'; +DELETE FROM `search_field` WHERE `name` = 'lc-cardnumber'; +DELETE FROM `search_marc_map` WHERE `id` NOT IN(SELECT `search_marc_map_id` FROM `search_marc_to_field`); -- 2.11.0