Recommendations
Trending
Items rising in views, clicks or purchases over a recent window. The right fallback for anonymous visitors and empty-result pages.
GET /recommendations/trending returns items whose engagement is rising sharpest over the trailing window. Optionally filtered by category, brand, or any indexed facet.
Request
GET /recommendations/trending?indexId=<id>&window=7d&limit=10
Authorization: Bearer <api-key>| Param | Type | Required | Notes |
|---|---|---|---|
indexId | string | yes | Source index. |
window | string | no | 1h, 24h, 7d, 30d. Default 24h. |
limit | number | no | 1–50, default 10. |
filterBy | string | no | Typesense filter_by — e.g. category:Shoes. |
Response
{
"items": [
{ "id": "sku-9001", "score": 4.2, "data": { ... } }
],
"window": "24h",
"engine": "trending"
}score is velocity — clicks-per-impression ratio over the window divided by the same ratio in the previous window. A score of 4.2 means this item is gaining attention 4.2× faster than its baseline.
When to use
- Anonymous homepage — No
userId, no anchor item. - Empty results fallback —
POST /searchreturned 0 hits; show trending in the same category. See the no-results recipe. - Editorial widget — "What's hot this week."
Window choice
| Window | Best for |
|---|---|
1h | Live events, breaking news, flash-sale dashboards. |
24h | News sites, dynamic ecommerce, default for most surfaces. |
7d | Long-tail stores, B2B catalogues — smooths out daily noise. |
30d | Bestseller rails — closer to "popular" than to "trending". |
Latency
p95 ~40 ms on Pro. The trending bucket is precomputed every 5 minutes per window; API is a hash lookup.
Code path
packages/api/modules/recommendations/procedures/trending.ts.