From 8e3585df3811ec704bfa036e74486b78afb1f653 Mon Sep 17 00:00:00 2001 From: Albert S Date: Sat, 6 Apr 2019 17:13:38 +0200 Subject: [PATCH] Query/Save filetype and size --- create.sql | 7 +++---- gui/searchresult.h | 2 ++ gui/searchworker.cpp | 12 ++++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/create.sql b/create.sql index a55b472..609cb16 100644 --- a/create.sql +++ b/create.sql @@ -1,8 +1,7 @@ -CREATE TABLE file(id INTEGER PRIMARY KEY, path varchar(4096) UNIQUE, mtime integer); +CREATE TABLE file(id INTEGER PRIMARY KEY, path varchar(4096) UNIQUE, mtime integer, size integer, filetype char(1)); CREATE TABLE content(id INTEGER PRIMARY KEY, fileid INTEGER REFERENCES file (id) ON DELETE CASCADE, page integer, content text); - -CREATE VIRTUAL TABLE content_fts USING fts5(content, content='content', content_rowid='id'); - +CREATE VIRTUAL TABLE content_fts USING fts5(content, content='content', content_rowid='id') +/* content_fts(content) */; CREATE TRIGGER contents_ai AFTER INSERT ON content BEGIN INSERT INTO content_fts(rowid, content) VALUES (new.id, new.content); END; diff --git a/gui/searchresult.h b/gui/searchresult.h index f124197..9df8c7f 100644 --- a/gui/searchresult.h +++ b/gui/searchresult.h @@ -8,6 +8,8 @@ class SearchResult unsigned int page; QString path; uint64_t mtime; + uint64_t size; + QChar filetype; SearchResult(); }; diff --git a/gui/searchworker.cpp b/gui/searchworker.cpp index 8248d64..598e799 100644 --- a/gui/searchworker.cpp +++ b/gui/searchworker.cpp @@ -117,6 +117,7 @@ QString SearchWorker::createSql(const SearchWorker::Command &cmd) return " content.id IN (SELECT content_fts.ROWID FROM content_fts WHERE content_fts.content MATCH '" + value + "' )"; } + throw std::invalid_argument("Unknown filter: " + key.toStdString()); } @@ -181,14 +182,15 @@ void SearchWorker::search(const QString &query) // TODO: hack, as we don't wanna look into content and get redundant results, when we don't even care about content if(whereSql.contains("content.")) { - prep = "SELECT file.path AS path, content.page AS page, file.mtime AS mtime FROM file INNER JOIN content ON " - "file.id = content.fileid WHERE 1=1 AND " + + prep = "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 + " ORDER By file.mtime DESC, content.page ASC"; } else { - prep = "SELECT file.path AS path, 0 as page, file.mtime AS mtime FROM file WHERE " + whereSql + - " ORDER by file.mtime DESC"; + prep = "SELECT file.path AS path, 0 as page, file.mtime AS mtime, file.size AS size, file.filetype AS " + "filetype FROM file WHERE " + + whereSql + " ORDER by file.mtime DESC"; } dbquery.prepare(prep); bool success = dbquery.exec(); @@ -207,6 +209,8 @@ void SearchWorker::search(const QString &query) result.path = dbquery.value("path").toString(); result.page = dbquery.value("page").toUInt(); result.mtime = dbquery.value("mtime").toUInt(); + result.size = dbquery.value("filesize").toUInt(); + result.filetype = dbquery.value("filetype").toChar(); results.append(result); } emit searchResultsReady(results);