searchServer
Search documents in a collection with optional pagination and total count.
When includeTotalCount=true, runs .collect() on the first page to count all
matching search results. Returns null if count exceeds 32k documents.
args
Search arguments including query, filters, pagination, and count options
Example
Section titled “Example”// With pagination and count (first page only)const result = await search({ ctx, collection: "posts", query: "react hooks", searchIndexName: "search_posts", searchField: "title", paginationOpts: { numItems: 100, cursor: null }, includeTotalCount: true,});// result: { page: [...], continueCursor: "...", isDone: false, totalCount: 42 }Call Signature
Section titled “Call Signature”searchServer<
DataModel,TCollectionSlug,TPopulate,D>(args):Promise<DocReturnItem<TCollectionSlug,TPopulate,D>[]>
Defined in: packages/core/src/api/search/server.ts:84
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/api/search/server.ts:98
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>>>