From 8c85389558848b3159aa1ed2bbc10a6d1613bfa5 Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Wed, 4 Feb 2015 16:42:12 +1300 Subject: [PATCH] Bug 12478 - more authority query building 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 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 148f5fb824..9f4846746d 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -269,7 +269,7 @@ sub build_authorities_query { if ($op eq 'is' || $op eq '=') { # look for something that matches completely # note, '=' is about numerical vals. May need special handling. - push @filter_parts, { filter => { term => { $wh => $val }} }; + push @filter_parts, { term => { $wh => $val }}; } elsif ($op eq 'exact') { # left and right truncation, otherwise an exact phrase push @query_parts, { match_phrase => { $wh => $val }}; @@ -280,7 +280,16 @@ sub build_authorities_query { } } # Merge the query and filter parts appropriately - + # 'should' behaves like 'or', if we want 'and', use 'must' + my $query_part = { bool => { should => \@query_parts } }; + my $filter_part = { bool => { should => \@filter_parts }}; + my $query; + if (@filter_parts) { + $query = { query => { filtered => { filter => $filter_part, query => $query_part }}}; + } else { + $query = { query => $query_part }; + } + return $query; } -- 2.39.5