Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
Plasma Add-ons
Commits
728c2c6e
Commit
728c2c6e
authored
Feb 12, 2022
by
Waqar Ahmed
Browse files
kate session runner: Fuzzy match the query when we don't have exact match
parent
727cded8
Pipeline
#136521
passed with stage
in 4 minutes and 49 seconds
Changes
1
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
runners/katesessions/katesessions.cpp
View file @
728c2c6e
...
...
@@ -14,6 +14,7 @@
#include
<QStandardPaths>
#include
<KDirWatch>
#include
<KFuzzyMatcher>
#include
<KLocalizedString>
#include
<KNotificationJobUiDelegate>
...
...
@@ -73,8 +74,13 @@ void KateSessions::match(RunnerContext &context)
return
;
}
QList
<
QueryMatch
>
matches
;
int
maxScore
=
0
;
for
(
const
QString
&
session
:
std
::
as_const
(
sessions
))
{
if
(
listAll
||
session
.
contains
(
term
,
Qt
::
CaseInsensitive
))
{
// Does the query match exactly?
// no query = perfect match => list everything
if
(
listAll
||
session
.
compare
(
term
,
Qt
::
CaseInsensitive
)
==
0
)
{
QueryMatch
match
(
this
);
match
.
setType
(
QueryMatch
::
ExactMatch
);
match
.
setRelevance
(
session
.
compare
(
term
,
Qt
::
CaseInsensitive
)
==
0
?
1
:
0.8
);
...
...
@@ -83,8 +89,29 @@ void KateSessions::match(RunnerContext &context)
match
.
setText
(
session
);
match
.
setSubtext
(
i18n
(
"Open Kate Session"
));
context
.
addMatch
(
match
);
}
else
{
// Do fuzzy matching
const
auto
res
=
KFuzzyMatcher
::
match
(
term
,
session
);
if
(
res
.
matched
)
{
QueryMatch
match
(
this
);
match
.
setRelevance
(
res
.
score
);
// store the score here for now
match
.
setIconName
(
m_triggerWord
);
match
.
setData
(
session
);
match
.
setText
(
session
);
match
.
setSubtext
(
i18n
(
"Open Kate Session"
));
matches
.
push_back
(
match
);
maxScore
=
std
::
max
(
res
.
score
,
maxScore
);
}
}
}
auto
calculate_relevance
=
[
maxScore
](
double
score
)
{
return
score
/
maxScore
;
};
for
(
auto
&
match
:
matches
)
{
match
.
setRelevance
(
calculate_relevance
(
match
.
relevance
()));
}
context
.
addMatches
(
matches
);
}
void
KateSessions
::
run
(
const
RunnerContext
&
context
,
const
QueryMatch
&
match
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment