bib-search indexing; search api wip
authorBill Erickson <berickxx@gmail.com>
Wed, 24 Oct 2018 21:42:28 +0000 (17:42 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 28 Aug 2019 21:41:55 +0000 (17:41 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm
Open-ILS/src/perlmods/lib/OpenILS/Elastic/BibSearch.pm
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.elastic-search.sql

index 46b79a3..eff1957 100644 (file)
@@ -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}
+            ];
         }
     }
 
index 6405a0f..2eab61c 100644 (file)
@@ -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;
     }
 
index 36bf569..d7e71df 100644 (file)
@@ -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