From eef0fae13723bef1a6a15246b034fbc1ac23c621 Mon Sep 17 00:00:00 2001 From: Albert S Date: Tue, 23 Aug 2022 23:30:10 +0200 Subject: [PATCH] shared,gui,cli: Fix intra-file ordering for content search results group_concat() does not preserve order of the ORDRE BY rank, making the ordering quite meaningless for pages inside a file. The recently introduced combobox to filter on a per file basis should anyway be prefered than any kind of grouping in queries. So we just remove the groupings here. "All files" in the previews tab thus should show the best results first now, from any files part of the result set. A GUI option to sort by page instead of rank can be considered. --- cli/commandsearch.cpp | 11 +++++++++-- gui/mainwindow.cpp | 25 ++++++++++++++++--------- shared/sqlitesearch.cpp | 7 +++---- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/cli/commandsearch.cpp b/cli/commandsearch.cpp index 247c38a..2877797 100644 --- a/cli/commandsearch.cpp +++ b/cli/commandsearch.cpp @@ -33,11 +33,18 @@ int CommandSearch::handle(QStringList arguments) try { + + QHash seenMap; auto results = dbService->search(query); - for(SearchResult &result : results) + for(const SearchResult &result : results) { - Logger::info() << result.fileData.absPath << Qt::endl; + const QString &absPath = result.fileData.absPath; + if(!seenMap.contains(absPath)) + { + seenMap[absPath] = true; + Logger::info() << absPath << Qt::endl; + } } } catch(LooqsGeneralException &e) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 0aed105..a4c3353 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -808,19 +808,25 @@ void MainWindow::handleSearchResults(const QVector &results) ui->comboPreviewFiles->setVisible(true); bool hasDeleted = false; + QHash seenMap; for(const SearchResult &result : results) { - QFileInfo pathInfo(result.fileData.absPath); + const QString &absPath = result.fileData.absPath; + QFileInfo pathInfo(absPath); - QString fileName = pathInfo.fileName(); - QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeResultsList); + if(!seenMap.contains(absPath)) + { + seenMap[absPath] = true; + QString fileName = pathInfo.fileName(); + QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeResultsList); - QDateTime dt = QDateTime::fromSecsSinceEpoch(result.fileData.mtime); - item->setIcon(0, iconProvider.icon(pathInfo)); - item->setText(0, fileName); - item->setText(1, result.fileData.absPath); - item->setText(2, dt.toString(Qt::ISODate)); - item->setText(3, this->locale().formattedDataSize(result.fileData.size)); + QDateTime dt = QDateTime::fromSecsSinceEpoch(result.fileData.mtime); + item->setIcon(0, iconProvider.icon(pathInfo)); + item->setText(0, fileName); + item->setText(1, absPath); + item->setText(2, dt.toString(Qt::ISODate)); + item->setText(3, this->locale().formattedDataSize(result.fileData.size)); + } bool exists = pathInfo.exists(); if(exists) { @@ -843,6 +849,7 @@ void MainWindow::handleSearchResults(const QVector &results) hasDeleted = true; } } + ui->treeResultsList->resizeColumnToContents(0); ui->treeResultsList->resizeColumnToContents(1); ui->treeResultsList->resizeColumnToContents(2); diff --git a/shared/sqlitesearch.cpp b/shared/sqlitesearch.cpp index 83efde9..0319217 100644 --- a/shared/sqlitesearch.cpp +++ b/shared/sqlitesearch.cpp @@ -194,10 +194,9 @@ QSqlQuery SqliteSearch::makeSqlQuery(const LooqsQuery &query) sortSql = "ORDER BY rank"; } } - prepSql = - "SELECT file.path AS path, group_concat(content.page) AS pages, file.mtime AS mtime, file.size AS size, " - "file.filetype AS filetype FROM file INNER JOIN content ON file.id = content.fileid " + - joinSql + " WHERE 1=1 AND " + whereSql + " GROUP BY file.path " + sortSql; + prepSql = "SELECT file.path AS path, content.page AS pages, file.mtime AS mtime, file.size AS size, " + "file.filetype AS filetype FROM file INNER JOIN content ON file.id = content.fileid " + + joinSql + " WHERE 1=1 AND " + whereSql + " " + sortSql; } else {