remove username and snippet from SERP page

This commit is contained in:
Russell Ballestrini 2024-07-04 12:04:46 -04:00
parent db3c15ea0d
commit 57d8e701f2
2 changed files with 0 additions and 28 deletions

27
app.py
View file

@ -188,41 +188,14 @@ def search_messages(keywords):
message.content.lower().count(keyword) for keyword in keyword_list
)
# Extract snippets with context around each occurrence of the keywords
snippets = []
content_lower = message.content.lower()
for keyword in keyword_list:
start_index = 0
while start_index < len(content_lower):
start_index = content_lower.find(keyword, start_index)
if start_index == -1:
break
# Calculate the snippet range
snippet_start = max(0, start_index - 25)
snippet_end = min(
len(message.content), start_index + len(keyword) + 25
)
snippet = message.content[snippet_start:snippet_end]
snippets.append(snippet)
start_index += len(keyword)
# Join all snippets for this message
snippet_text = " ... ".join(snippets)
if room.id not in search_results:
search_results[room.id] = {
"room_id": room.id,
"room_name": room.name,
"room_title": room.title,
"snippets": [],
"username": message.username,
"score": 0,
}
search_results[room.id]["snippets"].append(snippet_text)
search_results[room.id]["score"] += score
# Convert the dictionary to a list and sort results by score in descending order

View file

@ -27,7 +27,6 @@
<a href="/chat/{{ result.room_name }}?username={{ username }}">
<b>{{ result.room_name }}</b><br/>
{{ result.room_title or "No title" }}</br>
<!-- <b>Snippets:</b> {{ result.snippets | join(' ... ') }}<br> -->
<b>Score:</b> {{ result.score }}
</a>
</div>