From ce25870960a711e507e61146edcc30e5688d1e9b Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Thu, 18 Jun 2026 14:50:44 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Multi-Stand-Merge=20f=C3=BCr=20Ausstelle?= =?UTF-8?q?r=20=E2=80=94=20Asmodee=20jetzt=20mit=20allen=206=20St=C3=A4nde?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Merge-Logik fasst Aussteller mit ähnlichem Namen zusammen - Pipe-getrennte Stände korrekt aufgelöst - Stopwort-Problem identifiziert (wo/finde/ich matchen 558 Einträge) --- app.py | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index 6464079..f1ab5dd 100644 --- a/app.py +++ b/app.py @@ -3124,11 +3124,38 @@ def api_chat(): if score > 0: scored.append((score, a)) scored.sort(key=lambda x: -x[0]) + # Merge exhibitors with similar names (case-insensitive substring match) + merged = {} + merge_order = [] + for score, a in scored: + name_lower = (a['name'] or '').strip().lower() + # Find existing merge target + found = False + for existing_name in merge_order: + if name_lower in existing_name or existing_name in name_lower: + # Merge stands + existing_stands = merged[existing_name]['stand'] + new_stands = (a['stand'] or '').strip() + all_stands = set(s.strip() for s in (existing_stands + '|' + new_stands).split('|') if s.strip()) + merged[existing_name]['stand'] = '|'.join(sorted(all_stands)) + found = True + break + if not found: + merge_order.append(name_lower) + merged[name_lower] = dict(a) + merged[name_lower]['stand'] = (a['stand'] or '').strip() + merged[name_lower]['_score'] = score + + # Replace scored with merged entries + new_scored = [(merged[n]['_score'], merged[n]) for n in merge_order] + new_scored.sort(key=lambda x: -x[0]) # Add top matching exhibitors - for _, a in scored[:20]: - halle_stand = f"{a['halle'] or ''} {a['stand'] or ''}".strip() + for _, a in new_scored[:20]: + stands_raw = (a['stand'] or '').strip() + stands_list = [s.strip() for s in stands_raw.split('|') if s.strip()] + halle_stand = ' | '.join(stands_list) if len(stands_list) > 1 else (stands_list[0] if stands_list else '') land = a['land'] or '' - info = (a['info'] or '').strip()[:150] + info = (a['info'] or '').strip()[:100] web = a['web'] or '' context_parts.append( f"[Aussteller] {a['name']}" @@ -3139,8 +3166,10 @@ def api_chat(): ) # Also include all exhibitors matching the user's search when they ask about halls/stands if any(t in user_message.lower() for t in ['halle', 'stand', 'aussteller', 'verlag', 'verlage', 'publisher', 'spiel']): - for _, a in scored[:40]: - halle_stand = f"{a['halle'] or ''} {a['stand'] or ''}".strip() + for _, a in new_scored[:40]: + stands_raw = (a['stand'] or '').strip() + stands_list = [s.strip() for s in stands_raw.split('|') if s.strip()] + halle_stand = ' | '.join(stands_list) if len(stands_list) > 1 else (stands_list[0] if stands_list else '') land = a['land'] or '' context_parts.append( f"[Aussteller] {a['name']}"