Choose your language:
    Search for results

    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.

    Query parameters
    q  string  Optional

    The query string to search

    buildTriggerId  string  Optional

    The build trigger ID on which the search will be performed

    locale  string  Optional

    Restrict the search on one locale

    limit  string  Optional

    Maximum number of results to return (Max: 100, default: 20)

    offset  string  Optional

    Number of records to offset for the search

    Returns
    Returns an array of search_result objects.

    Examples

    Example code:
    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);
    });
    })
    Returned output:
    > 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"
    ]
    }
    }