From 864b2dd5057a37abbbd60f03a3581d56904b4a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=B9i=20Nguy=E1=BB=85n=20T=E1=BA=A5n=20Sang?= Date: Mon, 12 Feb 2024 14:12:44 +0700 Subject: [PATCH] Better search result display --- log.txt | 1 + main.py | 68 +++++++++++++++++++++++++++++-------------------- search/index.py | 6 +---- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/log.txt b/log.txt index e69de29..8b13789 100644 --- a/log.txt +++ b/log.txt @@ -0,0 +1 @@ + diff --git a/main.py b/main.py index e44f1f4..4c5b995 100644 --- a/main.py +++ b/main.py @@ -94,32 +94,46 @@ st.session_state.add_state = True if search_type == 'Text': - for row in Search_Result: - row2 = return_special_characters(row[2]) - row6 = return_special_characters(row[6]) - st.markdown('```' + str(row[0]) + '``` ```' + row[1] + '```') - row_title = row2.replace('\n', ' ') - row_title = row_title.replace(':', ' ') - st.markdown("### [" + row_title + ']' + '(' + row[1] + ')') - row_shorttext = row6.replace('\n', ' ') - row_shorttext = row_shorttext.replace('```', ' ') - st.markdown("```" + row_shorttext + "```") - st.markdown("   ") + if Search_Result is None: + st.write("No results found") + else: + for row in Search_Result: + row2 = return_special_characters(row[2]) + row6 = return_special_characters(row[6]) + row_title = row2.replace('\n', ' ') + row_title = row_title.replace(':', ' ') + row_shorttext = row6.replace('\n', ' ') + row_shorttext = row_shorttext.replace('```', ' ') + st.markdown("### [" + row_title + ']' + '(' + row[1] + ') ' + '```' + str(row[0]) + '```') + st.markdown(row_shorttext) + st.markdown("   ") elif search_type == 'Image': - for row in Search_Result: - st.image(image=row[1]) - row2 = return_special_characters(row[2]) - st.markdown('```' + str(row[0]) + '``` ```' + row[1] + '```') - row_title = row2.replace('\n', ' ') - row_title = row_title.replace(':', ' ') - st.markdown("### [" + row_title + ']' + '(' + row[1] + ')') - st.markdown("   ") + if Search_Result is None: + st.write("No results found") + else: + for i in range(0, len(Search_Result), 2): + cols = st.columns(2) + for j in range(2): + if i + j < len(Search_Result): + row = Search_Result[i + j] + cols[j].image(image=row[1]) + row2 = return_special_characters(row[2]) + row_title = row2.replace('\n', ' ') + row_title = row_title.replace(':', ' ') + cols[j].markdown("### [" + row_title + ']' + '(' + row[1] + ')' + '```' + str(row[0]) + '```') + cols[j].markdown(row[4]) + cols[j].markdown("   ") elif search_type == 'Video': - for row in Search_Result: - st.video(row[1]) - row2 = return_special_characters(row[2]) - st.markdown('```' + str(row[0]) + '``` ```' + row[1] + '```') - row_title = row2.replace('\n', ' ') - row_title = row_title.replace(':', ' ') - st.markdown("### [" + row_title + ']' + '(' + row[1] + ')') - st.markdown("   ") \ No newline at end of file + if Search_Result is None: + st.write("No results found") + else: + for row in Search_Result: + col1, col2 = st.columns([1, 3]) + col1.video(row[1]) + row2 = return_special_characters(row[2]) + row_title = row2.replace('\n', ' ') + row_title = row_title.replace(':', ' ') + col2.markdown('```' + str(row[0]) + '``` ```' + row[1] + '```') + col2.markdown("### [" + row_title + ']' + '(' + row[1] + ')') + col2.markdown(row[7]) + st.markdown("   ") diff --git a/search/index.py b/search/index.py index 6824b62..135171f 100644 --- a/search/index.py +++ b/search/index.py @@ -1,6 +1,3 @@ -import streamlit as st - -from atmt import ATMT_STRT from search.safe import escape_special_characters def Search_Data(conn, keyword): @@ -14,7 +11,6 @@ def Search_Data(conn, keyword): rows = cursor.fetchall() if len(rows) == 0: - st.write("No results found") - #ATMT_STRT(keyword) + return None else: return rows