-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from adshares/develop
Develop
- Loading branch information
Showing
10 changed files
with
629 additions
and
989 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
51 changes: 51 additions & 0 deletions
51
src/Infrastructure/ElasticSearch/QueryBuilder/DirectDealQueryBuilder.php
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,51 @@ | ||
<?php | ||
|
||
/** | ||
* @phpcs:disable Generic.Files.LineLength.TooLong | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Infrastructure\ElasticSearch\QueryBuilder; | ||
|
||
class DirectDealQueryBuilder | ||
{ | ||
private const SCRIPT_SCORE = <<<PAINLESS | ||
return Math.round( | ||
100000.0 | ||
* (params.last_seen_banners.containsKey(doc._id[0]) ? (params.last_seen_banners[doc._id[0]]) : 1) | ||
* (params.last_seen_campaigns.containsKey(doc['campaign_id'][0]) ? (params.last_seen_campaigns[doc['campaign_id'][0]]) : 1) | ||
) | ||
* 100000 | ||
+ Math.random(); | ||
PAINLESS; | ||
|
||
private QueryInterface $query; | ||
private array $userHistory; | ||
|
||
public function __construct(QueryInterface $query, array $userHistory) | ||
{ | ||
$this->query = $query; | ||
$this->userHistory = $userHistory; | ||
} | ||
|
||
public function build(): array | ||
{ | ||
return [ | ||
'function_score' => [ | ||
'boost_mode' => 'replace', | ||
'query' => $this->query->build(), | ||
'script_score' => [ | ||
'script' => [ | ||
'lang' => 'painless', | ||
'params' => [ | ||
'last_seen_banners' => (object)$this->userHistory['banners'], | ||
'last_seen_campaigns' => (object)$this->userHistory['campaigns'], | ||
], | ||
'source' => self::SCRIPT_SCORE, | ||
], | ||
], | ||
] | ||
]; | ||
} | ||
} |
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
Oops, something went wrong.