From 4c67555c49d40198c3e6b5cce65f30a2d7d69878 Mon Sep 17 00:00:00 2001 From: Drilon S Date: Fri, 9 Nov 2018 15:14:48 +0100 Subject: [PATCH] Temporary Fix added functions_score (tmp solution) --- src/ElasticEngine.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/ElasticEngine.php b/src/ElasticEngine.php index 06b7280..33c1b8c 100644 --- a/src/ElasticEngine.php +++ b/src/ElasticEngine.php @@ -86,6 +86,7 @@ public function delete($models) public function buildSearchQueryPayloadCollection(Builder $builder, array $options = []) { $payloadCollection = collect(); + $withFunction = false; if ($builder instanceof SearchBuilder) { $searchRules = $builder->rules ?: $builder->model->getSearchRules(); @@ -100,7 +101,13 @@ public function buildSearchQueryPayloadCollection(Builder $builder, array $optio $ruleEntity = new $rule($builder); if ($ruleEntity->isApplicable()) { - $payload->setIfNotEmpty('body.query.bool', $ruleEntity->buildQueryPayload()); + + if(method_exists($ruleEntity, 'buildFunctionQueryPayload')) { + $withFunction = true; + $payload->setIfNotEmpty('body.query', $ruleEntity->buildFunctionQueryPayload()); + }else { + $payload->setIfNotEmpty('body.query.bool', $ruleEntity->buildQueryPayload()); + } if ($options['highlight'] ?? true) { $payload->setIfNotEmpty('body.highlight', $ruleEntity->buildHighlightPayload()); @@ -119,7 +126,7 @@ public function buildSearchQueryPayloadCollection(Builder $builder, array $optio $payloadCollection->push($payload); } - return $payloadCollection->map(function (TypePayload $payload) use ($builder, $options) { + return $payloadCollection->map(function (TypePayload $payload) use ($builder, $options, $withFunction) { $payload ->setIfNotEmpty('body._source', $builder->select) ->setIfNotEmpty('body.collapse.field', $builder->collapse) @@ -131,7 +138,12 @@ public function buildSearchQueryPayloadCollection(Builder $builder, array $optio foreach ($builder->wheres as $clause => $filters) { - $clauseKey = 'body.query.bool.filter.bool.' . $clause; + if($withFunction) { + $clauseKey = 'body.query.function_score.query.bool.filter.bool.' . $clause; + + }else { + $clauseKey = 'body.query.bool.filter.bool.' . $clause; + } $clauseValue = array_merge( $payload->get($clauseKey, []),