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  integer  Optional

    Maximum number of results to return (defaults to 20, maximum is 100)

    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');
    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();
    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"
    ]
    }
    }