API functionsSearch Store API client
API functions allow you to pass a value directly to an endpoint to receive the JSON response generated by a comparable Query API or Signals API call. Each endpoint has a corresponding stateless API function.
Function value formats
Depending on the function used, you can choose to pass a string or JSON object API parameters. For example, you can pass the query books as a string to the search function:
window.getSearchStore().search('books')
You can also pass the query as a JSON object:
window.getSearchStore().search({query: 'books'})
By using a JSON object, you can make your request more specific. For example, you can specify that you want the third page of results for the query:
window.getSearchStore().search({
query: 'books',
page: 3
})
Examples
- Required parameters
-
You can pass the query
booksas a string to the with thesearchfunction to receive the results JSON response: - Request
window.getSearchStore().searchahead('books')
- Response
{
"queryId" : "fd110486-f168-47c0-a419-1518a4840589",
"hits" : 2,
"docs" : [ {
"type" : "page",
"id" : "441eb3be-7de6-470a-8141-e416a15c7db1-6a092bd4-5098-466c-94aa-40bf68294303-68708807657148371333355819934570439731",
"rank" : 3,
"datasourceLabels" : [ "books" ],
"fields" : {
"document.title" : "Garfield out to lunch / by Jim Davis.",
"document.url" : "https://www.example.com/docs/seattle-books-meta/2375907.html"
}
}, {
"type" : "page",
"id" : "441eb3be-7de6-470a-8141-e416a15c7db1-6a092bd4-5098-466c-94aa-40bf68294303-68708807657148371333355819934570439731",
"rank" : 2,
"datasourceLabels" : [ "books" ],
"fields" : {
"document.title" : "Percy Jackson & the Olympians. Book two, The sea of monsters : the graphic novel / by Rick Riordan ;...",
"document.url" : "https://www.example.com/docs/seattle-books-meta/2921533.html"
}
}]
}
Similarly, you can use the detail function to pass a document ID value to retrieve the details for that document:
- Request
window.getSearchStore().detail
('441eb3be-7de6-470a-8141-e416a15c7db1-6a092bd4-5098-466c-94aa-40bf68294303-68708807657148371333355819934570439731')
- Response
{
"queryId" : "fd110486-f168-47c0-a419-1518a4840589",
"type" : "page",
"id" : "441eb3be-7de6-470a-8141-e416a15c7db1-6a092bd4-5098-466c-94aa-40bf68294303-68708807657148371333355819934570439731",
"datasourceLabels" : [ "books" ],
"fields" : {
"document.title" : "Garfield out to lunch / by Jim Davis.",
"document.body" : "Garfield Fictitious character Comic books strips etc, Cats Comic books strips etc, Cartoons and comi... Garfield out to lunch / by Jim Davis. Info author pubYear publisher bibNumber Davis, Jim, 1945 July 28- 2006. Ballantine Books, 2375907",
"document.url" : "https://www.example.com/docs/seattle-books-meta/2375907.html",
"document.sourceCreateTimestamp" : "2022-04-21T15:39:45Z",
"document.sourceLastModifiedTimestamp" : "2022-04-21T15:39:45Z",
"document.languageCode" : "en"
}
}
If you want to send a click signal, which helps improve relevancy over time, use the clickSignal function. Use the same document ID for both functions. The example below also includes the optional parameter queryId in the clickSignal function.
- Request
window.getSearchStore().clickSignal({documentId: '441eb3be-7de6-470a-8141-e416a15c7db1-6a092bd4-5098-466c-94aa-40bf68294303-68708807657148371333355819934570439731', queryId: 'fd110486-f168-47c0-a419-1518a4840589'})
window.getSearchStore().detail('441eb3be-7de6-470a-8141-e416a15c7db1-6a092bd4-5098-466c-94aa-40bf68294303-68708807657148371333355819934570439731')
- Response
-
No response is given for the
clickSignalfunction. Instead, your application receives a click signal associated to your query and click action.
- Required and optional parameters
-
You can also pass a JSON object, to use additional API parameters and values with the function. For example, to send the query
bookswith thesearchfunction while specifying the results page number and facets returned: - Request
window.getSearchStore().search({
query: 'books',
page: 3,
facets: [{
field: 'type',
values: ['pdf', 'page']
}],
analyticsData: true
})