Skip to content

Commit 1b6a575

Browse files
committed
Fix FunstionScore Query random_score without seed bug
1 parent 591a74e commit 1b6a575

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

changes.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
CHANGES
22

3+
2014-07-07
4+
- Fix FunstionScore Query random_score without seed bug. #647
5+
36
2014-07-02
47
- Add setPostFilter method to Elastica\Query (http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_filtering_queries_and_aggregations.html#_post_filter) #645
58

lib/Elastica/Query/FunctionScore.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ public function setBoostMode($mode)
171171
*/
172172
public function setRandomScore($seed = NULL)
173173
{
174-
$seedParam = array();
174+
$seedParam = new \stdClass();
175175
if (!is_null($seed)) {
176-
$seedParam['seed'] = $seed;
176+
$seedParam->seed = $seed;
177177
}
178178
return $this->setParam('random_score', $seedParam);
179179
}

test/lib/Elastica/Test/Query/FunctionScoreTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ public function testRandomScore()
170170
$this->assertEquals("Miller's Field", $result0['name']);
171171
}
172172

173+
public function testRandomScoreWithoutSeed()
174+
{
175+
$query = new FunctionScore();
176+
$query->setRandomScore();
177+
178+
$response = $this->type->search($query);
179+
180+
$this->assertEquals(2, $response->count());
181+
}
182+
173183
public function testScriptScore()
174184
{
175185
$scriptString = "_score * doc['price'].value";

0 commit comments

Comments
 (0)