From 7318d65be7d1328fd82db7467b241cdc2da610d5 Mon Sep 17 00:00:00 2001
From: Georg Ringer <georg.ringer@gmail.com>
Date: Sun, 8 Mar 2020 23:29:04 +0100
Subject: [PATCH] [BUGFIX] Sort most search words by count

The statistic of EXT:indexed_search must be sorted by the count to avoid
stripping of the most used search words.

Resolves: #83062
Releases: master, 9.5
Change-Id: Id8008e0dc3a1ed2a837474fb954930395c80cc12
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63630
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
---
 .../Classes/Domain/Repository/AdministrationRepository.php      | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/typo3/sysext/indexed_search/Classes/Domain/Repository/AdministrationRepository.php b/typo3/sysext/indexed_search/Classes/Domain/Repository/AdministrationRepository.php
index 35e166074917..216b8f59d66d 100644
--- a/typo3/sysext/indexed_search/Classes/Domain/Repository/AdministrationRepository.php
+++ b/typo3/sysext/indexed_search/Classes/Domain/Repository/AdministrationRepository.php
@@ -405,6 +405,7 @@ class AdministrationRepository
                 )
             )
             ->groupBy('word')
+            ->orderBy('c', 'desc')
             ->setMaxResults((int)$max);
 
         if (!empty($additionalWhere)) {
@@ -413,6 +414,7 @@ class AdministrationRepository
 
         $result = $queryBuilder->execute();
         $countQueryBuilder = clone $queryBuilder;
+        $countQueryBuilder->resetQueryPart('orderBy');
         $count = (int)$countQueryBuilder
             ->count('uid')
             ->execute()
-- 
GitLab