basalt / search/src / Search
Class: Search
Defined in: search/src/search.ts:263
Constructors
Constructor
> new Search(options?, tenancyActive?): Search
Defined in: search/src/search.ts:271
Parameters
options?
SearchServiceOptions = {}
tenancyActive?
() => boolean
Whether the host app registered @basaltkit/tenancy. searchPlugin wires this to the container's 'tenancy:active' metadata marker — a signal, not an import, so this generic package never depends on the opt-in SaaS layer. Defaults to false (single-tenant).
Returns
Search
Methods
bulk()
> bulk(indexName, documents): Promise<void>
Defined in: search/src/search.ts:293
Parameters
indexName
string
documents
Returns
Promise<void>
index()
> index(indexName, document): Promise<void>
Defined in: search/src/search.ts:289
Parameters
indexName
string
document
Returns
Promise<void>
reindex()
> reindex(indexName, options?): Promise<number>
Defined in: search/src/search.ts:381
Rebuilds an index from the rules that keep it current.
A rule fed by events knows only what was created after it existed, so an application adding search to data it already has gets a box that returns nothing for everything old — and an empty result is indistinguishable from "there is none".
The rebuild goes through the rule's own document, so a record cannot be described one way when it is created and another way when it is rebuilt. That drift is quiet and nasty: the same search returns different things depending on whether a record predates the last rebuild.
Scope (ReindexOptions): inside a tenant context, or with { tenantId }, only that tenant's documents are cleared and rewritten — the others are untouched, so one call per tenant is safe. { all: true } (outside a tenant context) clears and rebuilds the whole index. With @basaltkit/tenancy registered and no tenant context, one of the two is required; a single-tenant app rebuilds its whole index by default.
Returns how many documents were written.
Parameters
indexName
string
options?
ReindexOptions = {}
Returns
Promise<number>
remove()
> remove(indexName, id, tenantId?): Promise<void>
Defined in: search/src/search.ts:297
Parameters
indexName
string
id
string
tenantId?
string
Returns
Promise<void>
search()
> search(indexName, q, options?): Promise<SearchResult>
Defined in: search/src/search.ts:301
Parameters
indexName
string
q
string
options?
SearchOptions = {}
Returns
Promise<SearchResult>