diff --git a/src/search/dolphinquery.h b/src/search/dolphinquery.h --- a/src/search/dolphinquery.h +++ b/src/search/dolphinquery.h @@ -48,13 +48,16 @@ /** @return Baloo::Query::includeFolder(), that is, the initial directory * for the query or an empty string if its a global search" */ QString includeFolder() const; + /** @return whether the query includes search in file content */ + bool isContentSearch() const; private: QUrl m_searchUrl; QString m_searchText; QString m_fileType; QStringList m_searchTerms; QString m_includeFolder; + bool m_hasFileName = false; }; #endif //DOLPHINQUERY_H diff --git a/src/search/dolphinquery.cpp b/src/search/dolphinquery.cpp --- a/src/search/dolphinquery.cpp +++ b/src/search/dolphinquery.cpp @@ -54,20 +54,39 @@ 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); + model.m_hasFileName = true; } 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; } @@ -96,3 +115,8 @@ { return m_includeFolder; } + +bool DolphinQuery::isContentSearch() const +{ + return !m_hasFileName; +} diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -522,6 +522,12 @@ m_facetsWidget->setRatingTerm(searchTerm); } + if (query.isContentSearch()) { + m_contentButton->setChecked(true); + } else { + m_fileNameButton->setChecked(true); + } + m_startSearchTimer->stop(); blockSignals(false); } diff --git a/src/tests/dolphinquerytest.cpp b/src/tests/dolphinquerytest.cpp --- a/src/tests/dolphinquerytest.cpp +++ b/src/tests/dolphinquerytest.cpp @@ -125,24 +125,6 @@ QStringList searchTerms = queryModel.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(queryModel.text(), expectedText);