From a5e698b027ce7ca7a7d0b9841dfa3771b3faaf86 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 5 Sep 2019 15:59:18 -0400 Subject: [PATCH] additional index tidying Signed-off-by: Bill Erickson --- .../OpenILS/Application/Search/ElasticMapper.pm | 2 +- .../src/perlmods/lib/OpenILS/Elastic/Bib/Search.pm | 34 ++++++++++++---------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/ElasticMapper.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/ElasticMapper.pm index 1d1dcdc3de..43d36e1242 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/ElasticMapper.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/ElasticMapper.pm @@ -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"}}; } } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Elastic/Bib/Search.pm b/Open-ILS/src/perlmods/lib/OpenILS/Elastic/Bib/Search.pm index 7c5d92c48b..fcb36bb85f 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Elastic/Bib/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Elastic/Bib/Search.pm @@ -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; -- 2.11.0