Search results
This page shows how pagination works when performing search requests.
Prerequisites
- You’re familiar with the concepts that are described on the Platform overview page.
- You’ve already created an index, and the Marengo video understanding engine is enabled for this index.
- You’ve already uploaded at least one video, and the platform has finished indexing it.
Examples
The SDKs provide two distinct methods, each suited to different use cases and requirements. Selecting the most efficient method is important for optimizing the performance of your application:
- Direct pagination: Choose this method mainly when the total number of items is manageable, or you must fetch a single page of results.
- Iterative pagination: Choose this method mainly when your application must retrieve a large number of items.
Direct pagination
To retrieve the first page of results, invoke the query
method of the search
object. The response will contain the following properties:
data
: An array containing the first page of resultspage_info
: An object containing information about pagination:limit_per_page
: The maximum number of results per page.total_results
: The total number of results.page_expires_at
: The time when the current page expires.next_page_token
: A token you can use to retrieve the results on the next page. The platform doesn’t return this field when you’ve reached the end of the datasetprev_page_token
: A token you can use to retrieve the results on the previous page. The platform doesn’t return this field when you’ve retrieved the first page.
pool
: An object that contains details about the index you queried.
To retrieve a specific page of results, invoke the by_page_token
method of the search
object, passing the next_page_token
property of the page_info
object as the value of the page_token
parameter. The response will be similar to the one returned when retrieving the first page of results. When the platform does not return the next_page_token
field, you’ve reached the end of the dataset.
Retrieve the first page of results
To retrieve the first page of results, invoke the query
method of the search
object:
The example output below was truncated for brevity:
Retrieve a specific page of results
To retrieve a specific page of results, invoke the by_page_token
method of the search
object, passing the next_page_token
property of the page_info
object as the value of the page_token
parameter:
Specify limits
The following example code iterates over results and and uses the page_limit
parameter to specify a limit of 5 items on each page:
Iterative pagination
To retrieve the first page of results, invoke the query
method of the search
object. To retrieve subsequent pages of results, use the iterator protocol in Python or the async iterator protocol in JavaScript.
Retrieve the first page of results
The following example code retrieves the first page of results by calling the query
method of the search
object:
The example output below was truncated for brevity:
Iterate over the results
The following example code iterates over results by invoking the next
function in Python or the next
method of the object containing the search results in JavaScript:
Specify limits
The following example code iterates over results and and uses the page_limit
parameter to specify a limit of 5 items on each page:
Use pagination in conjunction with grouping
When the response is grouped by video, you can use the page_limit
parameter to specify the number of videos the platform will return on each page. The following example code sets the page limit to three and specifies that the result must be grouped by video: