Use this method to search results related to a question:
client.search(query:String, options:Object).then(function(response){
//...
});
Name | Type | Description |
---|---|---|
query | string or array of strings | Question(s) to be responded with contents in the Knowledge Base. |
Name | Type | Default | Description |
---|---|---|---|
categoryId | string | 0 | Category identifier from the Knowledge instance's Knowledge Base. Category id 0 is reserved for the root. This parameter allows a string with the categories separated by commas. Example: 1,4,5 will search in the categories 1, 4 and 5. |
length | integer | 5 | Maximum number of items that may be returned in collection. Minimum:1. Max:100 |
splitQuery | boolean | 0 | If splitQuery is 1, the query is always split. If splitQuery is 0, the query is managed as usual. |
type | string | search | Allow to track the search event using a specific log type. Accepted values are search , contact and instant . |
This method calls the Knowledge API’s POST /search
endpoint. Please refer to the Responses section of that endpoint on the Knowledge API Routes page for the response format.
Get maximum 10 contents matching the query 'movies'.
// Only query string
client.search('movies').then(function(response){
response.data.results.forEach(function(result) {
console.log(`Result(${result.id}): ${result.title}`);
});
});
Get maximum 20 contents matching the query 'star wars' belonging to category 10.
// With parameters
client.search('star wars', {
categoryId: '10'
length: 20
}).then(function(response){
response.data.results.forEach(function(result) {
console.log(`Result(${result.id}): ${result.title}`);
});
});