Sort search results
This commit is contained in:
parent
77c84fc083
commit
a08a2998a3
1 changed files with 7 additions and 0 deletions
|
@ -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}",
|
||||
]
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue