2e reviewed manuscript

This commit is contained in:
Luciano Ramalho
2021-11-12 11:33:12 -03:00
parent f5e3cb8ad3
commit 80f7f84274
32 changed files with 323 additions and 156 deletions

View File

@@ -7,25 +7,26 @@ from pydantic import BaseModel
from charindex import InvertedIndex
app = FastAPI( # <1>
STATIC_PATH = Path(__file__).parent.absolute() / 'static' # <1>
app = FastAPI( # <2>
title='Mojifinder Web',
description='Search for Unicode characters by name.',
)
class CharName(BaseModel): # <2>
class CharName(BaseModel): # <3>
char: str
name: str
def init(app): # <3>
def init(app): # <4>
app.state.index = InvertedIndex()
static = Path(__file__).parent.absolute() / 'static' # <4>
app.state.form = (static / 'form.html').read_text()
app.state.form = (STATIC_PATH / 'form.html').read_text()
init(app) # <5>
@app.get('/search', response_model=list[CharName]) # <6>
async def search(q: str): # <7>
chars = app.state.index.search(q)
chars = sorted(app.state.index.search(q))
return ({'char': c, 'name': name(c)} for c in chars) # <8>
@app.get('/', response_class=HTMLResponse, include_in_schema=False)