From b10c2edf05315cf66c8505180310b20da4e003ac Mon Sep 17 00:00:00 2001 From: Albert S Date: Tue, 4 Jan 2022 11:18:53 +0100 Subject: [PATCH] MainWindow: Avoid potential double path searches --- gui/mainwindow.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 6ddbdad..88171e6 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -164,12 +164,22 @@ void MainWindow::lineEditReturnPressed() [&, q]() { SqliteSearch searcher(db); + QVector results; this->contentSearchQuery = LooqsQuery::build(q, TokenType::FILTER_CONTENT_CONTAINS, true); - LooqsQuery filesQuery = LooqsQuery::build(q, TokenType::FILTER_PATH_CONTAINS, false); - QVector results; - results.append(searcher.search(filesQuery)); - results.append(searcher.search(this->contentSearchQuery)); + /* We can have a path search in contentsearch too (if given explicitly), so no need to do it twice. + Make sure path results are listed first. */ + bool addContentSearch = this->contentSearchQuery.hasContentSearch(); + bool addPathSearch = !this->contentSearchQuery.hasPathSearch() || !addContentSearch; + if(addPathSearch) + { + LooqsQuery filesQuery = LooqsQuery::build(q, TokenType::FILTER_PATH_CONTAINS, false); + results.append(searcher.search(filesQuery)); + } + if(addContentSearch) + { + results.append(searcher.search(this->contentSearchQuery)); + } return results; }); searchWatcher.setFuture(searchFuture);