Allow searching by collection

This commit is contained in:
Correl Roush 2023-07-04 17:45:32 -04:00
parent 144b1eb2ba
commit 2435ecb5ff
3 changed files with 23 additions and 1 deletions

View file

@ -168,6 +168,9 @@ async def advanced_search(
if isinstance(criterion, tutor.search.Oracle):
constraints.append(f"cards.oracle_text ILIKE %({param})s")
params[param] = f"%{criterion.text}%"
if isinstance(criterion, tutor.search.Collection) and in_collection:
constraints.append(f"copies.collection ILIKE %({param})s")
params[param] = f"%{criterion.text}%"
if in_collection is not None:
if in_collection:

View file

@ -44,6 +44,11 @@ class Oracle(Criterion):
text: parsy.string
@dataclasses.dataclass
class Collection(Criterion):
text: parsy.string
@dataclasses.dataclass
class Name(Criterion):
operator: Operator = Operator.matches
@ -169,9 +174,15 @@ oracle = parsy.seq(
text=string_literal,
).combine_dict(Oracle)
collection = parsy.seq(
_keyword=lstring_from("collection"),
operator=matches,
text=string_literal,
).combine_dict(Collection)
name = parsy.seq(text=string_literal).combine_dict(Name)
criterion = colors | expansion | rarity | type_line | oracle | name
criterion = colors | expansion | rarity | type_line | oracle | collection | name
padding = parsy.regex(r"\s*")
search = padding >> (criterion << padding).many().map(Search)

View file

@ -193,6 +193,14 @@ paths:
Operators
: `:` (matches)
#### Collection
Keywords
: `collection`
Operators
: `:` (matches)
responses:
'200':
description: Search results