From 2026de4bcbdd41debb5f137fe4a852b3d431bfc9 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Thu, 3 Dec 2026 00:20:54 +0100 Subject: [PATCH] fix: note search shows no excerpt when the match is deep inside a note (#35561) Searching Notes for words that appear far into a note listed the note but showed no excerpt next to its title, because the search results only carried the start of each note. The results now carry the part of the note around the first match instead, and each result stays as small as before, so the words around the match show up wherever they are in the note. While searching, the grid preview of such a note starts near the match too. Matches near the start and matches only in the title look the same as before. Fixes #35556 --- backend/open_webui/routers/notes.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/routers/notes.py b/backend/open_webui/routers/notes.py index db6969d772..947674ca41 100644 --- a/backend/open_webui/routers/notes.py +++ b/backend/open_webui/routers/notes.py @@ -69,8 +69,12 @@ def truncate_note_data(data: Optional[dict], max_length: int = 1000, query: str return data page = matching_page(data, query) md = page['content'].get('md') or '' + text = md.lower() + hits = [text.find(term) for term in query.lower().split() if term in text] + # Start a little before the first search hit so the list can show the words around it. + start = max(0, min(hits) - 100) if hits else 0 return { - 'content': {'md': md[:max_length]}, + 'content': {'md': md[start : start + max_length]}, 'page_count': len(data.get('pages') or [None]), 'page_id': page['id'], 'page_title': page['title'],