Update unified search providers for unified contacts model (company queries contacts with type=company)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Contact search provider."""
|
||||
"""Contact search provider — works with unified contacts table."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -9,13 +9,11 @@ from typing import Any
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.contact import Contact
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ContactSearchProvider:
|
||||
"""Search provider for Contact entities."""
|
||||
"""Search provider for Contact entities (all types)."""
|
||||
|
||||
entity_type = "contact"
|
||||
|
||||
@@ -80,7 +78,8 @@ class ContactSearchProvider:
|
||||
"""Get text for embedding generation."""
|
||||
sql = text(
|
||||
"""
|
||||
SELECT first_name, last_name, email, phone, mobile, notes
|
||||
SELECT displayname, name, firstname, surname, email_1, email_2,
|
||||
phone_1, phone_2, mailing_city, tags, contact_warning
|
||||
FROM contacts
|
||||
WHERE id = :eid AND tenant_id = :tid
|
||||
"""
|
||||
@@ -90,32 +89,36 @@ class ContactSearchProvider:
|
||||
if not row:
|
||||
return ""
|
||||
parts = [
|
||||
row.get("first_name", ""),
|
||||
row.get("last_name", ""),
|
||||
row.get("email", ""),
|
||||
row.get("phone", ""),
|
||||
row.get("mobile", ""),
|
||||
row.get("notes", ""),
|
||||
row.get("displayname", ""),
|
||||
row.get("name", ""),
|
||||
row.get("firstname", ""),
|
||||
row.get("surname", ""),
|
||||
row.get("email_1", ""),
|
||||
row.get("email_2", ""),
|
||||
row.get("phone_1", ""),
|
||||
row.get("phone_2", ""),
|
||||
row.get("mailing_city", ""),
|
||||
row.get("tags", ""),
|
||||
]
|
||||
return " ".join(str(p) for p in parts if p)
|
||||
|
||||
def to_search_result(self, entity: object) -> dict[str, Any]:
|
||||
"""Convert contact to search result dict."""
|
||||
if isinstance(entity, dict):
|
||||
first = entity.get("first_name", "")
|
||||
last = entity.get("last_name", "")
|
||||
email = entity.get("email", "")
|
||||
displayname = entity.get("displayname", "")
|
||||
email = entity.get("email_1", "")
|
||||
entity_id = str(entity.get("id", ""))
|
||||
contact_type = entity.get("type", "")
|
||||
else:
|
||||
first = getattr(entity, "first_name", "")
|
||||
last = getattr(entity, "last_name", "")
|
||||
email = getattr(entity, "email", "")
|
||||
displayname = getattr(entity, "displayname", "")
|
||||
email = getattr(entity, "email_1", "")
|
||||
entity_id = str(getattr(entity, "id", ""))
|
||||
contact_type = getattr(entity, "type", "")
|
||||
return {
|
||||
"entity_type": self.entity_type,
|
||||
"entity_id": entity_id,
|
||||
"title": f"{first} {last}".strip(),
|
||||
"title": displayname,
|
||||
"snippet": email or "",
|
||||
"score": 0.0,
|
||||
"data": {},
|
||||
"data": {"type": contact_type},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user