Mercurial > code > home > repos > sco-bot
diff scobot/service/query.py @ 14:b9c2b7fedbcd
fix up deployment and connect ui to server again
author | drewp@bigasterisk.com |
---|---|
date | Thu, 11 Jul 2024 22:11:41 -0700 |
parents | 403eff4a16c8 |
children | 6ed25bcaaf1f |
line wrap: on
line diff
--- a/scobot/service/query.py Thu Jul 11 21:32:24 2024 -0700 +++ b/scobot/service/query.py Thu Jul 11 22:11:41 2024 -0700 @@ -1,3 +1,4 @@ +import html from scobot.index.access import SearchIndexRO from whoosh.qparser import QueryParser import json @@ -47,7 +48,7 @@ @asynccontextmanager async def lifespan(app: FastAPI): - app.state.index = SearchIndexRO('/tmp/scoindex') + app.state.index = SearchIndexRO('data/index') yield app = FastAPI(lifespan=lifespan) @@ -58,5 +59,10 @@ query = QueryParser("phrase", index.ix.schema).parse(q) pprint(query) - results = list(index.searcher.search(query)) - return {"results": results} + results = index.searcher.search(query) + docs=[] + for res in results: + doc=dict(res) + doc['snippetHtml'] = html.escape(doc['phrase']) + docs.append(doc) + return {"results": docs}