From 984c20161bc71684325a1394cfbb292683c94d53 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Thu, 10 Mar 2011 23:17:55 +0100 Subject: Add search modes for the Search Panel The search panel must get a hint whether clicking on the facets should result in searching everywhere or from the current folder. It is not sufficient to check the search-settings of the "Find:"-box, as when the "Find:"-box is invisible there is no hint for the user what kind of searching is done and the setting must be ignored. --- src/search/dolphinsearchbox.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src/search/dolphinsearchbox.cpp') diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp index 8119e821f..17a691e44 100644 --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -42,9 +42,9 @@ #include #ifdef HAVE_NEPOMUK - #include #include #include + #include #include #include #include @@ -349,28 +349,31 @@ void DolphinSearchBox::init() KUrl DolphinSearchBox::nepomukUrlForSearching() const { #ifdef HAVE_NEPOMUK - Nepomuk::Query::AndTerm andTerm; + Nepomuk::Query::OrTerm orTerm; const QString text = m_searchInput->text(); - if (m_fileNameButton->isChecked()) { - QString regex = QRegExp::escape(text); - regex.replace("\\*", QLatin1String(".*")); - regex.replace("\\?", QLatin1String(".")); - regex.replace("\\", "\\\\"); - andTerm.addSubTerm(Nepomuk::Query::ComparisonTerm( - Nepomuk::Vocabulary::NFO::fileName(), - Nepomuk::Query::LiteralTerm(regex), - Nepomuk::Query::ComparisonTerm::Regexp)); - } else { + + // Search the text in the filename in any case + QString regex = QRegExp::escape(text); + regex.replace("\\*", QLatin1String(".*")); + regex.replace("\\?", QLatin1String(".")); + regex.replace("\\", "\\\\"); + orTerm.addSubTerm(Nepomuk::Query::ComparisonTerm( + Nepomuk::Vocabulary::NFO::fileName(), + Nepomuk::Query::LiteralTerm(regex), + Nepomuk::Query::ComparisonTerm::Regexp)); + + if (m_contentButton->isChecked()) { + // Search the text also in the content of the files const Nepomuk::Query::Query customQuery = Nepomuk::Query::QueryParser::parseQuery(text, Nepomuk::Query::QueryParser::DetectFilenamePattern); if (customQuery.isValid()) { - andTerm.addSubTerm(customQuery.term()); + orTerm.addSubTerm(customQuery.term()); } } Nepomuk::Query::FileQuery fileQuery; fileQuery.setFileMode(Nepomuk::Query::FileQuery::QueryFilesAndFolders); - fileQuery.setTerm(andTerm); + fileQuery.setTerm(orTerm); if (m_fromHereButton->isChecked()) { const bool recursive = true; fileQuery.addIncludeFolder(m_searchPath, recursive); -- cgit v1.3