logo

English

JS SDK V2

Easily integrate with Lableb to add powerful search capabilities in-website/in-app :
  1. search (instant results & highly configurable)
  2. autocomplete (super fast & understand what you want)
  3. recommend (direct links between your data can be fetching using smart recommendation)
  4. index new data(documents) (indexing data make it available in search results)
  5. update existing data (documents get updated all the times...no problem, you can update it easily)
  6. delete documents(easily remove from search results)

SDK V2 features

  1. built with typescript to power your DX
  2. universal module build (can work in any environment)
  3. use different http client for different environment(browser/node)
  4. use the new Lableb RESTful API
  5. Promise based async code

Installation

npm

npm install @lableb/javascript-sdk

yarn

yarn add @lableb/javascript-sdk

Browser (~ 32KB)

<script src="https://unpkg.com/@lableb/[email protected]/dist/LablebSDK.min.js"></script>

Importing the SDK

Node.js

const LablebSDK = require('@lableb/javascript-sdk');

ESM Modules

import * as LablebSDK from'@lableb/javascript-sdk';

Browser

var LablebSDK = window.LablebSDK;

Initializing the SDK

let client = LablebSDK.init({
    
    projectName: '<PROJECT_NAME>',
    collectionName: '<COLLECTION_NAME>',

    // used for search, autocomplete, recommend, feedback
    searchToken: '<SEARCH_TOKEN>',

    // only needed in server in case you need to index/delete documents
    indexToken: '<INDEX_TOKEN>', 
    
    searchHandler: '<SEARCH_HANDLER>',
    autoCompleteHandler: '<AUTOCOMPLETE_HANDLER>',
    recommendHandler: '<RECOMMEND_HANDLER>',
});

Options

OptionsDefaultDescriptions
projectName-project name
collectionName"posts"collection name
searchToken-used in search, autocomplete, recommend
indexToken-used to index, or delete documents
searchHandler"default"configured handler used in search queries
autoCompleteHandler"suggest"configured handler used in autocomplete queries
recommendHandler"recommend"configured handler used in recommendation

To get your tokens and other config options

  1. login to Lableb Dashboard
  2. open API Keys tab
  3. generate new tokens(or use the existing ones)
  4. copy project name as it is(in small letters)

SDK offers:

  1. indexing documents function (only works in server environment)
  2. delete document function (only works in server environment)
  3. search function that enable you to send queries to Lableb API
  4. autocomplete function that help your user predicting what they are searching for
  5. recommend function help you get similar document given an existing document
  6. feedback function for search & autocomplete & recommend which is highly important to you to track your users search choices & recommendation in Lableb dashboard

Examples

You can read real code example in repository's /examples folder, we have example for various libraries, frameworks, environments:
  1. Node.js
  2. Node.js with Typescript
  3. Pure html-css-js example
  4. Pure html-css-js with hands on DOM manipulation
  5. angular ( > 7.x.x)
  6. react