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:
parent
0b321e0de1
commit
cfed88e135
@ -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())
|
||||||
@ -133,20 +134,33 @@ QSqlQuery SqliteSearch::makeSqlQuery(const QSSQuery &query)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(const Token &token : query.getTokens())
|
for(const Token &token : query.getTokens())
|
||||||
|
{
|
||||||
|
if(token.type == FILTER_CONTENT_CONTAINS)
|
||||||
|
{
|
||||||
|
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);
|
auto sql = createSql(token);
|
||||||
whereSql += sql.first;
|
whereSql += sql.first;
|
||||||
bindValues.append(sql.second);
|
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 " + joinSql+
|
||||||
whereSql + " GROUP BY file.path " + sortSql;
|
" WHERE 1=1 AND " +whereSql + " GROUP BY file.path " + sortSql;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user