From 8501eef2f1524823d98f750393101248f0bb32f7 Mon Sep 17 00:00:00 2001 From: Maciej Pienczyn Date: Fri, 20 Mar 2026 14:27:25 +0100 Subject: [PATCH] feat(search): add portal users to search results alongside KRS persons Search by name now finds registered portal users with avatar, company, and chamber role badge. Deduplicates with KRS person results. Co-Authored-By: Claude Opus 4.6 (1M context) --- blueprints/public/routes.py | 21 ++++++++++++++++++ templates/search_results.html | 42 +++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/blueprints/public/routes.py b/blueprints/public/routes.py index 00a6c2e..8bf4551 100644 --- a/blueprints/public/routes.py +++ b/blueprints/public/routes.py @@ -824,10 +824,31 @@ def search(): logger.info(f"Search '{query}': {len(people_results)} people found") + # Also search portal users (not yet in people_results via person_id) + user_results = [] + if query and len(query) >= 2: + q = f"%{query}%" + matched_users = db.query(User).filter( + User.is_active == True, + User.is_verified == True, + User.name.ilike(q) + ).limit(20).all() + + # Exclude users who are already in people_results (via person_id) + people_person_ids = {p.id for p in people_results} + for u in matched_users: + if u.person_id and u.person_id in people_person_ids: + continue # already shown as Person + user_results.append(u) + + if user_results: + logger.info(f"Search '{query}': {len(user_results)} portal users found") + return render_template( 'search_results.html', companies=companies, people=people_results, + user_results=user_results, query=query, category_id=category_id, result_count=len(companies), diff --git a/templates/search_results.html b/templates/search_results.html index 786f49f..e6d7965 100755 --- a/templates/search_results.html +++ b/templates/search_results.html @@ -242,7 +242,7 @@ {% if query %}

Znaleziono {{ companies|length }} firm - {%- if people %} i {{ people|length }} osób{% endif %} + {%- if people or user_results %} i {{ (people|length) + (user_results|length) }} osób{% endif %} dla zapytania: "{{ query }}"

{% else %} @@ -283,6 +283,44 @@ {% endif %} +{% if user_results %} + +{% endif %} + {% if companies %}
{% for company in companies %} @@ -341,7 +379,7 @@
{% endif %} -{% if not companies and not people %} +{% if not companies and not people and not user_results %}