From 079d9880345a29def99cd4b3a2e0b3a6e5c3230c Mon Sep 17 00:00:00 2001 From: Lars Date: Sun, 28 Dec 2025 11:57:49 +0100 Subject: [PATCH] bug fix --- app/frontend/ui_graph_service.py | 34 ++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/app/frontend/ui_graph_service.py b/app/frontend/ui_graph_service.py index 17f7fc2..a66b015 100644 --- a/app/frontend/ui_graph_service.py +++ b/app/frontend/ui_graph_service.py @@ -19,6 +19,7 @@ class GraphExplorerService: self.notes_col = f"{prefix}_notes" self.chunks_col = f"{prefix}_chunks" self.edges_col = f"{prefix}_edges" + self._note_cache = {} # Cache für Note-Payloads self._note_cache = {} def get_note_with_full_content(self, note_id): @@ -459,8 +460,20 @@ class GraphExplorerService: # Der Teil vor dem ersten "#" ist der Titel possible_title = ref_str.split("#")[0].strip() if possible_title: + # Normalisierungs-Funktion (wie in _find_connected_edges) + def normalize_title(t): + if not t: + return "" + t = re.sub(r'\s*\([^)]*\)', '', t) + t = re.sub(r'\s*\d{4}[\s–\-]*\d{0,4}', '', t) + t = re.sub(r'^(Mein|Meine)\s+', '', t, flags=re.IGNORECASE) + t = re.sub(r'\s+', ' ', t).strip() + return t.lower() + + possible_title_norm = normalize_title(possible_title) + try: - # Suche nach exaktem Titel-Match + # Versuch 3a: Exakte Titel-Suche res, _ = self.client.scroll( collection_name=self.notes_col, scroll_filter=models.Filter(must=[models.FieldCondition(key="title", match=models.MatchValue(value=possible_title))]), @@ -472,16 +485,25 @@ class GraphExplorerService: except Exception: pass - # Fallback: Text-Suche für Fuzzy-Matching try: + # Versuch 3b: Text-Suche (kann Teilmatches finden) res, _ = self.client.scroll( collection_name=self.notes_col, scroll_filter=models.Filter(must=[models.FieldCondition(key="title", match=models.MatchText(text=possible_title))]), - limit=1, with_payload=True + limit=10, with_payload=True # Mehr Ergebnisse für Fuzzy-Matching ) - if res and res[0].payload: - self._note_cache[res[0].payload['note_id']] = res[0].payload - return res[0].payload + if res: + # Prüfe alle Ergebnisse mit normalisiertem Vergleich + for r in res: + if r.payload: + note_title = r.payload.get("title", "") + note_title_norm = normalize_title(note_title) + if note_title_norm and possible_title_norm and len(possible_title_norm) > 5: + if (note_title_norm == possible_title_norm or + note_title_norm.startswith(possible_title_norm) or + possible_title_norm.startswith(note_title_norm)): + self._note_cache[r.payload['note_id']] = r.payload + return r.payload except Exception: pass