Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading