Add USD price search
This commit is contained in:
parent
b30a467793
commit
ed7ac88db0
2 changed files with 27 additions and 1 deletions
|
@ -171,6 +171,19 @@ async def advanced_search(
|
||||||
if criterion.operator == tutor.search.Operator.gte:
|
if criterion.operator == tutor.search.Operator.gte:
|
||||||
constraints.append(f"cards.rarity >= %({param})s::rarity")
|
constraints.append(f"cards.rarity >= %({param})s::rarity")
|
||||||
params[param] = criterion.rarity.value
|
params[param] = criterion.rarity.value
|
||||||
|
if isinstance(criterion, tutor.search.PriceUSD):
|
||||||
|
if criterion.operator == tutor.search.Operator.gte:
|
||||||
|
constraints.append(
|
||||||
|
f'(("copies"."isFoil" AND cards.price_usd_foil >= %({param})s)'
|
||||||
|
f'OR (NOT "copies"."isFoil" AND cards.price_usd >= %({param})s))'
|
||||||
|
)
|
||||||
|
params[param] = criterion.price
|
||||||
|
if criterion.operator == tutor.search.Operator.lte:
|
||||||
|
constraints.append(
|
||||||
|
f'(("copies"."isFoil" AND cards.price_usd_foil <= %({param})s)'
|
||||||
|
f'OR (NOT "copies"."isFoil" AND cards.price_usd <= %({param})s))'
|
||||||
|
)
|
||||||
|
params[param] = criterion.price
|
||||||
if isinstance(criterion, tutor.search.Oracle):
|
if isinstance(criterion, tutor.search.Oracle):
|
||||||
constraints.append(f"cards.oracle_text ILIKE %({param})s")
|
constraints.append(f"cards.oracle_text ILIKE %({param})s")
|
||||||
params[param] = f"%{criterion.text}%"
|
params[param] = f"%{criterion.text}%"
|
||||||
|
|
|
@ -44,6 +44,11 @@ class Oracle(Criterion):
|
||||||
text: parsy.string
|
text: parsy.string
|
||||||
|
|
||||||
|
|
||||||
|
@dataclasses.dataclass
|
||||||
|
class PriceUSD(Criterion):
|
||||||
|
price: parsy.string
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class Collection(Criterion):
|
class Collection(Criterion):
|
||||||
text: parsy.string
|
text: parsy.string
|
||||||
|
@ -180,6 +185,12 @@ collection = parsy.seq(
|
||||||
text=string_literal,
|
text=string_literal,
|
||||||
).combine_dict(Collection)
|
).combine_dict(Collection)
|
||||||
|
|
||||||
|
price_usd = parsy.seq(
|
||||||
|
_keyword=lstring_from("usd"),
|
||||||
|
operator=gte | lte,
|
||||||
|
price=string_literal,
|
||||||
|
).combine_dict(PriceUSD)
|
||||||
|
|
||||||
|
|
||||||
exact_name = parsy.seq(_prefix=lstring_from("!"), text=string_literal).combine_dict(
|
exact_name = parsy.seq(_prefix=lstring_from("!"), text=string_literal).combine_dict(
|
||||||
functools.partial(Name, operator=Operator.matches)
|
functools.partial(Name, operator=Operator.matches)
|
||||||
|
@ -188,7 +199,9 @@ partial_name = parsy.seq(text=string_literal).combine_dict(Name)
|
||||||
|
|
||||||
name = exact_name | partial_name
|
name = exact_name | partial_name
|
||||||
|
|
||||||
criterion = colors | expansion | rarity | type_line | oracle | collection | name
|
criterion = (
|
||||||
|
colors | expansion | rarity | type_line | oracle | collection | price_usd | name
|
||||||
|
)
|
||||||
|
|
||||||
padding = parsy.regex(r"\s*")
|
padding = parsy.regex(r"\s*")
|
||||||
search = padding >> (criterion << padding).many().map(Search)
|
search = padding >> (criterion << padding).many().map(Search)
|
||||||
|
|
Loading…
Reference in a new issue