Returns a list of search results matching your query.
By default, it returns 20 results. You can paginate the results using limit
and offset
parameters. In any case, a maximum number of 100 results is returned.
The query string to search
The build trigger ID on which the search will be performed
Restrict the search on one locale
Maximum number of results to return (defaults to 20, maximum is 100)
Number of records to offset for the search
const { SiteClient } = require('datocms-client');async function run() {const client = new SiteClient('YOUR-API-TOKEN');const searchResults = await client.searchResults.all({q: 'query',build_trigger_id: '44',locale: 'it',limit: 20,offset: '60'});searchResults.forEach((searchResult) => {console.log(searchResult);});// or, if you want to fetch all the pages with just one call:const searchResults = await client.searchResults.all({q: 'query',build_trigger_id: '44',locale: 'it',limit: 20,offset: '60'},{allPages: true});searchResults.forEach((searchResult) => {console.log(searchResult);});}run();
> node example.js{"id": "312","title": "My Page","bodyExcerpt": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed eiusmod","url": "Smith","score": 11.3,"highlight": {"title": ["Foo <em>bar</em> qux"],"body": ["Foo <em>bar</em> qux"]}}