MainWindow: Avoid potential double path searches

This commit is contained in:
Albert S. 2022-01-04 11:18:53 +01:00
parent c0657947b1
commit b10c2edf05

View File

@ -164,12 +164,22 @@ void MainWindow::lineEditReturnPressed()
[&, q]() [&, q]()
{ {
SqliteSearch searcher(db); SqliteSearch searcher(db);
QVector<SearchResult> results;
this->contentSearchQuery = LooqsQuery::build(q, TokenType::FILTER_CONTENT_CONTAINS, true); this->contentSearchQuery = LooqsQuery::build(q, TokenType::FILTER_CONTENT_CONTAINS, true);
/* 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); LooqsQuery filesQuery = LooqsQuery::build(q, TokenType::FILTER_PATH_CONTAINS, false);
QVector<SearchResult> results;
results.append(searcher.search(filesQuery)); results.append(searcher.search(filesQuery));
}
if(addContentSearch)
{
results.append(searcher.search(this->contentSearchQuery)); results.append(searcher.search(this->contentSearchQuery));
}
return results; return results;
}); });
searchWatcher.setFuture(searchFuture); searchWatcher.setFuture(searchFuture);