shared: Adjust queries to db revision 2
This commit is contained in:
parent
78f38fa418
commit
1da8344295
@ -151,11 +151,14 @@ SaveFileResult SqliteDbService::saveFile(QFileInfo fileInfo, QVector<PageData> &
|
|||||||
int lastid = inserterQuery.lastInsertId().toInt();
|
int lastid = inserterQuery.lastInsertId().toInt();
|
||||||
for(const PageData &data : pageData)
|
for(const PageData &data : pageData)
|
||||||
{
|
{
|
||||||
|
QSqlQuery ftsQuery(db);
|
||||||
|
ftsQuery.prepare("INSERT INTO fts(content) VALUES(?)");
|
||||||
|
ftsQuery.addBindValue(data.content);
|
||||||
|
ftsQuery.exec();
|
||||||
QSqlQuery contentQuery(db);
|
QSqlQuery contentQuery(db);
|
||||||
contentQuery.prepare("INSERT INTO content(fileid, page, content) VALUES(?, ?, ?)");
|
contentQuery.prepare("INSERT INTO content(fileid, page, ftsid) VALUES(?, ?, last_insert_rowid())");
|
||||||
contentQuery.addBindValue(lastid);
|
contentQuery.addBindValue(lastid);
|
||||||
contentQuery.addBindValue(data.pagenumber);
|
contentQuery.addBindValue(data.pagenumber);
|
||||||
contentQuery.addBindValue(data.content);
|
|
||||||
if(!contentQuery.exec())
|
if(!contentQuery.exec())
|
||||||
{
|
{
|
||||||
db.rollback();
|
db.rollback();
|
||||||
|
@ -115,7 +115,7 @@ QPair<QString, QVector<QString>> SqliteSearch::createSql(const Token &token)
|
|||||||
}
|
}
|
||||||
if(token.type == FILTER_CONTENT_CONTAINS)
|
if(token.type == FILTER_CONTENT_CONTAINS)
|
||||||
{
|
{
|
||||||
return {" content.id IN (SELECT content_fts.ROWID FROM content_fts WHERE content_fts.content MATCH ? ORDER BY "
|
return {" content.id IN (SELECT fts.ROWID FROM fts WHERE fts.content MATCH ? ORDER BY "
|
||||||
"rank) ",
|
"rank) ",
|
||||||
{value}};
|
{value}};
|
||||||
}
|
}
|
||||||
@ -141,10 +141,10 @@ QSqlQuery SqliteSearch::makeSqlQuery(const LooqsQuery &query)
|
|||||||
{
|
{
|
||||||
if(!ftsAlreadyJoined)
|
if(!ftsAlreadyJoined)
|
||||||
{
|
{
|
||||||
joinSql += " INNER JOIN content_fts ON content.id = content_fts.ROWID ";
|
joinSql += " INNER JOIN fts ON content.ftsid = fts.ROWID ";
|
||||||
ftsAlreadyJoined = true;
|
ftsAlreadyJoined = true;
|
||||||
}
|
}
|
||||||
whereSql += " content_fts.content MATCH ? ";
|
whereSql += " fts.content MATCH ? ";
|
||||||
bindValues.append(token.value);
|
bindValues.append(token.value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user