Skip to main content

Search across two entity types

Search both alerts and a custom Customer entity type in one query, projecting just the fields you need from each. Use this for a unified "did this person appear anywhere" lookup.

import sasvi
from sasvi.search import F, Q

client = sasvi.SVIClient.from_env()

results = (
client.search
.types("alerts", "Customer")
.text("<name-or-email>") # safe-by-default; escapes Lucene
.filter(F.range("score", gte=50) | F.term("status", "ACTIVE"))
.fields("display_label", "score", entity_name="alerts")
.fields("name", "email", entity_name="Customer")
.summary(limit=20)
)

print(repr(results))
# SearchResults(returned=12, total=47)
for hit in results:
print(
hit.entity_type_name,
hit.document_id,
hit.label,
hit.get("score") or hit.get("email"),
)

fields() applies per entity type. The SDK refuses to spread one field projection across mixed types because the schemas differ, so entity_name= disambiguates. Omit it only when exactly one type is in scope. Repeated fields(...) calls with the same entity_name merge their field lists. A different entity_name adds a separate projection for that other type.

Iterate every match​

For larger result sets, use the iterator instead of bumping limit:

for hit in client.search.types("alerts", "Customer").text("foo").iter(page_size=100):
process(hit)

Hydrate hits to bound objects​

for hit in results:
obj = hit.hydrate() # Document or Alert, depending on hit.entity_type_name
if obj is None:
continue
process(obj)

See From search to bound objects for the async fanout version.

Async​

results = await (
client.search.types("alerts", "Customer").text("<name-or-email>").summary_async(limit=20)
)

Go further​