if ( !$es->{index_name} );
# Append the name of this particular index to our namespace
$es->{index_name} .= '_' . $self->index;
+
+ $es->{key_prefix} = 'es_';
return $es;
}
analyser_standard => {
tokenizer => 'standard',
filter => ['lowercase'],
- }
+ },
+ default => {
+ tokenizer => 'keyword',
+ filter => ['lowercase'],
+ },
},
}
}
include_in_all => JSON::false,
type => "string",
},
- '_all.phrase' => {
- search_analyzer => "analyser_phrase",
- index_analyzer => "analyser_phrase",
- type => "string",
- },
}
}
};
sub {
my ( $name, $type, $facet, $suggestible, $sort, $marc_type ) = @_;
return if $marc_type ne $marcflavour;
+
# TODO if this gets any sort of complexity to it, it should
# be broken out into its own function.
$type eq 'boolean'
? 'boolean'
: 'string';
- $mappings->{data}{properties}{$name} = {
- search_analyzer => "analyser_standard",
- index_analyzer => "analyser_standard",
- type => $es_type,
- fields => {
- phrase => {
- search_analyzer => "analyser_phrase",
- index_analyzer => "analyser_phrase",
- type => "string",
- copy_to => "_all.phrase",
- },
- raw => {
- "type" => "string",
- "index" => "not_analyzed",
- }
- },
- };
- $mappings->{data}{properties}{$name}{null_value} = 0
- if $type eq 'boolean';
+
+ if ($es_type eq 'boolean') {
+ $mappings->{data}{properties}{$name} = _elasticsearch_mapping_for_boolean( $name, $es_type, $facet, $suggestible, $sort, $marc_type );
+ return; #Boolean cannot have facets nor sorting nor suggestions
+ } else {
+ $mappings->{data}{properties}{$name} = _elasticsearch_mapping_for_default( $name, $es_type, $facet, $suggestible, $sort, $marc_type );
+ }
+
if ($facet) {
$mappings->{data}{properties}{ $name . '__facet' } = {
type => "string",
if ($suggestible) {
$mappings->{data}{properties}{ $name . '__suggestion' } = {
type => 'completion',
- index_analyzer => 'simple',
+ analyzer => 'simple',
search_analyzer => 'simple',
};
}
if (defined $sort) {
$mappings->{data}{properties}{ $name . '__sort' } = {
search_analyzer => "analyser_phrase",
- index_analyzer => "analyser_phrase",
+ analyzer => "analyser_phrase",
type => "string",
include_in_all => JSON::false,
fields => {
phrase => {
search_analyzer => "analyser_phrase",
- index_analyzer => "analyser_phrase",
+ analyzer => "analyser_phrase",
type => "string",
},
},
return $mappings;
}
+=head2 _elasticsearch_mapping_for_*
+
+Get the ES mappings for the given data type or a special mapping case
+
+Receives the same parameters from the $self->_foreach_mapping() dispatcher
+
+=cut
+
+sub _elasticsearch_mapping_for_boolean {
+ my ( $name, $type, $facet, $suggestible, $sort, $marc_type ) = @_;
+
+ return {
+ type => $type,
+ null_value => 0,
+ };
+}
+
+sub _elasticsearch_mapping_for_default {
+ my ( $name, $type, $facet, $suggestible, $sort, $marc_type ) = @_;
+
+ return {
+ search_analyzer => "analyser_standard",
+ analyzer => "analyser_standard",
+ type => $type,
+ fields => {
+ phrase => {
+ search_analyzer => "analyser_phrase",
+ analyzer => "analyser_phrase",
+ type => "string",
+ },
+ raw => {
+ type => "string",
+ index => "not_analyzed",
+ }
+ },
+ };
+}
+
sub reset_elasticsearch_mappings {
my $mappings_yaml = C4::Context->config('intranetdir') . '/admin/searchengine/elasticsearch/mappings.yaml';
my $indexes = LoadFile( $mappings_yaml );
my $marcflavour = lc C4::Context->preference('marcflavour');
my @rules;
+
$self->_foreach_mapping(
sub {
my ( $name, $type, $facet, $suggestible, $sort, $marc_type, $marc_field ) = @_;
}
if ($suggestible) {
push @rules,
-"marc_map('$marc_field','${name}__suggestion.input.\$append', $options)";
+ #"marc_map('$marc_field','${name}__suggestion.input.\$append', $options)"; #must not have nested data structures in .input
+ "marc_map('$marc_field','${name}__suggestion.input.\$append')";
}
if ( $type eq 'boolean' ) {
}
}
);
+
+ push @rules, "move_field(_id,es_id)"; #Also you must set the Catmandu::Store::ElasticSearch->new(key_prefix: 'es_');
return \@rules;
}
my %result;
$result{biblioserver}{hits} = $results->total;
$result{biblioserver}{RECORDS} = \@records;
- return (undef, \%result, $self->_convert_facets($results->{facets}, $expanded_facet));
+ return (undef, \%result, $self->_convert_facets($results->{aggregations}, $expanded_facet));
}
=head2 search_auth_compat
type_id => $type . '_id',
expand => $type,
expandable => ( $type ne $exp_facet )
- && ( @{ $data->{terms} } > $limit ),
+ && ( @{ $data->{buckets} } > $limit ),
"type_label_$type_to_label{$type}{label}" => 1,
type_link_value => $type,
order => $type_to_label{$type}{order},
};
- $limit = @{ $data->{terms} } if ( $limit > @{ $data->{terms} } );
- foreach my $term ( @{ $data->{terms} }[ 0 .. $limit - 1 ] ) {
- my $t = $term->{term};
- my $c = $term->{count};
+ $limit = @{ $data->{buckets} } if ( $limit > @{ $data->{buckets} } );
+ foreach my $term ( @{ $data->{buckets} }[ 0 .. $limit - 1 ] ) {
+ my $t = $term->{key};
+ my $c = $term->{doc_count};
my $label;
if ( exists( $special{$type} ) ) {
$label = $special{$type}->{$t} // $t;