Issue Bug Closed

#108307Search results are sorted the wrong way, e.g. ascending by rank_flag

Monika Schneiders 11/25/25, 08:15 updated 08/11/26, 08:46

Description

Indexed Search 13.4.20
plugin.tx_indexedsearch.settings.defaultOptions.sortDesc = 1 leads to ascending order (the least relevant result comes first).
This is easily fixed via TypoScript by setting defaultOptions.sortDesc = 0. Therefore I assume it’s just a matter of exchanging ASC for DESC or vice versa at some point.

Reviews 4

Files 3

History 612

  1. Garvin Hicking commented and changed status New Needs Feedback <span data-processor="relativetime" data-value="2025-11-25T09:06:43+00:00" > 11/25/25, 09:06 </span>

    Hm, but the query “select * from index_rel order by flags desc, freq desc” actually returns with descending order the highest value first, so that is the most important value first.

    Can you describe this more in depth please?

    The DESC sort order has been in indexed_search forever and from what I can gather it properly sorts by priority with most important items first for “rank_flag” sorting.

  2. Monika Schneiders commented and changed attached sortDesc_0.png attached sortDesc_1_oben.png attached sortDesc_1_unten.png <span data-processor="relativetime" data-value="2025-11-25T10:44:50+00:00" > 11/25/25, 10:44 </span>

    Vielleicht liegt das Problem auch woanders. In beiliegenden Screenshots sieht man nicht nur die beschriebene umgekehrte Sortierreihenfolge, sondern im Vergleich zwischen Bild 1 und 3 auch, dass das Ranking bei der Einstellung sortDesc=0 unerwartet deutlich kleiner als 100% ist.

    Ansonsten wird die Suche hier mit Standardeinstellungen eingesetzt.

  3. Ernesto Baschny commented <span data-processor="relativetime" data-value="2025-12-08T19:11:38+00:00" > 12/08/25, 19:11 </span>

    Got the same problem. Indexedsearch in TYPO3 v12 behaved differently in the default setup, which is:

    defaultOptions {
    …
    sortOrder = rank_flag
    sortDesc = 1

    I think nobody ever configured indexed search to sort by something else than “ranking”. And “descending” seems to be the appropriate default.

    But, due to two bugs (probably introduced when indexed search was migrated to Extbase some 10-12 years ago), it worked as we expect it:

    1. IndexSearchRepository::getDescendingSortOrderFlag() – which processes this value – is misleading / buggy, since it returns DESC in case the sortDesc=0 and empty (default ASC) in case of sortDesc=1.

    2. Until TYPO3 v12, the sortDesc was not being used at all! Thus the value was empty, resulting in DESC by default (which is what we want).

    Now since the bugfix #107780 (https://review.typo3.org/c/Packages/TYPO3.CMS/+/91173) suddenly the bug 2 was fixed, and now in v13 we see the change of behaviour – bug 1 now appearing.

    Hot-Fix for current installations would be to change to `sortDesc = 0`.

    Better yet would be to change the behaviour of getDescendingSortOrderFlag so that it does what it’s name assumes that it does. In case of sortDesc=1, sort by DESC, otherwise sort by ASC.

    Either way, it will change the behavious – as it already happened between v12 and v13.

    Ideas?

  4. Marcel Marty commented <span data-processor="relativetime" data-value="2026-01-28T08:48:08+00:00" > 01/28/26, 08:48 </span>

    We fixed that temporary with the following XCLASS in our site package:

    sitepackage/Classes/XClass/IndexedSearch/Domain/Repository/IndexSearchRepository.php:

    <?php
    
    declare(strict_types=1);
    
    namespace VENDOR\ExtensionName\XClass\IndexedSearch\Domain\Repository;
    
    use TYPO3\CMS\IndexedSearch\Domain\Repository\IndexSearchRepository as BaseIndexSearchRepository;
    
    /**
     * XClass to fix the inverted sorting logic in indexed_search
     */
    class IndexSearchRepository extends BaseIndexSearchRepository
    {
        /**
         * Returns "DESC" or "ASC" depending on the settings of the incoming
         * highest/lowest result order (piVars['desc'])
         *
         * In the original class, the logic was inverted:
         * !$desc ? ' DESC' : ''
         * Which meant that if desc was true, it returned ASC, and if desc was false, it returned DESC.
         *
         * @param bool $inverse If TRUE, inverse the order which is defined by piVars['desc']
         * @return string "DESC" or "ASC"
         */
        protected function getDescendingSortOrderFlag(bool $inverse = false): string
        {
            $desc = $this->descendingSortOrderFlag;
            if ($inverse) {
                $desc = !$desc;
            }
            return $desc ? 'DESC' : 'ASC';
        }
    }

    in ext_localconf.php:

    // XClass for indexed_search to fix sorting logic
    $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\TYPO3\CMS\IndexedSearch\Domain\Repository\IndexSearchRepository::class] = [
        'className' => \VENDOR\ExtensionName\XClass\IndexedSearch\Domain\Repository\IndexSearchRepository::class,
    ];
  5. Gerrit Code Review pushed patch set 1 for main to change 94787 status Needs Feedback Under Review <span data-processor="relativetime" data-value="2026-07-15T06:46:05+00:00" > 07/15/26, 06:46 </span>

  6. Tobias Wojtylak commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-07-23T12:00:09+00:00" > 07/23/26, 12:00 </span>

    Applied in changeset commit:c0b6c146c10b3af86acd758d0349be263f99ab04.