diff --git a/runners/services/servicerunner.cpp b/runners/services/servicerunner.cpp --- a/runners/services/servicerunner.cpp +++ b/runners/services/servicerunner.cpp @@ -34,6 +34,29 @@ #include "debug.h" +namespace { + +int weightedLength(const QString &query) { + int length = 0; + auto chrs = query.toUcs4(); + for (auto chr : chrs) { + auto script = QChar::script(chr); + if (script == QChar::Script_Han || + script == QChar::Script_Hangul || + script == QChar::Script_Hiragana || + script == QChar::Script_Katakana || + script == QChar::Script_Yi || + QChar::isHighSurrogate(chr)) { + length += 2; + } else { + length += 1; + } + } + return length; +} + +} // namespace + /** * @brief Finds all KServices for a given runner query */ @@ -52,6 +75,7 @@ } term = context.query(); + weightedTermLength = weightedLength(term); matchExectuables(); matchNameKeywordAndGenericName(); @@ -170,7 +194,7 @@ void matchExectuables() { - if (term.length() < 2) { + if (weightedTermLength < 2) { return; } @@ -203,7 +227,7 @@ QVector queryList = term.splitRef(QLatin1Char(' ')); // If the term length is < 3, no real point searching the Keywords and GenericName - if (term.length() < 3) { + if (weightedTermLength < 3) { query = QStringLiteral("exist Exec and ( (exist Name and '%1' ~~ Name) or ('%1' ~~ Exec) )").arg(term); } else { //Match using subsequences (Bug: 262837) @@ -230,7 +254,7 @@ // If the term was < 3 chars and NOT at the beginning of the App's name or Exec, then // chances are the user doesn't want that app. - if (term.length() < 3) { + if (weightedTermLength < 3) { if (name.startsWith(term) || exec.startsWith(term)) { relevance = 0.9; } else { @@ -330,7 +354,7 @@ void matchJumpListActions() { - if (term.length() < 3) { + if (weightedTermLength < 3) { return; } @@ -382,6 +406,7 @@ QList matches; QString query; QString term; + int weightedTermLength; }; ServiceRunner::ServiceRunner(QObject *parent, const QVariantList &args)