diff --git a/app.py b/app.py index 909030f..9bb801f 100644 --- a/app.py +++ b/app.py @@ -1,3 +1,5 @@ +import logging + import uvicorn import create_app @@ -8,6 +10,8 @@ from paths import INDEX_PATH tiny_index = TinyIndex(Document, INDEX_PATH, NUM_PAGES, PAGE_SIZE) app = create_app.create(tiny_index) +logging.basicConfig() + if __name__ == "__main__": uvicorn.run("app:app", host="127.0.0.1", port=8000, log_level="info") diff --git a/create_app.py b/create_app.py index 1aafff8..590b62a 100644 --- a/create_app.py +++ b/create_app.py @@ -1,3 +1,4 @@ +from logging import getLogger from typing import List import Levenshtein @@ -8,22 +9,17 @@ from starlette.staticfiles import StaticFiles from index import TinyIndex, Document +logger = getLogger(__name__) + + def create(tiny_index: TinyIndex): app = FastAPI() @app.get("/search") def search(s: str): results = get_results(s) - doc = "" - for result in results: - doc += f'
\n' - return HTMLResponse(doc) - - # if '—' in s: - # url = s.split('—')[1].strip() - # else: - # url = f'https://www.google.com/search?q={s}' - # return RedirectResponse(url) + logger.info("Return results: %r", results) + return results def order_results(query, results: List[Document]): ordered_results = sorted(results, key=lambda result: Levenshtein.distance(query, result.title)) diff --git a/static/index.html b/static/index.html index 2bd6812..84d2ee6 100644 --- a/static/index.html +++ b/static/index.html @@ -5,12 +5,17 @@ type="application/opensearchdescription+xml" title="Stoatally Different" href="http://localhost:8000/plugin.xml"> + Stoatally different. + +