Skip to content

Commit

Permalink
add true random search when no parameters (excepted pager )are given …
Browse files Browse the repository at this point in the history
  • Loading branch information
WengerK committed Feb 9, 2024
1 parent db05366 commit 5489d45
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- remove caches on both Search & Autocomplete endpoints (Elasticsearch)

### Added
- add true random search when no parameters (excepted pager )are given on search - Games-of-Switzerland/swissgamesgarden#127

## [0.6.0] - 2024-02-09
### Changed
- move Linters php-deprecation-detector, php-cs-fixer & psalm into own Tools/ComposerJson
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ public function get(Request $request): CacheableJsonResponse {
$index = $this->elasticsearchPluginManager->createInstance(self::ELASTICSEARCH_PLUGIN_ID);
$es_query = $this->buildBaseGamesElasticsearchQuery($index, $resource_validator);

// When no parameters (excepted pager) have been submitted,
// then the order must be random.
// This is intended to be used on Homepage only.
if ($resource_validator->getRaw() === ['page' => '0']) {
$es_query['body']['sort'] = [
'_script' => [
'script' => 'Math.random()',
'type' => 'number',
'order' => 'asc',
],
];
}

// Add the sort property.
if (!empty($resource_validator->getSort())) {
$es_query['body']['sort'] = $this->addSort($resource_validator->getSort());
Expand Down

0 comments on commit 5489d45

Please sign in to comment.