Query/Save filetype and size

This commit is contained in:
Albert S. 2019-04-06 17:13:38 +02:00
parent ac921c691c
commit b7b93a66a9
3 changed files with 10 additions and 6 deletions

View File

@ -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 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 CREATE TRIGGER contents_ai AFTER INSERT ON content BEGIN
INSERT INTO content_fts(rowid, content) VALUES (new.id, new.content); INSERT INTO content_fts(rowid, content) VALUES (new.id, new.content);
END; END;

View File

@ -8,6 +8,8 @@ public:
unsigned int page; unsigned int page;
QString path; QString path;
uint64_t mtime; uint64_t mtime;
uint64_t size;
QChar filetype;
SearchResult(); SearchResult();
}; };

View File

@ -119,6 +119,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 + "' )"; 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()); throw std::invalid_argument("Unknown filter: " + key.toStdString());
} }
@ -183,11 +184,11 @@ 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 //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.")) 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 " + whereSql + " ORDER By file.mtime DESC, content.page ASC"; 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 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); dbquery.prepare(prep);
bool success = dbquery.exec(); bool success = dbquery.exec();
@ -206,6 +207,8 @@ void SearchWorker::search(const QString &query)
result.path = dbquery.value("path").toString(); result.path = dbquery.value("path").toString();
result.page = dbquery.value("page").toUInt(); result.page = dbquery.value("page").toUInt();
result.mtime = dbquery.value("mtime").toUInt(); result.mtime = dbquery.value("mtime").toUInt();
result.size = dbquery.value("filesize").toUInt();
result.filetype = dbquery.value("filetype").toChar();
results.append(result); results.append(result);
} }
emit searchResultsReady(results); emit searchResultsReady(results);