search: Avoid redundant results by placing pages into vector instead of returning searchresult for each page

Šī revīzija ir iekļauta:
Albert S. 2019-04-26 15:31:42 +02:00
vecāks 7107c90aeb
revīzija 08d81ef78b
5 mainīti faili ar 36 papildinājumiem un 29 dzēšanām

1
TODO
Parādīt failu

@ -1,4 +1,3 @@
Remove redundant searchresult info (redundant filedata (paths etc:))
pdfworker: use qtconcurrent
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

Parādīt failu

@ -105,10 +105,10 @@ void MainWindow::pdfPreviewReceived(PdfPreview preview)
label->setPixmap(QPixmap::fromImage(preview.previewImage));
ui->scrollAreaWidgetContents->layout()->addWidget(label);
ui->pdfProcessBar->setValue(++processedPdfPreviews);
connect(label, &ClickLabel::clicked, [=]() {
QSettings settings;
QString command = settings.value("pdfviewer").toString();
qDebug() << command;
if(command != "" && command.contains("%p") && command.contains("%f"))
{
command = command.replace("%f", preview.documentPath);
@ -146,10 +146,7 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
this->pdfSearchResults.clear();
ui->treeResultsList->clear();
ui->lblSearchResults->setText("Results: " + QString::number(results.size()));
QString lastpath = "";
for(const SearchResult &result : results)
{
if(lastpath != result.fileData.absPath)
{
QFileInfo pathInfo(result.fileData.absPath);
QString fileName =pathInfo.fileName();
@ -160,7 +157,6 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
item->setText(0, fileName);
item->setText(1, result.fileData.absPath);
item->setText(2, dt.toString(Qt::ISODate));
}
//TODO: this must be user defined or done more intelligently
if(this->pdfSearchResults.size() < 300)
@ -170,7 +166,6 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
this->pdfSearchResults.append(result);
}
}
lastpath = result.fileData.absPath;
}
ui->treeResultsList->resizeColumnToContents(0);
ui->treeResultsList->resizeColumnToContents(1);

Parādīt failu

@ -2,6 +2,7 @@
#include <QApplication>
#include <QScreen>
#include <QDebug>
#include <QScopedPointer>
#include "pdfworker.h"
PdfWorker::PdfWorker()
@ -42,18 +43,22 @@ void PdfWorker::generatePreviews(QVector<SearchResult> paths, double scalefactor
{
continue;
}
int p = (int)sr.page - 1;
for(unsigned int page : sr.pages)
{
int p = (int)page - 1;
if(p < 0)
p = 0;
Poppler::Page *pdfpage = doc->page(p);
QImage image = pdfpage->renderToImage(QGuiApplication::primaryScreen()->physicalDotsPerInchX() * scalefactor, QGuiApplication::primaryScreen()->physicalDotsPerInchY() *scalefactor);
Poppler::Page *pdfPage = doc->page(p);
QImage image = pdfPage->renderToImage(QGuiApplication::primaryScreen()->physicalDotsPerInchX() * scalefactor, QGuiApplication::primaryScreen()->physicalDotsPerInchY() *scalefactor);
PdfPreview preview;
preview.previewImage = image;
preview.documentPath = sr.fileData.absPath;
preview.page = sr.page;
preview.page = page;
emit previewReady(preview);
}
}
isFreeMutex.lock();
isFree.wakeOne();
isFreeMutex.unlock();

Parādīt failu

@ -6,7 +6,7 @@ class SearchResult
{
public:
FileData fileData;
unsigned int page;
QVector<unsigned int> pages;
};

Parādīt failu

@ -227,11 +227,11 @@ QSqlQuery SqliteSearch::makeSqlQuery(const QVector<SqliteSearch::Token> &tokens)
QString prepSql;
if(isContentSearch)
{
prepSql = "SELECT file.path AS path, content.page AS page, file.mtime AS mtime, file.size AS size, file.filetype AS filetype FROM file INNER JOIN content ON file.id = content.fileid WHERE 1=1 AND " + whereSql + " " + sortSql;
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 WHERE 1=1 AND " + whereSql + " " + sortSql + " GROUP BY file.path";
}
else
{
prepSql = "SELECT file.path AS path, 0 as page, file.mtime AS mtime, file.size AS size, file.filetype AS filetype FROM file WHERE 1=1 AND " + whereSql + " " + sortSql;
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 " + whereSql + " " + sortSql;
}
QSqlQuery dbquery(*db);
@ -268,7 +268,15 @@ QVector<SearchResult> SqliteSearch::search(const QString &query)
result.fileData.mtime = dbQuery.value("mtime").toUInt();
result.fileData.size = dbQuery.value("size").toUInt();
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);
}
return results;