UNPKG

@lableb/javascript-sdk

Version:

Lableb cloud search client for javascript

130 lines (75 loc) 3.12 kB
# Lableb's Client | Search By ID 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 use the search function as ```js const { code, response, time } = await lablebClient.searchById(options); const searchResult = response; ``` ---------------------- ## Options All options has types validation built in for you, in case you mis-typed something, And if you're using [typescript](https://github.com/microsoft/TypeScript) the code editor will tell you for any mis-typed argument instantly. Options are of three categories: - search specific - globally shared, which can be used to override any global option for this search function call - user related ---------------------- ### Search specific options | field | type | description | | ------- | ------ | ----------- | | id* | string | document id | ---------------------- ### Globally shared options Passing these options to the search function will override any globally passed options to the main `LablebClient` of the same name. | field | type | description | | ------------- | ------ | ----------- | | platformName | string | your platform name in small-letters | | indexName | string | the used index name for the search function | | APIKey | string | your search API Key copied from [Lableb Dashboard](https://dashboard.lableb.com) | ---------------------- ### User related options Useful to track your users behavior later on, because knowing your users can help you better develop your platform/product. | field | type | description | | ------------- | ------ | ----------- | | userId | string | end user id | | userIp | string | end user IP address | | userCountry | string | end user country code(ISO-3166) | | sessionId | string | uniques session Id for your end user | | sessionIdGenerator | function | pass callback that generate unique session id string | ---------------------- #### Alternative syntax for async code ```js let lablebClient = LablebClient({ APIKey: process.env.API_KEY, platformName: process.env.PLATFORM_NAME, }) lablebClient.searchById(options) .then(searchResponse => { const { code, response, time } = searchResponse; const searchResult = response; }) .catch(console.error);; ``` ---------------------- ### Search By ID Response ```js const searchResponse = await lablebClient.searchById(options); ``` | field | type | description | | ---------------------------- | ------ | ----------- | | time | number | time spent for the request in milliseconds | | code | number | http response code | | response | object | found document | --------------------- #### Search Response Examples ##### Results Example ```json [ { id: "8112-cmb", ...fields }, ] ```