Query/Save filetype and size

This commit is contained in:
Albert S. 2019-04-06 17:13:38 +02:00
父節點 9201e2e768
當前提交 8e3585df38
共有 3 個文件被更改,包括 13 次插入8 次删除

查看文件

@ -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;

查看文件

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

查看文件

@ -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 + 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());
} }
@ -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 // 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 " prep = "SELECT file.path AS path, content.page AS page, file.mtime AS mtime, file.size AS size, file.filetype "
"file.id = content.fileid WHERE 1=1 AND " + "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"; 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 + prep = "SELECT file.path AS path, 0 as page, file.mtime AS mtime, file.size AS size, file.filetype AS "
" ORDER by file.mtime DESC"; "filetype FROM file WHERE " +
whereSql + " ORDER by file.mtime DESC";
} }
dbquery.prepare(prep); dbquery.prepare(prep);
bool success = dbquery.exec(); bool success = dbquery.exec();
@ -207,6 +209,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);