Skip to content

Commit

Permalink
Improve package search
Browse files Browse the repository at this point in the history
Contributes-To: sailfishos-chum#88
  • Loading branch information
nephros committed Apr 27, 2024
1 parent 9c3ad4b commit 0cb259d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/chumpackagesmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "chum.h"

#include <QDebug>
#include <QRegularExpression>

#include <algorithm>

Expand Down Expand Up @@ -90,14 +91,18 @@ void ChumPackagesModel::reset() {
if (!m_search.isEmpty()) {
bool found = true;
QStringList lines{ p->name(),
p->summary(),
p->categories().join(' '),
p->developer(),
p->description() };
p->developer() };
QString txt = lines.join('\n').normalized(QString::NormalizationForm_KC).toLower();
for (QString query: m_search.split(' ', QString::SkipEmptyParts)) {
query = query.normalized(QString::NormalizationForm_KC).toLower();
found = found && txt.contains(query);
QRegularExpression re( "(\\b" + query + "|" + query + "\\b)",
QRegularExpression::CaseInsensitiveOption |
QRegularExpression::MultilineOption );
found = found && (
txt.contains(re)
|| p->summary().contains(query)
|| p->description().contains(query) );
}
if (!found) continue;
}
Expand Down

0 comments on commit 0cb259d

Please sign in to comment.