Skip to content

Commit

Permalink
Temporary Fix
Browse files Browse the repository at this point in the history
added functions_score (tmp solution)
  • Loading branch information
LonnyX authored Nov 9, 2018
1 parent be363a6 commit 4c67555
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/ElasticEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
Expand All @@ -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)
Expand All @@ -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, []),
Expand Down

0 comments on commit 4c67555

Please sign in to comment.