diff --git a/CHANGELOG.md b/CHANGELOG.md index 923a7b86..bda036d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/web/modules/custom/gos_elasticsearch/src/Plugin/rest/resource/ElasticGamesResource.php b/web/modules/custom/gos_elasticsearch/src/Plugin/rest/resource/ElasticGamesResource.php index 3f0e548e..827310c8 100644 --- a/web/modules/custom/gos_elasticsearch/src/Plugin/rest/resource/ElasticGamesResource.php +++ b/web/modules/custom/gos_elasticsearch/src/Plugin/rest/resource/ElasticGamesResource.php @@ -262,6 +262,18 @@ public function get(Request $request): CacheableJsonResponse { $es_query['body']['aggregations']['aggs_all']['aggs']['all_filtered_release_years_histogram']['filter']['bool']['should'][] = $this->addStatesFilter($states); } + // 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']['query'] = [ + 'function_score' => [ + 'query' => $es_query['body']['query'], + 'random_score' => (object) [], + ], + ]; + } + try { $results = $index->search($es_query); $this->response->setData($results);