From 8d9fdcfc8cd5eaa8b9e0aa3fb3d3cfd0b4f8daf8 Mon Sep 17 00:00:00 2001 From: Will Date: Fri, 19 Jan 2024 12:47:57 -0800 Subject: [PATCH] Changed Semantic Search result display in Dashboard -Changed Semantic Search result display in Dashboard --- .../dashboard/pages/5_Document Search.py | 25 ++++++++++++++----- cmd/dashboard/dashboard/templates.py | 21 ++++------------ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/cmd/dashboard/dashboard/pages/5_Document Search.py b/cmd/dashboard/dashboard/pages/5_Document Search.py index 533158a..dac1677 100644 --- a/cmd/dashboard/dashboard/pages/5_Document Search.py +++ b/cmd/dashboard/dashboard/pages/5_Document Search.py @@ -236,14 +236,27 @@ def build_page(username: str): try: json_results = utils.semantic_search(search_term, num_results) - if not json_results or "results" not in json_results: + if json_results and "error" in json_results: + error = json_results["error"] + if "index_not_found_exception" in error: + st.warning("No text has been indexed!") + else: + st.error(f"Error from NLP service: {error}") + elif not json_results or "results" not in json_results: st.warning("No results retrieved from semantic search, service might be busy") else: - for result in json_results["results"]: - (header, text, footer) = templates.semantic_search_result(result) - st.write(header, unsafe_allow_html=True) - st.write(text, unsafe_allow_html=False) - st.write(footer, unsafe_allow_html=True) + if len(json_results) > 0: + for result in json_results["results"]: + header = templates.semantic_search_result(result) + st.subheader("", divider="red") + st.markdown(header, unsafe_allow_html=True) + st.markdown("") + st.code(result["text"], None) + st.subheader("", divider="red") + else: + st.warning("No results retrieved from semantic search") + + except Exception as e: st.error(f"Exception: {e}") diff --git a/cmd/dashboard/dashboard/templates.py b/cmd/dashboard/dashboard/templates.py index b20e324..edbd84b 100644 --- a/cmd/dashboard/dashboard/templates.py +++ b/cmd/dashboard/dashboard/templates.py @@ -196,7 +196,7 @@ def sourcecode_search_result(i: int, object_id: str, download_url: str, source: ) -def semantic_search_result(result) -> Tuple[str, str, str]: +def semantic_search_result(result) ->str: """HTML scripts to display a semantic search json result.""" text = result["text"] @@ -220,23 +220,12 @@ def semantic_search_result(result) -> Tuple[str, str, str]: else None ) - return ( - f""" + return f"""
{originating_object_path}
-
-
- Score: {score} -   - {f"Source: {source}" if source else ""} - {pdf_html} -
-
""",
-        text,
-        """
-
- """, - ) +
+ Score: {score}
{f"Source: {source}" if source else ""}
{pdf_html} + """