From 824a444353b1dc76f5f644348ad9bdc2cff48565 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 25 May 2018 13:06:16 +0000 Subject: [PATCH] Bug 18163: Pass through limits in ES Before these patches we only allow a small subset of indexes to be used as limits - if we are going to let users add new fields eventually we probably don't want to strip out terms we didn't plan for. To test: 1 - Enable ES 2 - Using sample kohadevbox data try a search like this (or adjust as necessary): http://localhost:8080/cgi-bin/koha/opac-search.pl?idx=kw&idx=kw&idx=kw&limit=subject%2Cphr%3Astreet&sort_by=relevance&do=Search 3 - Note nothing is found 4 - Apply patches 5 - Repeat search 6 - It works! --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 8a0ead1..9f09da2 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -199,13 +199,13 @@ sub build_query_compat { my ( $self, $operators, $operands, $indexes, $orig_limits, $sort_by, $scan, $lang, $params ) = @_; - #die Dumper ( $self, $operators, $operands, $indexes, $orig_limits, $sort_by, $scan, $lang ); my @sort_params = $self->_convert_sort_fields(@$sort_by); my @index_params = $self->_convert_index_fields(@$indexes); my $limits = $self->_fix_limit_special_cases($orig_limits); if ( $params->{suppress} ) { push @$limits, "suppress:0"; } + # Merge the indexes in with the search terms and the operands so that # each search thing is a handy unit. unshift @$operators, undef; # The first one can't have an op @@ -540,7 +540,7 @@ sub _convert_index_fields { # If a field starts with mc- we save it as it's used (and removed) later # when joining things, to indicate we make it an 'OR' join. # (Sorry, this got a bit ugly after special cases were found.) - grep { $_->{field} } map { + map { my ( $f, $t ) = split /,/; my $mc = ''; if ($f =~ /^mc-/) { @@ -548,7 +548,7 @@ sub _convert_index_fields { $f =~ s/^mc-//; } my $r = { - field => $index_field_convert{$f}, + field => $index_field_convert{$f} // $f, type => $index_type_convert{ $t // '__default' } }; $r->{field} = ($mc . $r->{field}) if $mc && $r->{field}; @@ -716,7 +716,6 @@ to ensure those parts are correct. sub _clean_search_term { my ( $self, $term ) = @_; - my $auto_truncation = C4::Context->preference("QueryAutoTruncate") || 0; # Some hardcoded searches (like with authorities) produce things like -- 2.1.4