diff options
| author | Ismael Asensio <[email protected]> | 2019-11-15 23:34:13 +0100 |
|---|---|---|
| committer | Ismael Asensio <[email protected]> | 2019-11-28 22:08:13 +0100 |
| commit | 6776fbc94760188daeca0ab30e49f645f225f008 (patch) | |
| tree | ca16e7330b722f6235fadcb38a164a78f6dea22c /src/search/dolphinquery.cpp | |
| parent | 089a05b4edfd7a70e50ed7d8b158cbcc50538d36 (diff) | |
fix(search): Fix baloo searchString parsing
Summary:
Fix the parsing of Baloo query `searchString` to represent its parameters properly
in the search box:
# Baloo terms (`rating`, `modified`) are added to the user search text: {F7575590}
# Extra quotes are added to the search text: https://bugs.kde.org/show_bug.cgi?id=412952
This revision supersedes D24422, by making the fixes on the new dolphin query model,
instead of directly on the UI.
BUG: 412952
FIXED IN: 19.11.90
Test Plan:
- `bin/dolphinquerytest` passes without `XFAIL`s
- Dolphin search box is not garbled by search terms or quotes
Reviewers: elvisangelaccio, bruns, ngraham, #dolphin
Reviewed By: elvisangelaccio
Subscribers: kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D25260
Diffstat (limited to 'src/search/dolphinquery.cpp')
| -rw-r--r-- | src/search/dolphinquery.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/search/dolphinquery.cpp b/src/search/dolphinquery.cpp index 09a841859..8f8cb09ec 100644 --- a/src/search/dolphinquery.cpp +++ b/src/search/dolphinquery.cpp @@ -54,20 +54,38 @@ DolphinQuery DolphinQuery::fromBalooSearchUrl(const QUrl& searchUrl) model.m_includeFolder = query.includeFolder(); - model.m_searchText = query.searchString(); - const QStringList types = query.types(); model.m_fileType = types.isEmpty() ? QString() : types.first(); + QStringList textParts; + const QStringList subTerms = query.searchString().split(' ', QString::SkipEmptyParts); foreach (const QString& subTerm, subTerms) { + QString value; if (subTerm.startsWith(QLatin1String("filename:"))) { - const QString value = subTerm.mid(9); - model.m_searchText = value; + value = subTerm.mid(9); } else if (isSearchTerm(subTerm)) { model.m_searchTerms << subTerm; + continue; + } else if (subTerm == QLatin1String("AND") && subTerm != subTerms.at(0) && subTerm != subTerms.back()) { + continue; + } else { + value = subTerm; + } + + if (!value.isEmpty() && value.at(0) == QLatin1Char('"')) { + value = value.mid(1); + } + if (!value.isEmpty() && value.back() == QLatin1Char('"')) { + value = value.mid(0, value.size() - 1); + } + if (!value.isEmpty()) { + textParts << value; } } + + model.m_searchText = textParts.join(QLatin1Char(' ')); + #endif return model; } |
