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]()
{
SqliteSearch searcher(db);
QVector<SearchResult> results;
this->contentSearchQuery = LooqsQuery::build(q, TokenType::FILTER_CONTENT_CONTAINS, true);
LooqsQuery filesQuery = LooqsQuery::build(q, TokenType::FILTER_PATH_CONTAINS, false);
QVector<SearchResult> 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);