From 4ccc4c27f19d692dc626a8effabcaea76e2420ea Mon Sep 17 00:00:00 2001 From: Albert S Date: Sun, 2 Sep 2018 12:38:07 +0200 Subject: [PATCH] default to path search, not content, removed unneeded methods --- gui/searchworker.cpp | 43 ++----------------------------------------- gui/searchworker.h | 4 ---- 2 files changed, 2 insertions(+), 45 deletions(-) diff --git a/gui/searchworker.cpp b/gui/searchworker.cpp index 3bfb37d..bf3b450 100644 --- a/gui/searchworker.cpp +++ b/gui/searchworker.cpp @@ -14,13 +14,6 @@ SearchWorker::SearchWorker(const QString &dbpath) { qDebug() << "failed to open database"; } - queryContent = new QSqlQuery(db); - queryFile = new QSqlQuery(db); - queryFile->prepare("SELECT path, mtime FROM file WHERE path LIKE ? ORDER BY mtime DESC"); - - queryContent->prepare("SELECT file.path, content.page, file.mtime FROM file INNER JOIN content ON file.id = " - "content.fileid INNER JOIN content_fts ON content.id = content_fts.ROWID WHERE " - "content_fts.content MATCH ? ORDER By file.mtime DESC, content.page ASC"); } QVector SearchWorker::tokenize(QString expression) @@ -67,7 +60,7 @@ QVector SearchWorker::tokenize(QString expression) result.append(Command("AND")); } wasbool = false; - result.append(Command("contains", loneword)); + result.append(Command("path.contains", loneword)); } if(filtername != "") { @@ -113,7 +106,7 @@ QString SearchWorker::createSql(const SearchWorker::Command &cmd) { return " content.page = " + value; } - if(key == "contains") + if(key == "contains" || key == "c") { return " ( COALESCE( (SELECT 1 FROM content_fts WHERE content_fts.content MATCH '" + value + "' AND content_fts.ROWID= content.id), 0 ) )"; @@ -132,38 +125,6 @@ QString SearchWorker::makeSql(const QVector &tokens) } return result; } -void SearchWorker::searchForFile(const QString &query) -{ - QVector results; - queryFile->addBindValue("%" + query + "%"); - queryFile->exec(); - while(queryFile->next()) - { - SearchResult result; - result.page = 0; - result.path = queryFile->value(0).toString(); - result.mtime = queryFile->value(1).toUInt(); - - results.append(result); - } - emit searchResultsReady(results); -} -void SearchWorker::searchForContent(const QString &query) -{ - QVector results; - queryContent->addBindValue(query); - queryContent->exec(); - while(queryContent->next()) - { - SearchResult result; - - result.path = queryContent->value(0).toString(); - result.page = queryContent->value(1).toUInt(); - result.mtime = queryContent->value(2).toUInt(); - results.append(result); - } - emit searchResultsReady(results); -} void SearchWorker::search(const QString &query) { diff --git a/gui/searchworker.h b/gui/searchworker.h index 94bed0d..9254d56 100644 --- a/gui/searchworker.h +++ b/gui/searchworker.h @@ -24,8 +24,6 @@ class SearchWorker : public QObject Q_OBJECT private: - QSqlQuery *queryFile; - QSqlQuery *queryContent; QVector tokenize(QString expression); QString createSql(const Command &cmd); QString makeSql(const QVector &tokens); @@ -35,8 +33,6 @@ class SearchWorker : public QObject SearchWorker(); SearchWorker(const QString &dbpath); public slots: - void searchForFile(const QString &query); - void searchForContent(const QString &query); void search(const QString &query); signals: void searchResultsReady(const QVector &results);