forked from ongr-io/ElasticsearchDSL
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functional score test (ongr-io#189)
* add functional score test * update tests changed deprecated getMock to getMockBuilder * updated travis
- Loading branch information
Showing
16 changed files
with
108 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the ONGR package. | ||
* | ||
* (c) NFQ Technologies UAB <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace ONGR\ElasticsearchDSL\Tests\Functional\Query; | ||
|
||
use ONGR\ElasticsearchDSL\Query\FunctionScoreQuery; | ||
use ONGR\ElasticsearchDSL\Query\MatchAllQuery; | ||
use ONGR\ElasticsearchDSL\Search; | ||
use ONGR\ElasticsearchDSL\Tests\Functional\AbstractElasticsearchTestCase; | ||
|
||
class FunctionScoreQueryTest extends AbstractElasticsearchTestCase | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getDataArray() | ||
{ | ||
return [ | ||
'product' => [ | ||
[ | ||
'title' => 'acme', | ||
'price' => 10, | ||
], | ||
[ | ||
'title' => 'foo', | ||
'price' => 20, | ||
], | ||
[ | ||
'title' => 'bar', | ||
'price' => 30, | ||
], | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* Match all test | ||
*/ | ||
public function testRandomScore() | ||
{ | ||
$fquery = new FunctionScoreQuery(new MatchAllQuery()); | ||
$fquery->addRandomFunction(); | ||
$fquery->addParameter('boost_mode', 'multiply'); | ||
|
||
$search = new Search(); | ||
$search->addQuery($fquery); | ||
$results = $this->executeSearch($search); | ||
|
||
$this->assertEquals(count($this->getDataArray()['product']), count($results)); | ||
} | ||
|
||
public function testScriptScore() | ||
{ | ||
$fquery = new FunctionScoreQuery(new MatchAllQuery()); | ||
$fquery->addScriptScoreFunction( | ||
'price = doc[\'price\'].value; margin = doc[\'margin\'].value; | ||
if (price > target) { return price * (1 - discount); }; | ||
return price;', | ||
[ | ||
'target' => 20, | ||
'discount' => 0.9, | ||
], | ||
[ | ||
'lang' => 'groovy', | ||
] | ||
); | ||
|
||
$search = new Search(); | ||
$search->addQuery($fquery); | ||
$results = $this->executeSearch($search); | ||
|
||
foreach ($results as $document) { | ||
$this->assertLessThanOrEqual(20, $document['price']); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters