Sort search results

This commit is contained in:
Correl Roush 2021-07-15 22:00:01 -04:00
parent 77c84fc083
commit a08a2998a3

View file

@ -141,12 +141,19 @@ async def advanced_search(
joins.append("LEFT JOIN copies ON (cards.scryfall_id = copies.scryfall_id)")
constraints.append("copies.id IS NULL")
joins.append("JOIN sets ON (cards.set_code = sets.set_code)")
joins.append("JOIN rarities ON (cards.rarity = rarities.rarity)")
query = " ".join(
[
"SELECT cards.* FROM cards",
" ".join(joins),
"WHERE" if constraints else "",
" AND ".join(constraints),
"ORDER BY rarities.rarity_ord DESC",
", length(cards.color_identity) DESC",
", CASE ",
" WHEN length(cards.color_identity) > 0 THEN '0'"
" ELSE cards.color_identity END ASC",
", cards.name ASC",
f"LIMIT {offset},{limit}",
]
)