UNPKG

@lableb/javascript-sdk

Version:

Lableb cloud search client for javascript

168 lines (124 loc) 5.2 kB
# Lableb's Client | Autocomplete Feedback API After creating a new instance of Lableb's Client, ```js const lablebClient = LablebClient({ APIKey: process.env.API_KEY, platformName: process.env.PLATFORM_NAME, }); ``` You can access the autocomplete feedback functions at `lablebClient.feedback.autocomplete`, where you have two types of feedbacks functions: `single` and `batch` Use `lablebClient.feedback.autocomplete.single` to send one feedback at a time to Lableb, and use `lablebClient.feedback.autocomplete.batch` to send many feedbacks at the same time to Lableb. # Options ## Single Feedback | field | type | description | | ------------------ | ------ | ----------- | | documentFeedback* | object | feedback object(see below for details) | | platformName | string | your platform name in small-letters | | indexName | string | the used index name for the autocomplete function | | autocompleteHandler| string | the used autocomplete handler for the autocomplete function | | APIKey | string | your autocomplete API Key copied from [Lableb Dashboard](https://dashboard.lableb.com) | ## Content of the feedback object: `documentFeedback` | field | type | description | | --------- | ------ | ----------- | | query* | string | query used in the autocomplete function | | itemId | string | document"s id clicked on or chosen by the user | | itemOrder | string | document"s order clicked on or chosen by the user | | url | string | document"s url clicked on or chosen by the user | | sessionId | string | uniques session id of the end user | Example ```js await lablebClient.feedback.autocomplete.single({ documentFeedback: { query: "water", itemId: "37", itemOrder: "2", sessionId: "3mn6baLA", url: "https://example.com/items/37" } }); ``` ## Batch Feedback Its options basically the same as `single` feedback options except using `documentsFeedbacks` as an array instead of `documentFeedback` as an object. | field | type | description | | ------------------- | ------ | ----------- | | documentsFeedbacks* | array | array of feedback object(see below for details) | | platformName | string | your platform name in small-letters | | indexName | string | the used index name for the autocomplete function | | autocompleteHandler | string | the used autocomplete handler for the autocomplete function | | APIKey | string | your autocomplete API Key copied from [Lableb Dashboard](https://dashboard.lableb.com) | Example ```js await lablebClient.feedback.autocomplete.batch({ documentsFeedbacks: [ { query: "water", itemId: "37", itemOrder: "2", sessionId: "3mn6baL", url: "https://example.com/items/37" }, { query: "food", itemId: "421", itemOrder: "8", sessionId: "vA2ml2a", url: "https://example.com/items/421" }, { query: "cold", itemId: "687", itemOrder: "5", sessionId: "gavz@1m", url: "https://example.com/items/687" } ] }); ``` ------------------ #### Alternative syntax for async code ```js let lablebClient = LablebClient({ APIKey: process.env.API_KEY, platformName: process.env.PLATFORM_NAME, }); lablebClient.feedback.autocomplete.single({ documentFeedback: { query: "water", itemId: "37", itemOrder: "2", sessionId: "3mn6baLA", url: "https://example.com/items/37" } }) .then(() => { console.log("Autocomplete feedback has been sent."); }) .catch(console.error); }); ``` --------------------------- #### Real Usage Example ```js const { code, response, time } = await lablebClient.autocomplete(options); const autocompleteResults = response.results; ``` Autocomplete results is an array of objects representing your platform documents(data), each document automatically has a `feedback` object in it that contains everything you need to send within the feedback request. ```json [ { id: "8112-cmb", feedback: { query: "water", userCountry: "AE", ... }, ...fields }, { id: "9142-pam", feedback: { query: "water", userCountry: "AE", ... }, ...fields }, { id: "2712-alq", feedback: { query: "water", userCountry: "AE", ... }, ...fields }, { id: "2522-sgm", feedback: { query: "water", userCountry: "AE", ... }, ...fields }, { id: "8156-baj", feedback: { query: "water", userCountry: "AE", ... }, ...fields } ] ``` Now you can use the `feedback` object returned to be sent with the autocomplete feedback request ```js const { code, response, time } = await lablebClient.autocomplete(options); const autocompleteResults = response.results; // later on, the end user clicks on the first result const userInteraction = autocompleteResults[0]; await lablebClient.feedback.autocomplete.single({ documentFeedback: userInteraction.feedback }); ```