25 lines
804 B
Python
25 lines
804 B
Python
from fastapi import APIRouter
|
|
from rapidfuzz import fuzz
|
|
|
|
from app.clickhouse import get_client
|
|
from app.schemas import ContactMatchQuery
|
|
|
|
router = APIRouter(prefix="/contacts", tags=["contacts"])
|
|
|
|
|
|
@router.post("/match")
|
|
def match_contact(payload: ContactMatchQuery):
|
|
"""Placeholder pentru entity resolution: cauta dupa email/telefon normalizat,
|
|
apoi scoreaza candidatii cu rapidfuzz pentru potriviri apropiate."""
|
|
client = get_client()
|
|
if payload.email:
|
|
result = client.query(
|
|
"SELECT * FROM contacts WHERE email = {email:String} LIMIT 5",
|
|
parameters={"email": payload.email},
|
|
)
|
|
return {"matches": result.result_rows}
|
|
return {"matches": []}
|
|
|
|
|
|
def score_name_similarity(a: str, b: str) -> float:
|
|
return fuzz.token_sort_ratio(a, b)
|