Commit 55a8d72e authored by Xuetian Weng's avatar Xuetian Weng

Use heuristic weighted length algorithm to calculate the query term length.

Summary:
Composing CJK character requires a lot more key comparing to latin
characters. The raw length check does not make much sense for query string
in CJK characters. Here we use a simple algorithm to query the character
script property in unicode. If they are belong to CJK, use length 2 instead
of 1 for the character.

Test Plan:
Search "系" (normally requires three key press "x + i + 1" under pinyin) under
zh_CN in krunner and get some result instead of nothing.

Reviewers: hein, broulik

Reviewed By: hein

Subscribers: cfeck, ihipop, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D8771
parent b40c0de0
......@@ -27,7 +27,7 @@ include(KDEPackageAppTemplates)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
Plasma DocTools Runner JsEmbed NotifyConfig Su NewStuff Wallet KCMUtils
IdleTime Declarative TextWidgets KDELibs4Support Crash GlobalAccel
DBusAddons Wayland)
DBusAddons Wayland CoreAddons)
find_package(KF5NetworkManagerQt ${KF5_MIN_VERSION})
set_package_properties(KF5NetworkManagerQt PROPERTIES DESCRIPTION "Qt wrapper for NetworkManager API"
TYPE OPTIONAL
......
......@@ -12,6 +12,7 @@ ecm_qt_declare_logging_category(krunner_services_SRCS
add_library(krunner_services MODULE ${krunner_services_SRCS})
target_link_libraries(krunner_services
KF5::CoreAddons
KF5::KIOWidgets
KF5::I18n
KF5::Runner
......@@ -21,6 +22,7 @@ target_link_libraries(krunner_services
add_library(krunner_services_test STATIC ${krunner_services_SRCS})
target_link_libraries(krunner_services_test
KF5::CoreAddons
KF5::KIOWidgets
KF5::I18n
KF5::Runner
......
......@@ -31,9 +31,25 @@
#include <KRun>
#include <KService>
#include <KServiceTypeTrader>
#include <kcoreaddons_version.h>
#if KCOREADDONS_VERSION >= QT_VERSION_CHECK(5, 41, 0)
#include <KStringHandler>
#endif
#include "debug.h"
namespace {
int weightedLength(const QString &query) {
#if KCOREADDONS_VERSION >= QT_VERSION_CHECK(5, 41, 0)
return KStringHandler::logicalLength(query);
#else
return query.length();
#endif
}
} // namespace
/**
* @brief Finds all KServices for a given runner query
*/
......@@ -52,6 +68,7 @@ public:
}
term = context.query();
weightedTermLength = weightedLength(term);
matchExectuables();
matchNameKeywordAndGenericName();
......@@ -170,7 +187,7 @@ private:
void matchExectuables()
{
if (term.length() < 2) {
if (weightedTermLength < 2) {
return;
}
......@@ -203,7 +220,7 @@ private:
QVector<QStringRef> 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 +247,7 @@ private:
// 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 +347,7 @@ private:
void matchJumpListActions()
{
if (term.length() < 3) {
if (weightedTermLength < 3) {
return;
}
......@@ -382,6 +399,7 @@ private:
QList<Plasma::QueryMatch> matches;
QString query;
QString term;
int weightedTermLength;
};
ServiceRunner::ServiceRunner(QObject *parent, const QVariantList &args)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment