searchServer
Search documents in a collection with optional pagination and total count.
Pass paginationOpts: { ..., totalDocs: true } to also count matching
search results on the first page (cursor: null) only — same
take(countLimit + 1) cap and totalDocs/totalDocsCapped contract as
find (Design Decision 35); see its own JSDoc for the full explanation.
args
Search arguments including query, filters, pagination, and count options
Example
Section titled “Example”// With pagination and a first-page countconst result = await search({ ctx, collection: "posts", query: "react hooks", searchIndexName: "search_posts", searchField: "title", paginationOpts: { numItems: 100, cursor: null, totalDocs: true },});// result: { page: [...], continueCursor: "...", isDone: false, totalDocs: 42, totalDocsCapped: false }Call Signature
Section titled “Call Signature”searchServer<
DataModel,TCollectionSlug,TPopulate,D>(args):Promise<DocReturnItem<TCollectionSlug,TPopulate,D>[]>
Defined in: packages/core/src/collections/api/search/server.ts:124
Type Parameters
Section titled “Type Parameters”DataModel
Section titled “DataModel”DataModel extends GenericDataModel
TCollectionSlug
Section titled “TCollectionSlug”TCollectionSlug extends string
TPopulate
Section titled “TPopulate”TPopulate extends PopulateShape<TCollectionSlug> = Record<string, never>
D extends number = 0
Parameters
Section titled “Parameters”SearchServerArgs<DataModel, TCollectionSlug, TPopulate, D> & object
Returns
Section titled “Returns”Promise<DocReturnItem<TCollectionSlug, TPopulate, D>[]>
Call Signature
Section titled “Call Signature”searchServer<
DataModel,TCollectionSlug,TPopulate,D>(args):Promise<PaginationResult<DocReturnItem<TCollectionSlug,TPopulate,D>>>
Defined in: packages/core/src/collections/api/search/server.ts:138
Type Parameters
Section titled “Type Parameters”DataModel
Section titled “DataModel”DataModel extends GenericDataModel
TCollectionSlug
Section titled “TCollectionSlug”TCollectionSlug extends string
TPopulate
Section titled “TPopulate”TPopulate extends PopulateShape<TCollectionSlug> = Record<string, never>
D extends number = 0
Parameters
Section titled “Parameters”SearchServerArgs<DataModel, TCollectionSlug, TPopulate, D> & object
Returns
Section titled “Returns”Promise<PaginationResult<DocReturnItem<TCollectionSlug, TPopulate, D>>>