Ashutosh Thakur
08/28/2025, 3:21 PM{
"familyQuantity": 2,
"id": "680cde5de2443bb2a1bf70c1::990J0M53M00-010",
"location": [27.596642, 75.183688], // geopoint
"rootPartNumber": "990J0M53M00-010",
"supplierId": "680cde5de2443bb2a1bf70c1",
"supplierInfo": "supplierName::680cde5de2443bb2a1bf70c1::27.596642,75.183688"
}
Schema (relevant fields)
{
"name": "supplierinventories_rpn",
"fields": [
{
"name": "rootPartNumber",
"type": "string",
"facet": true
},
{
"name": "familyQuantity",
"type": "int32"
},
{
"name": "location",
"type": "geopoint"
},
{
"name": "supplierId",
"type": "string",
"facet": true
},
{
"name": "supplierInfo",
"type": "string",
"facet": true
}
]
}
Current query
(De-URL-encoded for readability; API key redacted)
curl --location --globoff \
'https://<typesense-host>/collections/supplierinventories_rpn/documents/search
?q=*
&query_by=rootPartNumber
&facet_by=supplierInfo
&filter_by=(
(rootPartNumber:=[69510M68P00] && familyQuantity:>=2) ||
(rootPartNumber:=[69100M75T40] && familyQuantity:>=1)
)
&& location:(27.1598238,75.7364393,100 km)
&max_facet_values=1000
&per_page=1000' \
-H 'x-typesense-api-key: <REDACTED>'
What I’m trying to achieve
1. Distance slabs for each requested part:
◦ ≤ 10 km
(Slab A)
◦ > 10 km
(Slab B)
◦ not found (Slab C)
2. Ability to compute/compare supplier plans:
◦ Plan A: multiple suppliers within 10 km (possibly opposite directions)
◦ Plan B: one supplier outside 10 km who covers all parts
◦ Choose the lowest LMD cost plan (e.g., cost model using base fee + km + multi-stop penalty).
Questions for the community
1. Outside radius filter: Is there a built-in way in filter_by
to express “outside 10 km” (NOT within a circle)? Or is the recommended approach to query within MAX radius and then bin client-side using the distance value returned from sort_by=location(lat,lng):asc
?
2. Ring query (R1–R2): Can I express a ring (e.g., between 10 km and 100 km) natively, or should I do two queries (≤100 km) minus (≤10 km)?
3. Per-hit distance: Is using &sort_by=location(lat,lng):asc
the canonical way to get a per-hit distance in the response for binning (Slab A vs Slab B)? Any SDK-specific tips here?
4. Faceting + geo: Any best practices when combining facet_by
(e.g., supplierId
or supplierInfo
) with a geo filter for large result sets (performance, limits, pagination)?
5. Alternative geo shapes: Would using polygon filters be preferable for some cities/areas versus a simple radius (e.g., matching municipal boundaries)? And still, there’s no “NOT polygon” support, correct?
6. Sorting helpers: I noticed exclude_radius
in geo sort helps prioritize outside-radius hits, but it doesn’t filter them out. Is that the intended use (ranking only), and filtering still needs to be done via separate queries / client logic?
What we’ll do with the results
• Produce an API response with counts by slab, the “not found” list, and a recommended plan (either multi-supplier ≤10 km or single farther supplier) based on our cost model.
• For now, we’ll keep the cost optimization on our server; Typesense handles the filtering/sorting.
Any guidance, examples, or gotchas would be super helpful. Thanks!
cc @Sahil Rally @Atishay Jain