search.py
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from typing import List, Any, Optional, Union
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from presupuestov1 import model, schema, constant, schemas, models, search
router = APIRouter(
tags=['search']
)
###############################################################################
# GET
###############################################################################
@router.get('/search', response_model=schemas.project.Search)
def fetch_search(
query: schema.SearchQueryParams = Depends(),
):
if query.q is None or len(query.q.strip()) < 3:
return {
'facet_counts': [],
'found': 0,
'out_of': 0,
'page': 0,
'search_time_ms': 0,
'hits': [],
}
return search.do_search(
query.q, query.page, query.is_class, query.class_, query.order
)
# try:
# return search.do_search(
# query.q, query.page, query.is_class, query.class_, query.order
# )
# except search.SearchUnavailable as exc:
# raise HTTPException(
# status_code=503,
# detail='Search temporarily unavailable',
# headers={'Retry-After': str(exc.retry_after)},
# ) from exc