}
}
- 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}
+ ];
}
}
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;
}
-- 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