File 2002-krunner.patch of Package plasma6-workspace

diff --git a/krunner/view.cpp b/krunner/view.cpp
index 45dc7c33fefd5227f67f06dd11ecd7db2b035d5b..828ac3e86002ab5619fa52d85a210750ea72747e 100644
--- a/krunner/view.cpp
+++ b/krunner/view.cpp
@@ -49,10 +49,10 @@ View::View(PlasmaQuick::SharedQmlEngine *engine, QWindow *)
     setTitle(i18n("KRunner"));
 
     m_config = KConfigGroup(KSharedConfig::openConfig(), u"General"_s);
-    m_stateData = KSharedConfig::openConfig(u"krunnerstaterc"_s, //
+    m_stateData = KSharedConfig::openConfig(u"krunner/krunnerstaterc"_s, //
                                             KConfig::NoGlobals,
                                             QStandardPaths::GenericDataLocation)
-                      ->group(u"General"_s);
+                      ->group(u"PlasmaRunnerManager"_s);
     m_configWatcher = KConfigWatcher::create(KSharedConfig::openConfig());
     connect(m_configWatcher.data(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group) {
         const QLatin1String pluginsGrp("Plugins");
diff --git a/runners/services/servicerunner.cpp b/runners/services/servicerunner.cpp
index 00853a6aab63450204e8e2e60d10202a008bf884..a88a2e301e1cbff689921ff4fe2dfc61b0e2a1de 100644
--- a/runners/services/servicerunner.cpp
+++ b/runners/services/servicerunner.cpp
@@ -16,6 +16,7 @@
 #include <QDebug>
 #include <QDir>
 #include <QIcon>
+#include <QRegularExpression>
 #include <QStandardPaths>
 #include <QUrl>
 #include <QUrlQuery>
@@ -37,11 +38,6 @@
 
 #include "debug.h"
 
-int weightedLength(const QString &query)
-{
-    return KStringHandler::logicalLength(query);
-}
-
 inline bool contains(const QString &result, const QList<QStringView> &queryList)
 {
     return std::all_of(queryList.cbegin(), queryList.cend(), [&result](QStringView query) {
@@ -58,6 +54,36 @@ inline bool contains(const QStringList &results, const QList<QStringView> &query
     });
 }
 
+bool acceptMatch(const QString &text, const QString &query, KRunner::QueryMatch &match, qreal relevance)
+{
+    if (text.isEmpty() || query.isEmpty()) {
+        return false;
+    }
+
+    if (text.compare(query, Qt::CaseInsensitive) == 0) {
+        match.setCategoryRelevance(KRunner::QueryMatch::CategoryRelevance::Highest);
+        match.setRelevance(relevance);
+
+        return true;
+    }
+
+    if (text.startsWith(query, Qt::CaseInsensitive)) {
+        match.setCategoryRelevance(KRunner::QueryMatch::CategoryRelevance::High);
+        match.setRelevance(relevance * 0.5);
+
+        return true;
+    }
+
+    if (KStringHandler::logicalLength(query) > 2 && text.contains(query, Qt::CaseInsensitive)) {
+        match.setCategoryRelevance(KRunner::QueryMatch::CategoryRelevance::Moderate);
+        match.setRelevance(relevance * 0.25);
+
+        return true;
+    }
+
+    return false;
+}
+
 /**
  * @brief Finds all KServices for a given runner query
  */
@@ -76,10 +102,8 @@ public:
         query = context.query();
         // Splitting the query term to match using subsequences
         queryList = QStringView(query).split(QLatin1Char(' '));
-        weightedTermLength = weightedLength(query);
 
         matchNameKeywordAndGenericName();
-        matchCategories();
         matchJumpListActions();
 
         context.addMatches(matches);
@@ -130,10 +154,6 @@ private:
                 if (serviceProperty.contains(str, Qt::CaseInsensitive)) {
                     relevanceIncrement += 0.01;
                 }
-            } else if (category == Category::Comment) {
-                if (serviceProperty.contains(str, Qt::CaseInsensitive)) {
-                    relevanceIncrement += 0.01;
-                }
             }
         }
 
@@ -210,136 +230,33 @@ private:
 
     void matchNameKeywordAndGenericName()
     {
-        const auto nameKeywordAndGenericNameFilter = [this](const KService::Ptr &service) {
-            // Name
-            if (contains(service->name(), queryList)) {
-                return true;
-            }
-            // If the term length is < 3, no real point searching the untranslated Name, Keywords and GenericName
-            if (weightedTermLength < 3) {
-                return false;
-            }
-            if (contains(service->untranslatedName(), queryList)) {
-                return true;
-            }
-
-            // Keywords
-            if (contains(service->keywords(), queryList)) {
-                return true;
-            }
-            // GenericName
-            if (contains(service->genericName(), queryList) || contains(service->untranslatedGenericName(), queryList)) {
-                return true;
-            }
-            // Comment
-            if (contains(service->comment(), queryList)) {
-                return true;
-            }
-
-            return false;
-        };
-
         for (const KService::Ptr &service : m_services) {
-            if (!nameKeywordAndGenericNameFilter(service) || disqualify(service)) {
+            if (disqualify(service)) {
                 continue;
             }
 
-            const QString id = service->storageId();
-            const QString name = service->name();
-
-            KRunner::QueryMatch::CategoryRelevance categoryRelevance = KRunner::QueryMatch::CategoryRelevance::Moderate;
-            qreal relevance(0.6);
-
-            // If the term was < 3 chars and NOT at the beginning of the App's name, then chances are the user doesn't want that app
-            if (weightedTermLength < 3) {
-                if (name.startsWith(query, Qt::CaseInsensitive)) {
-                    relevance = 0.9;
-                } else {
-                    continue;
-                }
-            } else if (name.compare(query, Qt::CaseInsensitive) == 0) {
-                relevance = 1;
-                categoryRelevance = KRunner::QueryMatch::CategoryRelevance::Highest;
-            } else if (const int idx = name.indexOf(queryList[0], 0, Qt::CaseInsensitive); idx != -1) {
-                relevance = 0.8;
-                relevance += increaseMatchRelavance(name, queryList, Category::Name);
-                if (idx == 0) {
-                    relevance += 0.1;
-                    categoryRelevance = KRunner::QueryMatch::CategoryRelevance::High;
-                }
-            } else if (const int idx = service->genericName().indexOf(queryList[0], 0, Qt::CaseInsensitive); idx != -1) {
-                relevance = 0.65;
-                relevance += increaseMatchRelavance(service->genericName(), queryList, Category::GenericName);
-                if (idx == 0) {
-                    relevance += 0.05;
-                }
-            } else if (const int idx = service->comment().indexOf(queryList[0], 0, Qt::CaseInsensitive); idx != -1) {
-                relevance = 0.5;
-                relevance += increaseMatchRelavance(service->comment(), queryList, Category::Comment);
-                if (idx == 0) {
-                    relevance += 0.05;
-                }
-            }
-
             KRunner::QueryMatch match(m_runner);
-            match.setCategoryRelevance(categoryRelevance);
             setupMatch(service, match);
-            if (service->categories().contains(QLatin1String("KDE"))) {
-                qCDebug(RUNNER_SERVICES) << "found a kde thing" << id << match.subtext() << relevance;
-                relevance += .09;
-            }
-
-            if (const auto foundIt = m_runner->m_favourites.constFind(service->desktopEntryName()); foundIt != m_runner->m_favourites.cend()) {
-                if (foundIt->isGlobal || foundIt->linkedActivities.contains(m_currentActivity)) {
-                    qCDebug(RUNNER_SERVICES) << "entry is a favorite" << id << match.subtext() << relevance;
-                    relevance *= 1.25; // Give favorites a relative boost,
-                }
-            }
-
-            qCDebug(RUNNER_SERVICES) << name << "is this relevant:" << relevance;
-            match.setRelevance(relevance);
 
-            matches << match;
-        }
-    }
+            static const qreal nameRelevance = 1;
+            static const qreal genericNameRelevance = 0.9;
+            static const qreal execRelevance = 0.8;
+            static const qreal commentRelevance = 0.7;
 
-    void matchCategories()
-    {
-        // Do not match categories for short queries, BUG: 469769
-        if (weightedTermLength < 5) {
-            return;
-        }
-        for (const KService::Ptr &service : m_services) {
-            const QStringList categories = service->categories();
-            if (disqualify(service) || !contains(categories, queryList)) {
+            if (!acceptMatch(service->name(), query, match, nameRelevance)
+                && !acceptMatch(service->genericName(), query, match, genericNameRelevance)
+                && !acceptMatch(service->untranslatedGenericName(), query, match, genericNameRelevance)
+                && !acceptMatch(service->exec(), query, match, execRelevance)
+                && !acceptMatch(service->comment(), query, match, commentRelevance)) {
                 continue;
             }
-            qCDebug(RUNNER_SERVICES) << service->name() << "is an exact match!" << service->storageId() << service->exec();
 
-            KRunner::QueryMatch match(m_runner);
-            setupMatch(service, match);
-
-            qreal relevance = 0.4;
-            if (std::any_of(categories.begin(), categories.end(), [this](const QString &category) {
-                    return category.compare(query, Qt::CaseInsensitive) == 0;
-                })) {
-                relevance = 0.6;
-            }
-
-            if (service->isApplication()) {
-                relevance += .04;
-            }
-
-            match.setRelevance(relevance);
             matches << match;
         }
     }
 
     void matchJumpListActions()
     {
-        if (weightedTermLength < 3) {
-            return;
-        }
         for (const KService::Ptr &service : m_services) {
             const auto actions = service->actions();
             // Skip SystemSettings as we find KCMs already
@@ -353,22 +270,6 @@ private:
                 }
                 seen(action);
 
-                const int matchIndex = action.text().indexOf(query, 0, Qt::CaseInsensitive);
-                if (matchIndex < 0) {
-                    continue;
-                }
-
-                KRunner::QueryMatch match(m_runner);
-                if (!action.icon().isEmpty()) {
-                    match.setIconName(action.icon());
-                } else {
-                    match.setIconName(service->icon());
-                }
-                match.setText(i18nc("Jump list search result, %1 is action (eg. open new tab), %2 is application (eg. browser)",
-                                    "%1 - %2",
-                                    action.text(),
-                                    service->name()));
-
                 QUrl url(service->storageId());
                 url.setScheme(QStringLiteral("applications"));
 
@@ -376,17 +277,19 @@ private:
                 urlQuery.addQueryItem(QStringLiteral("action"), action.name());
                 url.setQuery(urlQuery);
 
+                KRunner::QueryMatch match(m_runner);
                 match.setData(url);
+                match.setIconName(action.icon().isEmpty() ? service->icon() : action.icon());
+                match.setText(i18nc("Jump list search result, %1 is action (eg. open new tab), %2 is application (eg. browser)",
+                                    "%1 - %2",
+                                    action.text(),
+                                    service->name()));
 
-                qreal relevance = 0.5;
-                if (action.text().compare(query, Qt::CaseInsensitive) == 0) {
-                    relevance = 0.65;
-                    match.setCategoryRelevance(KRunner::QueryMatch::CategoryRelevance::High); // Give it a higer match type to ensure it is shown, BUG: 455436
-                } else if (matchIndex == 0) {
-                    relevance += 0.05;
-                }
+                static const qreal textRelevance = 0.95;
 
-                match.setRelevance(relevance);
+                if (!acceptMatch(action.text(), query, match, textRelevance)) {
+                    continue;
+                }
 
                 matches << match;
             }
openSUSE Build Service is sponsored by