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 (Max: 100, default: 20)
Number of records to offset for the search
const SiteClient = require('datocms-client').SiteClient;const client = new SiteClient('YOUR-API-TOKEN');client.searchResults.all({q: 'query',build_trigger_id: '44',locale: 'it',limit: '50',offset: '60'}).then((searchResults) => {searchResults.forEach((searchResult) => {console.log(searchResult);});}).catch((error) => {console.error(error);});// if you want to fetch all the pages with just one call:client.searchResults.all({q: 'query',build_trigger_id: '44',locale: 'it',limit: '50',offset: '60'}, {allPages: true}).then((searchResults) => {searchResults.forEach((searchResult) => {console.log(searchResult);});})
> 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"]}}