From afefa1928f1ee7dd1c94dc401f9a20a379bdccfa Mon Sep 17 00:00:00 2001 From: Mawoka Date: Thu, 14 Apr 2022 15:28:43 +0200 Subject: [PATCH] :sparkles: Added search --- classquiz/routers/search.py | 6 +- frontend/src/routes/explore.svelte | 2 +- frontend/src/routes/search.svelte | 92 ++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 frontend/src/routes/search.svelte diff --git a/classquiz/routers/search.py b/classquiz/routers/search.py index 0ed932f..9836e26 100644 --- a/classquiz/routers/search.py +++ b/classquiz/routers/search.py @@ -53,7 +53,7 @@ class SearchData(pydantic.BaseModel): sort: Optional[list[str]] = None -@router.post("/search", response_model=SearchResponse) +@router.post("/", response_model=SearchResponse) async def search(data: SearchData): index = meilisearch.get_index(settings.meilisearch_index) query = index.search(data.q, { @@ -68,10 +68,10 @@ async def search(data: SearchData): "sort": data.sort, "attributesToHighlight": data.attributesToHighlight }) - return query.serialize() + return SearchResponse(**query) -@router.get("/search", response_model=SearchResponse) +@router.get("/", response_model=SearchResponse) async def search_get(q: str, offset: int = 0, limit: int = 20, filter: str | None = None, cropLength: int = 200, matches: bool = False, attributesToHighlight: Optional[str] = "*"): index = meilisearch.get_index(settings.meilisearch_index) diff --git a/frontend/src/routes/explore.svelte b/frontend/src/routes/explore.svelte index 4c4d1aa..57e6ca0 100644 --- a/frontend/src/routes/explore.svelte +++ b/frontend/src/routes/explore.svelte @@ -1,6 +1,6 @@ diff --git a/frontend/src/routes/search.svelte b/frontend/src/routes/search.svelte new file mode 100644 index 0000000..df44a35 --- /dev/null +++ b/frontend/src/routes/search.svelte @@ -0,0 +1,92 @@ + + + +
+
+
+
+ + +
+
+
+
+ + +{#if resp_data} +
+ {#each resp_data.hits as quiz} + + {/each} +
+{/if} + + + \ No newline at end of file