From b8c0fc0ae3a7d1d66b6029024056db22bd63aaa8 Mon Sep 17 00:00:00 2001 From: Albert S Date: Fri, 26 Apr 2019 21:41:20 +0200 Subject: [PATCH] search: default sort by mtime and page --- shared/sqlitesearch.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/shared/sqlitesearch.cpp b/shared/sqlitesearch.cpp index 999284b..71e4a99 100644 --- a/shared/sqlitesearch.cpp +++ b/shared/sqlitesearch.cpp @@ -198,8 +198,8 @@ QPair> SqliteSearch::createSql(const SqliteSearch::Tok QSqlQuery SqliteSearch::makeSqlQuery(const QVector &tokens) { QString whereSql; - QString sortSql; QString limitSql; + QString sortSql; QVector bindValues; bool isContentSearch = false; for(const Token &c : tokens) @@ -227,10 +227,18 @@ QSqlQuery SqliteSearch::makeSqlQuery(const QVector &tokens) QString prepSql; if(isContentSearch) { + if(sortSql.isEmpty()) + { + sortSql = "ORDER BY file.mtime DESC, content.page ASC"; + } prepSql = "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 " + whereSql + " " + sortSql + " GROUP BY file.path"; } else { + if(sortSql.isEmpty()) + { + sortSql = "ORDER BY file.mtime DESC"; + } prepSql = "SELECT file.path AS path, '0' as pages, file.mtime AS mtime, file.size AS size, file.filetype AS filetype FROM file WHERE 1=1 AND " + whereSql + " " + sortSql; }