From 11ca03703ab9eccb02d84bf88fa878813b03957e 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 | 123 +++++++++++++++++---- admin/searchengine/elasticsearch/mappings.yaml | 115 +++++++------------ ...ical-field-names-and-resolve-aliased-fields.sql | 17 +++ 3 files changed, 160 insertions(+), 95 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..e4b6ce4f17 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -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 { diff --git a/admin/searchengine/elasticsearch/mappings.yaml b/admin/searchengine/elasticsearch/mappings.yaml index 4c164896ee..1056c25ee6 100644 --- a/admin/searchengine/elasticsearch/mappings.yaml +++ b/admin/searchengine/elasticsearch/mappings.yaml @@ -159,6 +159,11 @@ authorities: marc_type: normarc sort: ~ suggestible: '' + - facet: '' + marc_field: 995j + marc_type: unimarc + sort: ~ + suggestible: '' type: '' Local-number: label: Local-number @@ -577,8 +582,8 @@ biblios: sort: ~ suggestible: '' type: string - acqdate: - label: acqdate + Date-of-acquisition: + label: Date-of-acquisition mappings: - facet: '' marc_field: 952d @@ -596,8 +601,8 @@ biblios: sort: ~ suggestible: '' type: date - an: - label: an + Authority-Number: + label: Authority-Number mappings: - facet: '' marc_field: '1009' @@ -1120,8 +1125,8 @@ biblios: sort: ~ suggestible: '' type: number - author: - label: author + Author: + label: Author mappings: - facet: '1' marc_field: 100a @@ -1141,12 +1146,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 +1171,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 +1191,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 +1246,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 +1265,8 @@ biblios: sort: ~ suggestible: '' type: '' - control-number: - label: control-number + Control-number: + label: Control-number mappings: - facet: '' marc_field: '001' @@ -1481,8 +1472,8 @@ biblios: sort: ~ suggestible: '' type: string - identifier-standard: - label: identifier-standard + Identifier-standard: + label: Identifier-standard mappings: - facet: '' marc_field: '010' @@ -1550,8 +1541,8 @@ biblios: sort: ~ suggestible: '' type: '' - isbn: - label: isbn + ISBN: + label: ISBN mappings: - facet: '' marc_field: 020a @@ -1655,30 +1646,6 @@ biblios: sort: ~ suggestible: '' type: string - lc-cardnumber: - label: lc-cardnumber - mappings: - - facet: '' - marc_field: '010' - marc_type: marc21 - sort: ~ - suggestible: '' - - facet: '' - marc_field: '011' - marc_type: marc21 - sort: ~ - suggestible: '' - - facet: '' - marc_field: '010' - marc_type: normarc - sort: ~ - suggestible: '' - - facet: '' - marc_field: 995j - marc_type: unimarc - sort: ~ - suggestible: '' - type: '' lf: label: lf mappings: @@ -1712,8 +1679,8 @@ biblios: sort: ~ suggestible: '' type: '' - ln: - label: ln + language: + label: language mappings: - facet: '' marc_field: 008_/35-37 @@ -1731,8 +1698,8 @@ biblios: sort: ~ suggestible: '' type: '' - local-classification: - label: local-classification + Local-classification: + label: Local-classification mappings: - facet: '' marc_field: 952o @@ -1877,8 +1844,8 @@ biblios: sort: ~ suggestible: '' type: boolean - pl: - label: pl + Place-publication: + label: Place-publication mappings: - facet: '' marc_field: 008_/15-17 @@ -1891,8 +1858,8 @@ biblios: sort: ~ suggestible: '' type: '' - place: - label: place + Place-of-publication: + label: Place-of-publication mappings: - facet: '1' marc_field: 260a @@ -1910,8 +1877,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 +1896,8 @@ biblios: sort: ~ suggestible: '' type: '' - publisher: - label: publisher + Publisher: + label: Publisher mappings: - facet: '1' marc_field: 260b @@ -1976,8 +1943,8 @@ biblios: sort: ~ suggestible: '' type: '' - se: - label: se + Title-series: + label: Title-series mappings: - facet: '1' marc_field: 440a @@ -2024,8 +1991,8 @@ biblios: sort: ~ suggestible: '' type: string - subject: - label: subject + Subject: + label: Subject mappings: - facet: '1' marc_field: 600a @@ -2286,8 +2253,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..1b0935ba76 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_19575-use-canonical-field-names-and-resolve-aliased-fields.sql @@ -0,0 +1,17 @@ +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` = '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'; +DELETE FROM `search_field` WHERE `name` = 'lc-cardnumber'; +DELETE FROM `search_field` WHERE `name` = 'bnb-card-number'; +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'; -- 2.11.0