diff --git a/src/Search/Query/Compound/FunctionScoreQuery.php b/src/Search/Query/Compound/FunctionScoreQuery.php index a4d4663..5699197 100644 --- a/src/Search/Query/Compound/FunctionScoreQuery.php +++ b/src/Search/Query/Compound/FunctionScoreQuery.php @@ -59,7 +59,7 @@ public function toArray() if (!empty($queryArray)) { $array['query'] = $queryArray; } else { - $array['query'] = ['match_all' => []]; + $array['query'] = ['match_all' => new \stdClass()]; } } diff --git a/tests/Search/Query/Compound/FunctionScoreQueryTest.php b/tests/Search/Query/Compound/FunctionScoreQueryTest.php index 96e5f82..9baf962 100644 --- a/tests/Search/Query/Compound/FunctionScoreQueryTest.php +++ b/tests/Search/Query/Compound/FunctionScoreQueryTest.php @@ -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, ] ]; @@ -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()); + } }