Commit 6a308a6a authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Remove check if result conains query string

This essentially overrides the runner relevance and match type.

An example is my custom runner for the nordvpn cli, having the query string in the
result text would be unneeded, because one already has the category set.

This is also a perquisite for https://bugs.kde.org/show_bug.cgi?id=340283

Before:
https://phabricator.kde.org/file/data/jjdng2qroopr5w6sv2mq/PHID-FILE-yvv5nhamspryvbbkfwd4/Screenshot_20220508_130532.png

After:
https://phabricator.kde.org/file/data/lop7apvdb2tn276ngk5k/PHID-FILE-2yxwbxbayxkn54rtlzth/Screenshot_20220508_130702.png
parent 19dc0f02
Pipeline #189074 passed with stage
in 52 seconds
......@@ -48,40 +48,9 @@ public:
}
}
bool categoryHasMatchWithAllWords(const QModelIndex &categoryIdx) const
{
for (int i = 0; i < sourceModel()->rowCount(categoryIdx); ++i) {
const QModelIndex idx = sourceModel()->index(i, 0, categoryIdx);
const QString display = idx.data(Qt::DisplayRole).toString();
bool containsAllWords = true;
for (const QString &word : m_words) {
if (!display.contains(word, Qt::CaseInsensitive)) {
containsAllWords = false;
}
}
if (containsAllWords) {
return true;
}
}
return false;
}
protected:
bool lessThan(const QModelIndex &sourceA, const QModelIndex &sourceB) const override
{
// prefer categories that have a match containing the query string in the display role
if (!sourceA.parent().isValid() && !sourceB.parent().isValid()) {
const bool hasMatchWithAllWordsA = categoryHasMatchWithAllWords(sourceA);
const bool hasMatchWithAllWordsB = categoryHasMatchWithAllWords(sourceB);
if (hasMatchWithAllWordsA != hasMatchWithAllWordsB) {
return !hasMatchWithAllWordsA && hasMatchWithAllWordsB;
}
}
const int typeA = sourceA.data(ResultsModel::TypeRole).toInt();
const int typeB = sourceB.data(ResultsModel::TypeRole).toInt();
......
Supports Markdown
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