additional index tidying
authorBill Erickson <berickxx@gmail.com>
Thu, 5 Sep 2019 19:59:18 +0000 (15:59 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 21 Feb 2020 21:19:51 +0000 (16:19 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Search/ElasticMapper.pm
Open-ILS/src/perlmods/lib/OpenILS/Elastic/Bib/Search.pm

index 1d1dcdc..43d36e1 100644 (file)
@@ -443,7 +443,7 @@ sub add_elastic_facet_aggregations {
         my $fgrp = $facet->search_group;
         $fname = "$fgrp|$fname" if $fgrp;
 
-        $elastic_query->{aggs}{$fname} = {terms => {field => $fname}};
+        $elastic_query->{aggs}{$fname} = {terms => {field => "$fname.raw"}};
     }
 }
 
index 7c5d92c..fcb36bb 100644 (file)
@@ -127,39 +127,43 @@ sub create_index {
         my $search_group = $field->search_group;
         $field_name = "$search_group|$field_name" if $search_group;
 
-        # Every field gets a keyword index (default) for aggregation and 
-        # a lower-case keyword index (.lower) for sorting and certain
-        # types of searches (exact match, starts with)
+        # Every field gets a lowercase keyword index for term 
+        # searches/filters and sorting.
         my $def = {
             type => 'keyword',
-            fields => {
-                lower => {
-                    type => 'keyword', 
-                    normalizer => 'custom_lowercase'
-                }
-            }
+            normalizer => 'custom_lowercase'
         };
 
-        if ($field->search_field eq 't') {
-            # Search fields also get full text indexing and analysis
-            # plus a "folded" variation for ascii folded searches.
+        my $fields = {};
 
-            $def->{fields}->{text} = {type => 'text'};
+        if ($field->facet_field eq 't') {
+            # Facet fields are used for aggregation which requires
+            # an unaltered keyword field.
+            $fields->{raw} = {type => 'keyword'};
+        }
 
-            $def->{fields}->{text_folded} = {
+        if ($field->search_field eq 't') {
+            # Text search fields get an additional variety of indexes to
+            # support full text searching
+            # The 'raw' field is used for aggregation.
+
+            $fields->{text} = {type => 'text'},
+            $fields->{text_folded} = {
                 type => 'text', 
                 analyzer => 'folding'
             };
 
             # Add the language analyzers
             for my $lang_analyzer ($self->language_analyzers) {
-                $def->{fields}->{"text_$lang_analyzer"} = {
+                $fields->{"text_$lang_analyzer"} = {
                     type => 'text',
                     analyzer => $lang_analyzer
                 };
             }
         }
 
+        $def->{fields} = $fields if keys %$fields;
+
         # Apply field boost.
         $def->{boost} = $field->weight if ($field->weight || 1) > 1;