search: Avoid redundant results by placing pages into vector instead of returning searchresult for each page
Tento commit je obsažen v:
rodič
950749e1e4
revize
8c027566e3
1
TODO
1
TODO
@ -1,4 +1,3 @@
|
|||||||
Remove redundant searchresult info (redundant filedata (paths etc:))
|
|
||||||
pdfworker: use qtconcurrent
|
pdfworker: use qtconcurrent
|
||||||
Consider injecting Logger (default stdout/stderr) to classes instead of using Logger::info()/Logger::error()::
|
Consider injecting Logger (default stdout/stderr) to classes instead of using Logger::info()/Logger::error()::
|
||||||
sync/share GUI and CLI data-structures. Better to share codebase in general
|
sync/share GUI and CLI data-structures. Better to share codebase in general
|
||||||
|
@ -106,12 +106,12 @@ void MainWindow::pdfPreviewReceived(PdfPreview preview)
|
|||||||
label->setPixmap(QPixmap::fromImage(preview.previewImage));
|
label->setPixmap(QPixmap::fromImage(preview.previewImage));
|
||||||
ui->scrollAreaWidgetContents->layout()->addWidget(label);
|
ui->scrollAreaWidgetContents->layout()->addWidget(label);
|
||||||
ui->pdfProcessBar->setValue(++processedPdfPreviews);
|
ui->pdfProcessBar->setValue(++processedPdfPreviews);
|
||||||
|
|
||||||
connect(label, &ClickLabel::clicked,
|
connect(label, &ClickLabel::clicked,
|
||||||
[=]()
|
[=]()
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
QString command = settings.value("pdfviewer").toString();
|
QString command = settings.value("pdfviewer").toString();
|
||||||
qDebug() << command;
|
|
||||||
if(command != "" && command.contains("%p") && command.contains("%f"))
|
if(command != "" && command.contains("%p") && command.contains("%f"))
|
||||||
{
|
{
|
||||||
command = command.replace("%f", preview.documentPath);
|
command = command.replace("%f", preview.documentPath);
|
||||||
@ -149,21 +149,17 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
|
|||||||
this->pdfSearchResults.clear();
|
this->pdfSearchResults.clear();
|
||||||
ui->treeResultsList->clear();
|
ui->treeResultsList->clear();
|
||||||
ui->lblSearchResults->setText("Results: " + QString::number(results.size()));
|
ui->lblSearchResults->setText("Results: " + QString::number(results.size()));
|
||||||
QString lastpath = "";
|
|
||||||
for(const SearchResult &result : results)
|
for(const SearchResult &result : results)
|
||||||
{
|
{
|
||||||
if(lastpath != result.fileData.absPath)
|
QFileInfo pathInfo(result.fileData.absPath);
|
||||||
{
|
QString fileName = pathInfo.fileName();
|
||||||
QFileInfo pathInfo(result.fileData.absPath);
|
QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeResultsList);
|
||||||
QString fileName = pathInfo.fileName();
|
|
||||||
QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeResultsList);
|
|
||||||
|
|
||||||
QDateTime dt = QDateTime::fromSecsSinceEpoch(result.fileData.mtime);
|
QDateTime dt = QDateTime::fromSecsSinceEpoch(result.fileData.mtime);
|
||||||
item->setIcon(0, iconProvider.icon(pathInfo));
|
item->setIcon(0, iconProvider.icon(pathInfo));
|
||||||
item->setText(0, fileName);
|
item->setText(0, fileName);
|
||||||
item->setText(1, result.fileData.absPath);
|
item->setText(1, result.fileData.absPath);
|
||||||
item->setText(2, dt.toString(Qt::ISODate));
|
item->setText(2, dt.toString(Qt::ISODate));
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: this must be user defined or done more intelligently
|
// TODO: this must be user defined or done more intelligently
|
||||||
if(this->pdfSearchResults.size() < 300)
|
if(this->pdfSearchResults.size() < 300)
|
||||||
@ -173,7 +169,6 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
|
|||||||
this->pdfSearchResults.append(result);
|
this->pdfSearchResults.append(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastpath = result.fileData.absPath;
|
|
||||||
}
|
}
|
||||||
ui->treeResultsList->resizeColumnToContents(0);
|
ui->treeResultsList->resizeColumnToContents(0);
|
||||||
ui->treeResultsList->resizeColumnToContents(1);
|
ui->treeResultsList->resizeColumnToContents(1);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QScopedPointer>
|
||||||
#include "pdfworker.h"
|
#include "pdfworker.h"
|
||||||
|
|
||||||
PdfWorker::PdfWorker()
|
PdfWorker::PdfWorker()
|
||||||
@ -41,18 +42,22 @@ void PdfWorker::generatePreviews(QVector<SearchResult> paths, double scalefactor
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int p = (int)sr.page - 1;
|
for(unsigned int page : sr.pages)
|
||||||
if(p < 0)
|
{
|
||||||
p = 0;
|
int p = (int)page - 1;
|
||||||
Poppler::Page *pdfpage = doc->page(p);
|
if(p < 0)
|
||||||
QImage image = pdfpage->renderToImage(QGuiApplication::primaryScreen()->physicalDotsPerInchX() * scalefactor,
|
p = 0;
|
||||||
QGuiApplication::primaryScreen()->physicalDotsPerInchY() * scalefactor);
|
Poppler::Page *pdfPage = doc->page(p);
|
||||||
|
QImage image =
|
||||||
|
pdfPage->renderToImage(QGuiApplication::primaryScreen()->physicalDotsPerInchX() * scalefactor,
|
||||||
|
QGuiApplication::primaryScreen()->physicalDotsPerInchY() * scalefactor);
|
||||||
|
|
||||||
PdfPreview preview;
|
PdfPreview preview;
|
||||||
preview.previewImage = image;
|
preview.previewImage = image;
|
||||||
preview.documentPath = sr.fileData.absPath;
|
preview.documentPath = sr.fileData.absPath;
|
||||||
preview.page = sr.page;
|
preview.page = page;
|
||||||
emit previewReady(preview);
|
emit previewReady(preview);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
isFreeMutex.lock();
|
isFreeMutex.lock();
|
||||||
isFree.wakeOne();
|
isFree.wakeOne();
|
||||||
|
@ -6,7 +6,7 @@ class SearchResult
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileData fileData;
|
FileData fileData;
|
||||||
unsigned int page;
|
QVector<unsigned int> pages;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SEARCHRESULT_H
|
#endif // SEARCHRESULT_H
|
||||||
|
@ -223,13 +223,14 @@ QSqlQuery SqliteSearch::makeSqlQuery(const QVector<SqliteSearch::Token> &tokens)
|
|||||||
QString prepSql;
|
QString prepSql;
|
||||||
if(isContentSearch)
|
if(isContentSearch)
|
||||||
{
|
{
|
||||||
prepSql = "SELECT file.path AS path, content.page AS page, file.mtime AS mtime, file.size AS size, "
|
prepSql =
|
||||||
"file.filetype AS filetype FROM file INNER JOIN content ON file.id = content.fileid WHERE 1=1 AND " +
|
"SELECT file.path AS path, group_concat(content.page) AS pages, file.mtime AS mtime, file.size AS size, "
|
||||||
whereSql + " " + sortSql;
|
"file.filetype AS filetype FROM file INNER JOIN content ON file.id = content.fileid WHERE 1=1 AND " +
|
||||||
|
whereSql + " " + sortSql + " GROUP BY file.path";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
prepSql = "SELECT file.path AS path, 0 as page, file.mtime AS mtime, file.size AS size, file.filetype AS "
|
prepSql = "SELECT file.path AS path, '0' as pages, file.mtime AS mtime, file.size AS size, file.filetype AS "
|
||||||
"filetype FROM file WHERE 1=1 AND " +
|
"filetype FROM file WHERE 1=1 AND " +
|
||||||
whereSql + " " + sortSql;
|
whereSql + " " + sortSql;
|
||||||
}
|
}
|
||||||
@ -266,7 +267,15 @@ QVector<SearchResult> SqliteSearch::search(const QString &query)
|
|||||||
result.fileData.mtime = dbQuery.value("mtime").toUInt();
|
result.fileData.mtime = dbQuery.value("mtime").toUInt();
|
||||||
result.fileData.size = dbQuery.value("size").toUInt();
|
result.fileData.size = dbQuery.value("size").toUInt();
|
||||||
result.fileData.filetype = dbQuery.value("filetype").toChar();
|
result.fileData.filetype = dbQuery.value("filetype").toChar();
|
||||||
result.page = dbQuery.value("page").toUInt();
|
QString pages = dbQuery.value("pages").toString();
|
||||||
|
QStringList pagesList = pages.split(",");
|
||||||
|
for(QString &page : pagesList)
|
||||||
|
{
|
||||||
|
if(page != "")
|
||||||
|
{
|
||||||
|
result.pages.append(page.toUInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
results.append(result);
|
results.append(result);
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
|
Načítá se…
x
Odkázat v novém úkolu
Zablokovat Uživatele