From 1d0edd61bdb3229a75064dd025a54c6c3b4aab15 Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Fri, 13 Mar 2015 15:22:53 +1300 Subject: [PATCH] Bug 12478: sort is sorted Signed-off-by: Nick Clemens Signed-off-by: Jesse Weaver Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall Signed-off-by: Brendan Gallagher --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 7e3522455a..a30f5e1eee 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -260,22 +260,26 @@ The search description is a hashref that looks something like: sub build_authorities_query { my ($self, $search) = @_; +warn "Search is " . Dumper $search; # Start by making the query parts my @query_parts; my @filter_parts; foreach my $s ( @{ $search->{searches} } ) { my ($wh, $op, $val) = @{ $s }{qw(where operator value)}; - $wh = '_all' if $wh eq 'any'; + $wh = '_all' if $wh eq ''; if ($op eq 'is' || $op eq '=') { # look for something that matches completely # note, '=' is about numerical vals. May need special handling. # _allphrase is a special field that only groups the exact # matches. Also, we lowercase our search because the ES - # index lowercases its values. + # index lowercases its values, and term searches don't get the + # search analyzer applied to them. push @filter_parts, { term => { "$wh.phrase" => lc $val }}; } elsif ($op eq 'exact') { # left and right truncation, otherwise an exact phrase push @query_parts, { match_phrase => { $wh => $val }}; + } elsif ($op eq 'start') { + push @query_parts, { wildcard => { "$wh.phrase" => lc "$val*" }}; } else { # regular wordlist stuff # TODO truncation @@ -294,6 +298,7 @@ sub build_authorities_query { } else { $query = { query => $query_part }; } + $query = { %$query, %sort }; return $query; } -- 2.39.5