From 08a11f7ed828099d3ce3180bec068140733c2670 Mon Sep 17 00:00:00 2001 From: Tim Repke <repke@mcc-berlin.net> Date: Wed, 26 Jun 2024 18:36:16 +0200 Subject: [PATCH] use body for oa search --- server/api/routes/search.py | 40 ++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/server/api/routes/search.py b/server/api/routes/search.py index 5e1e6c9..45451ef 100644 --- a/server/api/routes/search.py +++ b/server/api/routes/search.py @@ -29,27 +29,31 @@ class TermStats(BaseModel): ttf: int +class SearchPayload(BaseModel): + query: str + limit: int = 20 + offset: int = 0 + def_type: DefType = 'lucene' + field: SearchField = 'title_abstract' + histogram: bool = False + op: OpType = 'AND' + histogram_from: int = 1990 + histogram_to: int = 2024 + + @router.post('/openalex/select', response_model=SearchResult) -async def search_openalex(query: str, - limit: int = 20, - offset: int = 0, - def_type: DefType = 'lucene', - field: SearchField = 'title_abstract', - histogram: bool = False, - op: OpType = 'AND', - histogram_from: int = 1990, - histogram_to: int = 2024, +async def search_openalex(search: SearchPayload, permissions: UserPermissions = Depends(UserPermissionChecker('search_oa'))) -> SearchResult: - return await query_async(query=query, + return await query_async(query=search.query, openalex_endpoint=str(settings.OA_SOLR), - histogram=histogram, - histogram_to=histogram_to, - histogram_from=histogram_from, - op=op, - def_type=def_type, - field=field, - offset=offset, - limit=limit) + histogram=search.histogram, + histogram_to=search.histogram_to, + histogram_from=search.histogram_from, + op=search.op, + def_type=search.def_type, + field=search.field, + offset=search.offset, + limit=search.limit) @router.get('/openalex/terms', response_model=list[TermStats]) -- GitLab