Skip to main content

Install

Quickstart

Get the endpoint URL and key from your endpoint’s API access panel — see the SDK 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:
Or have the client log a one-line hint on every empty result during development:

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:
A field with multiple values is joined with ", ". To see what your source exposes, log the whole map once:
Need the full original result (every field, untrimmed)? It’s on 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

An empty array is a valid answer, not an error. The usual causes, in order:
  1. 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").
  2. A freshness filter. Queries that imply recency ("latest", "news") apply a published_date cutoff — if your source’s data is older, that can remove everything. Drop the recency words or widen the range.
  3. 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.
Use { explain: true } to see which it is:
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.
Raise timeoutMs and retry. Reuse one client instead of constructing one per request.