Install
Quickstart
new Raily(options)
Construct once and reuse it.
search(query, options?)
Returns
Promise<SearchHit[]> — or Promise<SearchResult> when explain: true (see
Debugging empty results).
Debugging empty results
A search can legitimately return nothing — and a bare[] doesn’t say why. Pass
{ explain: true } to get the endpoint’s own message plus a hint:
SearchHit
Working with fields
fields is a flat { name: value } map of the display fields configured on your source —
e.g. title, text, author, published_date. Read a value by name:
", ". To see what your source exposes, log
the whole map once:
hit.raw.
Errors
RailyAuthError extends RailyError, so check it first.
Concurrency
search returns a promise — fan out with Promise.all:
Recipe: a search route
Troubleshooting
No results came back (empty array)
No results came back (empty array)
An empty array is a valid answer, not an error. The usual causes, in order:
- The query is too generic. Category words like
"articles","news", or"posts"carry no topical signal, so nothing matches strongly enough to return. Search a specific topic ("battery recycling", not"articles"). - A freshness filter. Queries that imply recency (
"latest","news") apply apublished_datecutoff — if your source’s data is older, that can remove everything. Drop the recency words or widen the range. - Your source has no data yet. A brand-new source may not have finished indexing yet. Search a term you know is in the data; if that’s also empty, confirm the source has finished indexing in the Raily app.
{ explain: true } to see which it is:“API key was rejected for this endpoint” (RailyAuthError)
“API key was rejected for this endpoint” (RailyAuthError)
The key is missing, wrong, expired, or was issued for a different endpoint. A key only
works against the endpoint it was created on. Re-check
RAILY_API_KEY and RAILY_ENDPOINT.Searches are slow or time out
Searches are slow or time out
Raise
timeoutMs and retry. Reuse one client instead of constructing one per request.