]> cloud.milkyroute.net Git - dolphin.git/commitdiff
fix(search): Fix baloo searchString parsing
authorIsmael Asensio <isma.af@gmail.com>
Fri, 15 Nov 2019 22:34:13 +0000 (23:34 +0100)
committerIsmael Asensio <isma.af@gmail.com>
Thu, 28 Nov 2019 21:08:13 +0000 (22:08 +0100)
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

src/search/dolphinquery.cpp
src/tests/dolphinquerytest.cpp

index 09a841859188cd18a219329d95d7cbde32b2ec50..8f8cb09ec121c96e52cff9aa4333d7430bb5fb99 100644 (file)
@@ -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;
 }
index 14eb03620cc71e27772dbc17dd403095b26184b3..1c6b39e267a5391f58d7ae604a50f4ef84eb4cb6 100644 (file)
@@ -114,24 +114,6 @@ void DolphinSearchBoxTest::testBalooSearchParsing()
     QStringList searchTerms = query.searchTerms();
     searchTerms.sort();
 
-    // FIXME: Current parsing bugs
-    QEXPECT_FAIL("content/singleQuote", "Quotes around text are shown", Continue);
-    QEXPECT_FAIL("content/doubleQuote", "Quotes around text are shown", Continue);
-
-    QEXPECT_FAIL("filename",             "Quotes around text are shown", Continue);
-    QEXPECT_FAIL("filename/singleQuote", "Quotes around text are shown", Continue);
-    QEXPECT_FAIL("filename/doubleQuote", "Quotes around text are shown", Continue);
-
-    QEXPECT_FAIL("rating"                  , "Text includes also search terms", Continue);
-    QEXPECT_FAIL("rating+content"          , "Text includes also search terms", Continue);
-    QEXPECT_FAIL("rating+filename"         , "Text includes also search terms", Continue);
-    QEXPECT_FAIL("modified"                , "Text includes also search terms", Continue);
-    QEXPECT_FAIL("modified+content"        , "Text includes also search terms", Continue);
-    QEXPECT_FAIL("modified+filename"       , "Text includes also search terms", Continue);
-    QEXPECT_FAIL("rating+modified"         , "Text includes also search terms", Continue);
-    QEXPECT_FAIL("rating+modified+content" , "Text includes also search terms", Continue);
-    QEXPECT_FAIL("rating+modified+filename", "Text includes also search terms", Continue);
-
     // Check for parsed text (would be displayed on the input search bar)
     QCOMPARE(query.text(), expectedText);