From 2435ecb5ff56c63f861317550eb98e0cfec45fef Mon Sep 17 00:00:00 2001 From: Correl Date: Tue, 4 Jul 2023 17:45:32 -0400 Subject: [PATCH] Allow searching by collection --- tutor/database.py | 3 +++ tutor/search.py | 13 ++++++++++++- tutor/templates/openapi.yaml | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tutor/database.py b/tutor/database.py index f3da0bf..74f6b51 100644 --- a/tutor/database.py +++ b/tutor/database.py @@ -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: diff --git a/tutor/search.py b/tutor/search.py index 89b13f9..abe2162 100644 --- a/tutor/search.py +++ b/tutor/search.py @@ -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) diff --git a/tutor/templates/openapi.yaml b/tutor/templates/openapi.yaml index a535a76..dc15b47 100644 --- a/tutor/templates/openapi.yaml +++ b/tutor/templates/openapi.yaml @@ -193,6 +193,14 @@ paths: Operators : `:` (matches) + + #### Collection + + Keywords + : `collection` + + Operators + : `:` (matches) responses: '200': description: Search results