From 48c31420a7586dbfcab0afe7e59388a565b9a073 Mon Sep 17 00:00:00 2001 From: bach Date: Wed, 9 Sep 2026 16:02:39 +0200 Subject: [PATCH] search results in changed order #3584 --- config/sync/search_api.index.database.yml | 8 ++++++++ .../custom/materio_sapi/src/Controller/Base.php | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/config/sync/search_api.index.database.yml b/config/sync/search_api.index.database.yml index feb7bbde..786a2612 100644 --- a/config/sync/search_api.index.database.yml +++ b/config/sync/search_api.index.database.yml @@ -69,6 +69,14 @@ name: database description: '' read_only: false field_settings: + changed: + label: Changed + datasource_id: 'entity:node' + property_path: changed + type: date + dependencies: + module: + - node field_country_name_computed: label: 'Country Name' datasource_id: 'entity:node' diff --git a/web/modules/custom/materio_sapi/src/Controller/Base.php b/web/modules/custom/materio_sapi/src/Controller/Base.php index 83bfd617..fb6d8c40 100644 --- a/web/modules/custom/materio_sapi/src/Controller/Base.php +++ b/web/modules/custom/materio_sapi/src/Controller/Base.php @@ -79,6 +79,10 @@ class Base extends ControllerBase { // Add sorting. $this->phrase_query->sort('search_api_relevance', 'DESC'); + // Tiebreaker: among equally relevant matches, show the most recently + // modified first (Solr otherwise falls back to internal doc order, i.e. + // indexation order, which puts the oldest materiaux first). + $this->phrase_query->sort('changed', 'DESC'); // Set one or more tags for the query. // @see hook_search_api_query_TAG_alter() @@ -186,6 +190,10 @@ class Base extends ControllerBase { // Add sorting. $this->and_query->sort('search_api_relevance', 'DESC'); + // Tiebreaker: among equally relevant matches, show the most recently + // modified first (Solr otherwise falls back to internal doc order, i.e. + // indexation order, which puts the oldest materiaux first). + $this->and_query->sort('changed', 'DESC'); // Set one or more tags for the query. // @see hook_search_api_query_TAG_alter() @@ -280,6 +288,10 @@ class Base extends ControllerBase { // Add sorting. $this->or_query->sort('search_api_relevance', 'DESC'); + // Tiebreaker: among equally relevant matches, show the most recently + // modified first (Solr otherwise falls back to internal doc order, i.e. + // indexation order, which puts the oldest materiaux first). + $this->or_query->sort('changed', 'DESC'); // Set one or more tags for the query. // @see hook_search_api_query_TAG_alter()