Bug 12478: sort is sorted
authorRobin Sheat <robin@catalyst.net.nz>
Fri, 13 Mar 2015 02:22:53 +0000 (15:22 +1300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 26 Apr 2016 12:55:48 +0000 (09:55 -0300)
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Koha/SearchEngine/Elasticsearch/QueryBuilder.pm

index 7e35224..a30f5e1 100644 (file)
@@ -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;
 }