shared: sqlitesearch: Remove subquery for content search

The subquery only works for boolean retrieval, its
ordering is irrelevant. Thus, use INNER JOIN instead
and order by rank by default.
This commit is contained in:
Albert S. 2021-03-07 22:23:12 +01:00
parent e225fdad21
commit ee4fe51a77

View File

@ -125,6 +125,7 @@ QPair<QString, QVector<QString>> SqliteSearch::createSql(const Token &token)
QSqlQuery SqliteSearch::makeSqlQuery(const QSSQuery &query) QSqlQuery SqliteSearch::makeSqlQuery(const QSSQuery &query)
{ {
QString whereSql; QString whereSql;
QString joinSql;
QVector<QString> bindValues; QVector<QString> bindValues;
bool isContentSearch = query.getTokensMask() & FILTER_CONTENT == FILTER_CONTENT; bool isContentSearch = query.getTokensMask() & FILTER_CONTENT == FILTER_CONTENT;
if(query.getTokens().isEmpty()) if(query.getTokens().isEmpty())
@ -134,19 +135,32 @@ QSqlQuery SqliteSearch::makeSqlQuery(const QSSQuery &query)
for(const Token &token : query.getTokens()) for(const Token &token : query.getTokens())
{ {
auto sql = createSql(token); if(token.type == FILTER_CONTENT_CONTAINS)
whereSql += sql.first; {
bindValues.append(sql.second); joinSql += " INNER JOIN content_fts ON content.id = content_fts.ROWID ";
whereSql += " content_fts.content MATCH ? ";
bindValues.append(token.value);
}
else
{
auto sql = createSql(token);
whereSql += sql.first;
bindValues.append(sql.second);
}
} }
QString prepSql; QString prepSql;
QString sortSql = createSortSql(query.getSortConditions()); QString sortSql = createSortSql(query.getSortConditions());
if(isContentSearch) if(isContentSearch)
{ {
if(sortSql.isEmpty())
{
sortSql = "ORDER BY rank";
}
prepSql = prepSql =
"SELECT file.path AS path, group_concat(content.page) AS pages, file.mtime AS mtime, file.size AS size, " "SELECT file.path AS path, group_concat(content.page) AS pages, 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 " + "file.filetype AS filetype FROM file INNER JOIN content ON file.id = content.fileid " +
whereSql + " GROUP BY file.path " + sortSql; joinSql + " WHERE 1=1 AND " + whereSql + " GROUP BY file.path " + sortSql;
} }
else else
{ {