Query/Save filetype and size
This commit is contained in:
父節點
9201e2e768
當前提交
8e3585df38
@ -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;
|
||||
|
@ -8,6 +8,8 @@ class SearchResult
|
||||
unsigned int page;
|
||||
QString path;
|
||||
uint64_t mtime;
|
||||
uint64_t size;
|
||||
QChar filetype;
|
||||
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 +
|
||||
"' )";
|
||||
}
|
||||
|
||||
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);
|
||||
|
載入中…
新增問題並參考
Block a user