DistroqueryAPI: getRepositoryPackages: better sort results by query relevance

This commit is contained in:
Silvan Calarco 2024-11-03 18:31:33 +01:00
parent fd5a9768da
commit f90a4edb6b

View File

@ -116,9 +116,18 @@ json DistroqueryAPI::getRepositoryPackages(string repository, int per_page, int
archorder++;
}
sql += ") AS u ORDER BY name COLLATE NOCASE ASC,sort"
" LIMIT " + to_string(per_page) +
" OFFSET " + to_string(per_page * (page -1));
sql += ") AS u";
if (query != "") {
sql += " ORDER BY name='" + query + "' COLLATE NOCASE DESC, "
"name LIKE '" + query + "%' DESC,"
"summary LIKE '%" + query + "%' DESC,"
" name COLLATE NOCASE ASC,sort";
} else {
sql += " ORDER BY name COLLATE NOCASE ASC,sort";
}
sql += " LIMIT " + to_string(per_page) +
" OFFSET " + to_string(per_page * (page -1));
if (sqlite3_prepare_v2(db, sql.c_str(), sql.length(), &stmt, NULL) == SQLITE_OK) {
json packages = json::array();