Mercurial > code > home > repos > sco-bot
changeset 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 |
files | Dockerfile.server pyproject.toml scobot/index/build_index_flow.py scobot/service/__init__.py scobot/service/query.py web/src/main.ts |
diffstat | 5 files changed, 23 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/Dockerfile.server Thu Jul 11 21:32:24 2024 -0700 +++ b/Dockerfile.server Thu Jul 11 22:11:41 2024 -0700 @@ -8,4 +8,4 @@ RUN pdm run python -c 'import nltk; nltk.download("punkt")' COPY env ./ -COPY scobot/** ./scobot/ \ No newline at end of file +COPY scobot/ ./scobot/
--- a/pyproject.toml Thu Jul 11 21:32:24 2024 -0700 +++ b/pyproject.toml Thu Jul 11 22:11:41 2024 -0700 @@ -33,4 +33,5 @@ run_prefect_server = "prefect server start" run_build_flow = "python -c 'from scobot.index.build_index_flow import buildIndex; buildIndex.serve(buildIndex.__name__)'" start_build = "prefect deployment run buildIndex/buildIndex" -run_local_deploy = "fastapi dev --host 0.0.0.0 --port 8001 scobot" \ No newline at end of file +run_local_deploy = "fastapi dev --host 0.0.0.0 --port 8001 scobot" +run_local_vite = {shell = "(cd web; pnpm exec vite)"}
--- a/scobot/index/build_index_flow.py Thu Jul 11 21:32:24 2024 -0700 +++ b/scobot/index/build_index_flow.py Thu Jul 11 22:11:41 2024 -0700 @@ -91,7 +91,7 @@ log = get_run_logger() scobot.index.access.log = log - index = SearchIndex(Path('/tmp/scoindex')) + index = SearchIndex(Path('data/index')) for url in meetingListUrls(): mtgs = cast(list[MeetingRow], getCityMutableJson(url)) log.info(f'got {len(mtgs)=}')
--- 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}
--- a/web/src/main.ts Thu Jul 11 21:32:24 2024 -0700 +++ b/web/src/main.ts Thu Jul 11 22:11:41 2024 -0700 @@ -5,6 +5,12 @@ import { unsafeHTML } from "lit/directives/unsafe-html.js"; setBasePath("@fs/opt/node_modules/@shoelace-style/shoelace/dist"); +interface Doc { + sourceTitle: string + phrase: string + snippetHtml: string +} + @customElement("sco-search-page") export class ScoSearchPage extends LitElement { static styles = [ @@ -52,7 +58,7 @@ `, ]; @state() query: string = "climate"; - @state() results: Object[] = []; + @state() results: Doc[] = []; @state() queryError: string = ""; @queryAsync("sl-textarea") queryEl?: Promise<SlTextarea>; protected async firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>) { @@ -114,10 +120,10 @@ <section id="results"> <dl> ${this.results.map( - (r) => - html`<dt>${r.title}</dt> + (r: Doc) => + html`<dt>${r.sourceTitle}</dt> <dd>${unsafeHTML(r.snippetHtml)}</dd>` - )} + )} </dl> <div>Matching results: ${this.results.length}</div> </section>