shared: sqlitesearch: Only order by rank if token is FILTER_CONTENT_CONTAINS

Cette révision appartient à :
Albert S. 2022-04-17 21:15:58 +02:00
Parent 2a024a9b40
révision 8194476fa6

Voir le fichier

@ -133,7 +133,8 @@ QSqlQuery SqliteSearch::makeSqlQuery(const LooqsQuery &query)
throw LooqsGeneralException("Nothing to search for supplied"); throw LooqsGeneralException("Nothing to search for supplied");
} }
for(const Token &token : query.getTokens()) auto tokens = query.getTokens();
for(const Token &token : tokens)
{ {
if(token.type == FILTER_CONTENT_CONTAINS) if(token.type == FILTER_CONTENT_CONTAINS)
{ {
@ -154,9 +155,13 @@ QSqlQuery SqliteSearch::makeSqlQuery(const LooqsQuery &query)
if(isContentSearch) if(isContentSearch)
{ {
if(sortSql.isEmpty()) if(sortSql.isEmpty())
{
if(std::find_if(tokens.begin(), tokens.end(),
[](const Token &t) -> bool { return t.type == FILTER_CONTENT_CONTAINS; }) != tokens.end())
{ {
sortSql = "ORDER BY rank"; 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 " + "file.filetype AS filetype FROM file INNER JOIN content ON file.id = content.fileid " +