From 18abcb0445d0617f1b5651caff5453ecea083225 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 24 Oct 2018 17:42:28 -0400 Subject: [PATCH] bib-search indexing; search api wip Signed-off-by: Bill Erickson --- .../lib/OpenILS/Application/Search/Biblio.pm | 29 ++++++++++++++---- .../src/perlmods/lib/OpenILS/Elastic/BibSearch.pm | 23 +++++++++++---- .../sql/Pg/upgrade/XXXX.schema.elastic-search.sql | 34 ++++++++++++++-------- 3 files changed, 62 insertions(+), 24 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm index 46b79a3308..eff1957505 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm @@ -1400,12 +1400,29 @@ sub elastic_search { } } - if ($calls{sort}) { - my $key = 'title.raw' if ($calls{sort} =~ /title/); - $key = 'author.raw' if ($calls{sort} =~ /author/); - $key = 'pub_date' if ($calls{sort} =~ /pubdate/); - if ($key) { - $elastic_query->{sort} = [{$key => $descending ? 'desc' : 'asc'}]; + if (my $key = $calls{sort}) { + + # These sort fields match the default display field entries. + # TODO: index fields specific to sorting + + my $dir = $descending ? 'desc' : 'asc'; + if ($key =~ /title/) { + $elastic_query->{sort} = [ + {'title|sort' => $dir}, + {'title|proper.raw' => $dir} + {'title|maintitle.raw' => $dir} + ]; + + } elsif ($key =~ /author/) { + $elastic_query->{sort} = [ + {'author|sort' => $dir}, + {'author|first_author.raw' => $dir} + ]; + + } elsif ($key =~ /pubdate/) { + $elastic_query->{sort} = [ + {'identifier|pub_date' => $dir} + ]; } } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Elastic/BibSearch.pm b/Open-ILS/src/perlmods/lib/OpenILS/Elastic/BibSearch.pm index 6405a0fbe7..2eab61c6a6 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Elastic/BibSearch.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Elastic/BibSearch.pm @@ -186,14 +186,25 @@ sub create_index { my $field_class = $field->{field_class}; my $field_name = "$field_class|" . $field->{name}; + my $datatype = $field->{datatype}; + my $def; - # Clone the class-level index definition (e.g. title) to - # use as the source of the field-specific index. - my $def = clone($BASE_PROPERTIES->{$field_class}); + if ($datatype eq 'text') { + + # Clone the class-level index definition (e.g. title) to + # use as the source of the field-specific index. + $def = clone($BASE_PROPERTIES->{$field_class}); + + # Copy data for all search fields to their parent class to + # support group-level searches (e.g. title search) + $def->{copy_to} = $field_class; + + } else { + # non-text (keyword, etc.) fields are indexed as-is, no extra text field + # index analysis is necessary. + $def = {type => $datatype}; + } - # Copy data for all fields to their parent class to - # support group-level searches (e.g. title search) - $def->{copy_to} = $field_class; $mappings->{$field_name} = $def; } diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.elastic-search.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.elastic-search.sql index 36bf569c5a..d7e71df094 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.elastic-search.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.elastic-search.sql @@ -85,33 +85,43 @@ WHERE cmf.xpath IS NOT NULL AND (cmf.search_field OR cmf.facet_field); -- Add additional indexes for other search-y / filter-y stuff INSERT INTO config.elastic_marc_field - (index, active, field_class, label, name, format, - datatype, search_field, facet_field, xpath) + (index, active, search_field, facet_field, + field_class, label, name, format, datatype, xpath) VALUES ( (SELECT id FROM config.elastic_index WHERE purpose = 'bib-search'), - TRUE, - 'identifier', 'Language', 'item_lang', 'marcxml', 'keyword', TRUE, TRUE, + TRUE, TRUE, TRUE, + 'identifier', 'Language', 'item_lang', 'marcxml', 'keyword', $$substring(//marc:controlfield[@tag='008']/text(), '36', '3')$$ ), ( (SELECT id FROM config.elastic_index WHERE purpose = 'bib-search'), - TRUE, - 'identifier', 'Item Form', 'item_form', 'marcxml', 'keyword', TRUE, TRUE, + TRUE, TRUE, TRUE, + 'identifier', 'Item Form', 'item_form', 'marcxml', 'keyword', $$substring(//marc:controlfield[@tag='008']/text(), '24', '1')$$ ), ( (SELECT id FROM config.elastic_index WHERE purpose = 'bib-search'), - TRUE, - 'identifier', 'Audience', 'audience', 'marcxml', 'keyword', TRUE, TRUE, + TRUE, TRUE, TRUE, + 'identifier', 'Audience', 'audience', 'marcxml', 'keyword', $$substring(//marc:controlfield[@tag='008']/text(), '23', '1')$$ ), ( (SELECT id FROM config.elastic_index WHERE purpose = 'bib-search'), - TRUE, - 'identifier', 'Literary Form', 'lit_form', 'marcxml', 'keyword', TRUE, TRUE, + TRUE, TRUE, TRUE, + 'identifier', 'Literary Form', 'lit_form', 'marcxml', 'keyword', $$substring(//marc:controlfield[@tag='008']/text(), '34', '1')$$ ), ( (SELECT id FROM config.elastic_index WHERE purpose = 'bib-search'), - TRUE, - 'identifier', 'Publication Date', 'pub_date', 'mods32', 'long', TRUE, TRUE, + TRUE, TRUE, TRUE, + 'identifier', 'Publication Date', 'pub_date', 'mods32', 'long', $$//mods32:mods/mods32:originInfo/mods32:dateIssued[@encoding='marc']$$ +), ( + (SELECT id FROM config.elastic_index WHERE purpose = 'bib-search'), + TRUE, FALSE, TRUE, + 'title', 'Title Sort', 'sort', 'mods32', 'keyword', + $$(//mods32:mods/mods32:titleInfo[mods32:nonSort]/mods32:title|//mods32:mods/mods32:titleNonfiling[mods32:title and not (@type)])[1]$$ +), ( + (SELECT id FROM config.elastic_index WHERE purpose = 'bib-search'), + TRUE, FALSE, TRUE, + 'author', 'Author Sort', 'sort', 'mods32', 'keyword', + $$//mods32:mods/mods32:name[mods32:role/mods32:roleTerm[text()='creator']][1]$$ ); -- TODO ADD MORE FIELDS -- 2.11.0