From 46f51b9554d4534b94ea600b135ff29edb19b159 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 | 41 ++--------------------------------------- gui/searchworker.h | 4 ---- 2 files changed, 2 insertions(+), 43 deletions(-) diff --git a/gui/searchworker.cpp b/gui/searchworker.cpp index 2ea03c8..6a503ff 100644 --- a/gui/searchworker.cpp +++ b/gui/searchworker.cpp @@ -15,11 +15,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) @@ -66,7 +61,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 != "") { @@ -114,7 +109,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 +127,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 e0f021b..3a77d01 100644 --- a/gui/searchworker.h +++ b/gui/searchworker.h @@ -26,8 +26,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); @@ -36,8 +34,6 @@ public: 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);