take(count)

Fetches a specific number of search results.

If count is not specified, all results are returned.

Params

  • count (Number) – maximum number of search results to be returned.

Returns

Array<Obj> – An array of Obj instances matching the search criteria. If count is given, the length of the array is less than or equal to count

Examples

Perform a full-text search for “easy”, limiting the result set to 20 CMS objects:

Copy
topResults = Scrivito.Obj.where("*", "containsPrefix", "easy").take(20);

Fetch the latest three blog posts:

Copy
allPosts = Scrivito.Obj.where('_objClass', 'equals', 'BlogPost');
latestPosts = allPosts.order('_createdAt', 'desc').take(3);

Since take() returns an array, there is no need to use the spread operator:

Copy
allObjs = Scrivito.Obj.all().take();

See also

first, toArray