From 8f108a8cd39acc4c1f82f9dd229890cfc4650f9b Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Sat, 10 Aug 2024 11:12:47 -0700 Subject: [PATCH] Fixed #15513 --- CHANGELOG.md | 1 + src/elements/db/ElementQuery.php | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e1b19eb00a..a5af1c80714 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Fixed an error that occurred when installing Craft in PostgreSQL. ([#15504](https://github.com/craftcms/cms/issues/15504)) - Fixed a bug where Matrix fields weren’t retaining the sort order for disabled nested entries. ([#15505](https://github.com/craftcms/cms/issues/15505)) - Fixed a bug where Link fields weren’t displaying their input if they only had one type selected, and it wasn’t URL. ([#15512](https://github.com/craftcms/cms/issues/15512)) +- Fixed a bug where elements’ `searchScore` values were `null` when ordering an element query by `score`. ([#15513](https://github.com/craftcms/cms/issues/15513)) ## 5.3.1 - 2024-08-07 diff --git a/src/elements/db/ElementQuery.php b/src/elements/db/ElementQuery.php index 4503ed871ca..46d70d660d2 100644 --- a/src/elements/db/ElementQuery.php +++ b/src/elements/db/ElementQuery.php @@ -1696,8 +1696,11 @@ public function populate($rows): array // Should we set a search score on the elements? if (isset($this->_searchResults)) { foreach ($rows as &$row) { - if (isset($row['id'], $this->_searchResults[$row['id']])) { - $row['searchScore'] = (int)round($this->_searchResults[$row['id']]); + if (isset($row['id'], $row['siteId'])) { + $key = sprintf('%s-%s', $row['id'], $row['siteId']); + if (isset($this->_searchResults[$key])) { + $row['searchScore'] = (int)round($this->_searchResults[$key]); + } } } }