Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Fix issue with empty function_score query (#109)
Browse files Browse the repository at this point in the history
* Fix issue with empty function_score query. "match_all": [] should be "match_all": {}

* Add unit test for empty function score query
  • Loading branch information
hungneox committed Jun 18, 2018
1 parent bd3a32e commit e9bfa0a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Search/Query/Compound/FunctionScoreQuery.php
Expand Up @@ -59,7 +59,7 @@ public function toArray()
if (!empty($queryArray)) {
$array['query'] = $queryArray;
} else {
$array['query'] = ['match_all' => []];
$array['query'] = ['match_all' => new \stdClass()];
}
}

Expand Down
25 changes: 21 additions & 4 deletions tests/Search/Query/Compound/FunctionScoreQueryTest.php
Expand Up @@ -59,11 +59,11 @@ public function testToArray()
]
]
],
'weight' => 34.12,
'boost' => 5.1,
'max_boost' => 14.3,
'weight' => 34.12,
'boost' => 5.1,
'max_boost' => 14.3,
'boost_mode' => 'multiply',
'min_score' => 1,
'min_score' => 1,
]
];

Expand Down Expand Up @@ -99,4 +99,21 @@ public function testToArrayMinimumFields()

$this->assertEquals($expectedArray, $functionScoreQuery->toArray());
}

public function testEmptyQuery()
{
$functionScoreQuery = new FunctionScoreQuery();

$functionScoreQuery->setQuery(new BoolQuery());

$expectedArray = [
'function_score' => [
'query' => [
'match_all' => new \stdClass()
],
],
];

$this->assertEquals($expectedArray, $functionScoreQuery->toArray());
}
}

0 comments on commit e9bfa0a

Please sign in to comment.