Java Library Integration

📘

Important

This document is ONLY for the customers using the new console. For the older version, refer to the documentation here.

Since we are gradually migrating all our customers toward our new upgraded console, we would slowly deprecate the older version.

Unbxd Search JS Library helps you build awesome search experiences with Unbxd Search powering the search results page. With a few simple configurations, you can quickly get up and running with our default template to experience the Unbxd Search functionalities.

📘

Note

The current version is v2.0.0.

Quick Integration with Unbxd Template

There are two ways in which you can quickly get up and running with our default template to try out our JS Library functionalities:

If you have a console account already, follow the steps below:

  1. Go to the console dashboard & click the Website Preview button.
  2. Then click the Download UI Kit button to download the Unbxd Default template package for your catalog.
  3. Unzip the package & open the index.html file in your browser to view the search results landing page for your catalog with the Unbxd default template.

OR

  1. Download the Unbxd Search Library default template package from here .
  2. Unzip the package & open the index.html file inside the folder.
  3. Update the global variables UNBXD_SITE_KEY and UNBXD_API_KEY in the <head> section <script> tag of the index.html file with your Site key & API keys.
window.UNBXD_SITE_KEY=  < your site key >//yoursitekey
window.UNBXD_API_KEY= < your API key>//yourapikey

Update the global variable “UNBXD_MAPPED_FIELDS” with the field mapping of your catalog fields.

 window.UNBXD_MAPPED_FIELDS = {
   "unxTitle": "title",
  "unxImageUrl": "Image_Link",
   "unxPrice": "Price",
   "unxDescription":" productDescription"
};

Finally, open index.html in your browser to view the search results landing page for your catalog with the Unbxd default template.

Quick Integration to Your Site

To integrate the JS Library into your site, follow the following steps:

Include the JS Library. This can be done in two ways:

  1. Adding it as a URL to your HTML file. First, add the following CSS file into the “ section of your HTML page to get the Unbxd default theme styles.
<link rel="stylesheet" href="https://libraries.unbxdapi.com/search-sdk/v2.0.0/vanillaSearch.min.css" /> 

Then add the following script file for the library at the end of the body section.

<script type="text/javascript" src="https://libraries.unbxdapi.com/search-sdk/v2.0.0/vanillaSearch.min.js">

This will set the “UnbxdSearch” constructor on the window object.

  1. Install it via npm using the following command
npm i @unbxd-ui/vanilla-search-library

and import the UnbxdSearch class like below:

import  UnbxdSearch  from  "@unbxd-ui/vanilla-search-library";

Note: To include default CSS, use the following command

import "@unbxd-ui/vanilla-search-library/public/dist/css/vanillaSearch.css";

Or if you are using SCSS, include the below file

import "@unbxd-ui/vanilla-search-library/styles/index.scss";

Create a search object using UnbxdSearch(class/constructor) with the relevant configs.

window.unbxdSearch = new UnbxdSearch({
 siteKey: "demo-unbxd700181503576558",
 apiKey: "fb853e3332f2645fac9d71dc63e09ec1",
 products:{
    productType:"SEARCH",
    productAttributes: [
            "title",
            "uniqueId",
            "price",
            "sku",
            "imageUrl",
            "displayPrice",
            "salePrice",
            "sortPrice"
      ]
 }
});

A full configuration will look like:

window.unbxdSearch = new UnbxdSearch({
 siteKey: "demo-german-unbxd809051586180937",
 apiKey: "16e3cf8d510c50106d64f1ebb919b34e",
 searchBoxEl: document.getElementById("unbxdInput"),
 searchButtonEl: document.getElementById("searchBtn"),
 products:{
   el:document.getElementById("searchResultsWrapper"),
   attributesMap: {
      "unxTitle": "title",
      "unxImageUrl": "imageUrl"
      "unxPrice": "displaySalePrice"
   },
   productAttributes: [
      "title",
      "imageUrl",
      "price"
   ]
 },
 spellCheck: {
   enabled: true,
   el: document.getElementById("didYouMeanWrapper")
 },
 noResults: {
     el: document.getElementById("noResultWrapper")
 },
 facet: {
   facetsEl: document.getElementById("facetsWrapper"),
   selectedFacetsEl: document.getElementById("selectedFacetWrapper"),
   applyMultipleFilters:false,
   defaultOpen:"FIRST",
   isCollapsible: true,
   isSearchable: true
 },
 pagination: {
   type: "FIXED_PAGINATION",
   el:document.querySelector("#clickScrollContainer"),
   onPaginate:function(data) {
   }
 },
 breadcrumb: {
   el: document.getElementById("breadcrumpContainer")
 },
 pagesize: {
   el: document.getElementById("changeNoOfProducts")
 },
 sort: {
   el: document.getElementById("sortWrapper"),
   options: [
     {
       value: "sortPrice desc",
       text: "Price High to Low"
     },
     {
       value: "sortPrice asc",
       text: " Price Low to High"
     }
   ]
 },
 loader :{
     el:document.getElementById("loaderEl")
 },
 productView:{
   el: document.getElementById("productViewTypeContainer"),
   defaultViewType: "GRID"
 },
 banner: {
   el: document.getElementById("bannerContainer"),
   count: 1
 }
});

You can also modify the configs anytime using the “updateConfig” method on the returned object. “updateConfig” accepts a new config object as an argument that will merge with the existing config object.

const  unbxdSearch = new UnbxdSearch({
 siteKey: "demo-unbxd700181503576558",
 apiKey: "fb853e3332f2645fac9d71dc63e09ec1",
 products:{
    productType:"SEARCH"
 }
});
unbxdSearch.updateConfig({
 products:{
    productType:"CATEGORY"
 }
});

Refer to the “List of Available Configurations” section below for a full list of all available configs.

Nomenclature

You will see the following terms:

  • **el **– The term el refers to a DOM element. So the rendered component will be rendered inside this DOM element.
    Ex: document.getElementById(“searchResultsWrapper”).
  • template – templates are functions where you can return the HTML string that needs to be rendered. This provides you with the power of the entire JavaScript to build your desired HTML string

All the class names generated by the library will have the prefix “UNX-“. So you can use it to customize styles.

Detailed integration guide

The final integrated result that we aim at with this quickstart can be seen at this codesandbox.

Let us walk through the important configs that need to be passed along with their values for powering the search results page.

Authentication

Once installed, you need to authenticate the Unbxd library using your Unbxd account keys (also known as Authentication Keys).

Whenever a customer signs up with Unbxd, they are issued one or more site keys and API keys depending on their use case. Some common scenarios:

For a customer with one website and two environments (production and staging), two site keys (one for each environment) and one API key are issued. For a customer with more than one website (multi-website vendor), the site key would be issued for every website + environment combination. So there would be an “n” number (equal to the number of websites) of API keys generated.

For multiple site keys, check if you have:

  • more than one environment
  • more than one website
  • different product set for staging and live
  • wish to track search performance and clicks separately for every microsite.

To get your Site Key and API Key in the console, please refer to the steps mentioned in the Configure Site section.

Pass the Site Key and API Key from the console in the “siteKey” and “APIKey” configs.

siteKey

PropertyData TypeRequiredDefaultDescription
siteKeystringtrueNASite key assigned by Unbxd (the unique identifier for each customer/site)

API Key

PropertyData TypeRequiredDefaultDescription
siteKeystringtrueNASite key assigned by Unbxd (the unique identifier for each customer/site)

At the end of this step, you should have the Site Key & API Key which can be passed into the “siteKey” & “APIKey” configs as shown below:

const  unbxdSearch =new UnbxdSearch({
 siteKey:"",
 apiKey:""
});

Types of Pages to Render

Unbxd has two product offerings:

  • SEARCH: Powers search results pages
  • BROWSE or CATEGORY: Powers category listing pages

Pass a config parameter called “productType” to indicate whether you want to render the search results page (productType= “SEARCH”) or the category listing page (productType= “CATEGORY”)

const  unbxdSearch = new UnbxdSearch({
 siteKey:"your site key",
 apiKey:"your API key",
products:{
    productType:"CATEGORY" //SEARCH , CATEGORY or BROWSE
}
});

Property

Data Type

Required

Default

Description

Dependency

productType

string

true

search

Used to indicate if the page is search or category. Possible values: search, category``search → uses term from URL.category → invokes getCategoryID to fetch category.

  • For SEARCH, set productType = "SEARCH" - For CATEGORY, set productType = "CATEGORY" and implement getCategoryID function.

At the end of this step, you should choose a “productType” of the page that you want to render and pass it in the config as shown below:

const  unbxdSearch = new UnbxdSearch({
 siteKey: "-your site key-",
 apiKey: "-your API key-",
products:{
    productType:"SEARCH"
}
});

Confige Page

Before we delve into the next set of configs, let’s first understand the most common sections in a search results page or category landing page. A search results page or a category landing page is made up of the following set of sections:

  1. Products list section
  • View type could be grid or list view
  • Sort by widget
  • Pagination widget with no. of products per page control
  • Pagination could be an infinite scroll or page number based
  • Number of results loaded on a page
  1. Facets section
  2. Spell check/search results message section
  3. Merchandising banners section

View Different Sections on a Search Result Page


In the following sections, we will discuss how to configure and render each feature with the Unbxd Search JS Library.

Search input box & search button selector

The library uses the following two configurations to bind keyboard and mouse events to the search input field and search button on your website.

PropertyData TypeRequiredDefaultDescription
searchBoxElElementtrueNADOM element for the search input box. Used by the library to bind keyboard input events.
searchButtonElElementfalseNADOM element for the search button. Used by the library to bind mouse click events.

At the end of this step, you should have configured the “input” & “search button” as shown below:

window.unbxdSearch = new UnbxdSearch({
  siteKey: "<your site key>",
  apiKey: "<your API key>",
  searchBoxEl: document.getElementById("unbxdInput"),
  searchButtonEl: document.getElementById("searchBtn"),
});

Search Results/Product Options

This is where products from the search results will be rendered.

Configure the Search Results Section

OptionDatatypeDefault ValueDescription
productTypeString"SEARCH"Type of products page to render. Accepted values: SEARCH, BROWSE, or CATEGORY.
elElementnullElement in which to render the search results.
templateFunctiondefaultCustomize the product card by returning custom HTML. Parameters: (product object, index, swatches, view type, product config).
productAttributesArray["title", "uniqueId", "price", "sku", "imageUrl", "displayPrice", "salePrice", "sortPrice", "productDescription", "unbxd_color_mapping", "colorName", "color"]Required fields to generate the product result template. Helps improve result loading performance.
attributesMapObject{"unxTitle": "title", "unxImageUrl": "imageUrl", "unxPrice": "salePrice", "unxStrikePrice": "displayPrice", "unxId": "uniqueId", "unxDescription": "productDescription"}Maps field names for displaying product data in the card.
gridCountNumberAdjusts as per screen sizeDefines how many product columns to show per row. Adjusts automatically if not set.
productItemClassString"product-item"Additional CSS class added to each product card.
onProductClickFunctionfunction(product, event) {}Callback triggered on product card click. Receives product and event as parameters.

Sample “products” config:

products:{
       el: document.getElementById("searchResultsWrapper"),
       template:function(product,idx,swatchUI,productViewType){ return ``},
       productType:"SEARCH",
       gridCount:1,
       onProductClick: function(product,e) {
       },
       productAttributes: [
           "title",
           "uniqueId",
           "price",
           "sku",
           "imageUrl",
           "displayPrice",
           "salePrice",
           "sortPrice",
           "productDescription",
           "unbxd_color_mapping",
           "colorName",
           "color"
       ],
       attributesMap:{
           'unxTitle':'title',
           'unxImageUrl':'imageUrl',
           'unxPrice':'salePrice',
           'unxStrikePrice':'displayPrice',
           'unxId':'uniqueId',
           'unxDescription':'productDescription'
       }
 
   },

Read more about product configuration here.

Sort Options

Sorting allows you to rearrange the search results based on certain fields in a particular order.

Rearrange the Search Results with Sort Option

To render the Sort By feature, you must configure the sort config object. The following are the various options available under the object:

OptionDatatypeDefault ValueDescription
enabledBooleantrueSet to false to disable the sort component.
elElementnullElement in which to render the sort component.
optionsArray[ {value: "price desc", text: "Price High to Low"}, {value: "price asc", text: "Price Low to High"}, {value: "rating asc", text: "Rating Low to High"}, {value: "rating desc", text: "Rating High to Low"} ]Array of sort options available to the user.
sortClassString"UNX-sort-item"CSS class name applied to each sort item. Must be used in your template.
selectedSortClassString"UNX-selected-sort"CSS class name applied to the selected sort item.
templateFunctiondefaultCustomize the sort UI using this function. Receives two parameters: selected sort value and the entire sort config object.
actionString"change"Event type to trigger sort: either "click" or "change".

Sample “sort” config

sort: {
   el: document.getElementById("sortWrapper"),
   selectedSortClass:'UNX-selected-sort',
   sortClass:'UNX-sort-item',
   template: function(selectedSort, sortConfig) { return ``},
   options:[{
        value:"price desc",
        text:"Price High to Low"
    },
    {
        value:"price asc",
        text:" Price Low to High"
    }],
   action:'change'
},

Please find the complete documentation here.

Pagination

Pagination helps to control the number of products displayed on the page and the type of pagination (infinite scroll, click to scroll, or fixed pagination) to display.

Control the Number of Products On One Page

Fixed Pagination: This traditional type of pagination displays the set number of products on one page.

Click & Scroll

You can configure the pagination feature by updating the required configs under the “pagination” config object.

The following are the various options available under the “pagination” config object:

OPTIONDATATYPEDEFAULT VALUEDESCRIPTION
enabledBooleantrueTurn this off if you do not want the pagination widget
typeString"CLICK_N_SCROLL"Type of pagination: "FIXED_PAGINATION", "INFINITE_SCROLL", or "CLICK_N_SCROLL"
elElementnullElement in which to render the pagination component
templateFunctiondefaultCustom HTML string returned from a function that receives pagination info
pageClassString"UNX-page-items"CSS classname for the pagination component
selectedPageClassString"UNX-selected-page-item"CSS classname for the selected page item
onPaginateFunction(paginationInfo){}Callback function called after a pagination action
pageLimitNumber6Number of pages to show upfront (for "FIXED_PAGINATION" type)
infinteScrollTriggerElElementwindowElement to detect infinite scroll boundary (when type is "INFINITE_SCROLL")
heightDiffToTriggerNextPageNumber100Height difference to trigger next page fetch (for "INFINITE_SCROLL" type)
actionString"click"Action on which pagination should trigger: "click" or "change"

sample

pagination : {
       enabled:true,
       el: document.querySelector("#clickScrollContainer"),
       template: function (paginationData, pagination) { return ``},
       pageClass:"UNX-page-items",
       selectedPageClass:"UNX-selected-page-item",
       type:'CLICK_N_SCROLL', // INFINITE_SCROLL or CLICK_N_SCROLL or FIXED_PAGINATION
       infinteScrollTriggerEl:window, //if paginationType = INFINITE_SCROLL
       heightDiffToTriggerNextPage:100, //if paginationType = INFINITE_SCROLL,   
       onPaginate:function(paginationInfo){},
       action:'click',
       pageLimit:6
   }

Facets

Facets are the product filters provided on your webpage, allowing customers to narrow down the search result set.

To render the facets on the search results page, you can use the “facet” config object to configure the various options.

OPTIONDATATYPEDEFAULT VALUEDESCRIPTION
facetsElElementnullElement in which to render the facets
facetTemplateFunctiondefaultCustomize entire facets block (receives: full block, facet values, isExpanded, search text)
facetItemTemplateFunctiondefaultCustomize each individual facet item (receives: full block, facet value, search text)
facetMultiSelectBooleantrueSet to false to disable multiple facet selection
facetClassString"UNX-facets-block"CSS class for facet block
facetActionString"click"Event type for selection: "click" or "change"
selectedFacetClassString"UNX-selected-facet-btn"CSS class for selected facet items
selectedFacetsElElementnullElement to render selected facets (falls back to rendering alongside facets if null)
selectedFacetTemplateFunctiondefaultCustomize selected facet block (receives: full block, selected value)
selectedFacetItemTemplateFunctiondefaultCustomize selected facet item (receives: full block, selected value)
clearAllTextString"Clear All"Text for "clear all" button
rangeTemplateFunctiondefaultCustomize range facets (receives: range list)
rangeWidgetConfigObjectNARange slider config (see "Facet Range Widget Config")
facetMultilevelBooleantrueEnables multilevel facets in API
facetMultilevelNameString"Category"Field name for multilevel facet
multiLevelFacetSelectorClassString"UNX-multilevel-facet"CSS class for multilevel facet items
multiLevelFacetTemplateFunctiondefaultCustomize multilevel facet (receives: full block, selected values, search text)
facetDepthNumber4Number of category levels to support
clearFacetsSelectorClassString"UNX-clear-facet"Class for clear selected facets button
removeFacetsSelectorClassString"UNX-remove-facet"Class for delete individual facet button
onFacetLoadFunctionfunction(facets) {}Callback after facet selection/deselection
applyMultipleFiltersBooleanfalseEnables "apply all filters together" functionality
applyButtonTextString"Apply"Label for apply button
clearButtonTextString"clear"Label for clear button
isCollapsibleBooleantrueEnables collapsible accordion-style facets
defaultOpenString"ALL"For collapsible facets: "ALL", "FIRST", or "NONE" as default open state
isSearchableBooleantrueEnable search inside facet blocks
searchPlaceHolderString""Placeholder text for facet search input
enableViewMoreBooleanfalseEnables "view more/less" toggle for long facet lists
viewMoreTextArray["show all", "show less"]Texts for view more / less toggle
viewMoreLimitNumber3Min facet value count to show view more

Facet Range Widget Config

You can configure the range sliders by setting the “rangeWidgetConfig” object under the “facet” object. Range facets will be rendered automatically along with other facets if it is configured on the console dashboard.

The following are the various options available for configuring the range widget

OPTIONDATATYPEDEFAULT VALUEDESCRIPTION
minLabelString""Text label for the lower end of the range slider
maxLabelString""Text label for the higher end of the range slider
prefixString"$"Prefix for the range values (e.g., $ for price range display like $10)

Sample

 facet: {
       facetsEl: document.getElementById("facetsWrapper"),
       facetTemplate:function(facetObj, children, isExpanded,facetSearchTxt, facet){},
       facetItemTemplate:function(facet,value, facetSearchText){},
       facetMultiSelect:true,
       facetClass:"UNX-facets-block",
       facetAction:"click",
       selectedFacetClass:"UNX-selected-facet-btn",
       selectedFacetsEl:null,
       selectedFacetTemplate:function(selections, facet){},
       selectedFacetItemTemplate:function(selectedFacet,selectedFacetItem){},
       clearAllText:"Clear All",
       rangeWidgetConfig: {
           "minLabel":"",
           "maxLabel":"",
           "prefix":'$'
       },
       facetMultilevel:true,
       facetMultilevelName:"Category",
       multiLevelFacetSelectorClass:"UNX-multilevel-facet",
       facetDepth:4,
       clearFacetsSelectorClass: "UNX-clear-facet",
       removeFacetsSelectorClass: "UNX-remove-facet",
       onFacetLoad:function(facets){
       },
       applyMultipleFilters:false,
       applyButtonText:"Apply",
       clearButtonText:"clear",
       isCollapsible:true,
       isSearchable:true,
       searchPlaceHolder:"",
       textFacetWrapper:"UNX-facets-item",
       defaultOpen:"ALL",
       enableViewMore:false,
       viewMoreText:["show all", "show less"],
       viewMoreLimit:3
   }

Page Size

Page Size widget allows you to configure the number of products on each page.

Configure the no. of Products on Each Page

To render the Page Size widget, you need to configure the “pageSize” config object.

The following are the various options available under the object:

OPTIONDATATYPEDEFAULT VALUEDESCRIPTION
enabledBooleantrueTurn this off to disable the page size selection component
elElementnullElement in which to render the page size control
pageSizeNumber12Default number of results shown per page
optionsArray[8, 12, 16, 20, 24]List of selectable page sizes. Recommended to align with column count (e.g., for 3-column layout use multiples like 15, 18, 21)
pageSizeClassString"UNX-pagesize"CSS class to apply to the page size element
selectedPageSizeClassString"UNX-selected-pagesize"CSS class to apply to the selected page size option
actionString"change"Event type to trigger page size change: "click" or "change"
templateFunctiondefaultFunction to customize the HTML template of the component. Receives two parameters: the selected page size and the full config object

Sample

pageSize: {
  enabled:true,
       pageSize:12,
       options:[8,12,16,20,24],
       pageSizeClass:"UNX-pagesize",
       selectedPageSizeClass:"UNX-selected-pagesize",
       action:'change',
       template:function(){},
       el:null
   }

Product View

You can configure the way in which the products have to be displayed (List or Grid) with the Product Views widget.

Configure the Way Your Products are Displayed

Update the options under the “productView” config object to configure the product view feature.

OPTIONDATATYPEDEFAULT VALUEDESCRIPTION
enabledBooleantrueTurn this off to disable the product view switcher component
elElementnullElement in which to render the product view type component
templateFunctiondefaultCustom function to render product view HTML. Receives 2 parameters: selected view type and full config object
defaultViewTypeString"GRID"Default product view type. Accepts "LIST" or "GRID"
actionString"click"Event type to switch product view: "click" or "change"
viewTypeClassString"UNX-product-view"CSS class to apply to each product view option
selectedViewTypeClassString"UNX-selected-product-view"CSS class to apply to the currently selected product view option

Sample “productView” config

productView : {
  enabled:true,
       el:null,
       template:renderProductViewType,
       action: “click”, // CLICK or CHANGE
       viewTypeClass: “UNX-product-view”,
       selectedViewTypeClass: “UNX-selected-product-view”,
       viewTypes: “GRID”
   }

Spellcheck & Search Query

The spell check feature provides spelling suggestions or spell-checks for misspelled search queries.

Give Spell-Checks for Misspelled Search Queries

In such cases, Unbxd's context-aware algorithm understands your visitor’s intent and sends a “Did You Mean” response along with a search result set for the query, if any.

You can configure the spellcheck feature by updating the required configs under the “spellCheck” config object.

OPTIONDATATYPEDEFAULT VALUEDESCRIPTION
enabledBooleantrueEnables or disables the spell check component
elElementnullElement in which to render the spell check component
templateFunctiondefaultFunction to customize the spell check UI. Receives 3 parameters: the search query, suggested query text, and a config object {start, productsLn, numberOfProducts}
selectorClassString"UNX-suggestion"Additional CSS class name applied to the spell check component

Sample “spellCheck” config

spellCheck:{
       enabled:true,
       el:document.getElementById("didYouMeanWrapper"),
       template: function(query,suggestion,pages) { return ``},
       selectorClass: "UNX-suggestion"
   }

Breadcrumbs

To render the breadcrumb component, set the “breadcrumb” config object.

The following options are available under the object:

OPTIONDATATYPEDEFAULT VALUEDESCRIPTION
enabledBooleantrueEnables or disables the breadcrumb component
elElementnullElement in which to render the breadcrumbs
templateFunctiondefaultFunction to customize breadcrumb HTML. Receives the breadcrumb list as parameter
selectorClassString"bread-crumb"CSS class to apply to each breadcrumb item

Variants

Configure variants display by setting the “variants” config object.

The following options are available under the object:

OPTIONDATATYPEDEFAULT VALUEDESCRIPTION
enabledBooleanfalseSet this flag to true to enable variant rendering
countNumber5Number of variants to be shown
groupByString"v_colour"Field name (as per catalog) to group the variants by (e.g., "v_colour", "v_size", etc.)
attributesArray["title", "v_imageUrl"]Array of catalog fields to include in each variant
mappingObject{ "image_url": "v_imageUrl" }Field mapping from catalog attributes to variant attributes, required for correct rendering

Sample “variants” config

variants:{
        enabled:false,
        count:5,
        groupBy:'v_colour',
        attributes:[
            "title",
            "v_imageUrl"
        ],
        mapping:{
            "image_url":"v_imageUrl"
        }
    },

Swatches

Configure swatches display by using the configs in this section.

The following options are available under the object:

OPTIONDATATYPEDEFAULT VALUEDESCRIPTION
enabledBooleanfalseEnables or disables the swatches component
attributesMapObject{ swatchImgs: "unbxd_color_mapping", swatchColors: "color", swatchList: "color" }Field mappings from catalog to swatch attributes (e.g., color images, color names, list of colors)
swatchClassString"UNX-swatch-btn"CSS class to apply to swatch buttons
templateFunctiondefaultFunction to customize the swatch UI. Receives two parameters: the current swatch data and the complete swatches list

Sample “swatches” config

swatches:{
       enabled:true,
       attributesMap:{},
       swatchClass:'UNX-swatch-btn',
       template:function(swatchData) {
           const {
               swatchColors = [],
               swatchImgs = []
           } = swatchData;
           let btnUI = ``;
           swatchColors.forEach((item,id) => {
               const imgId = swatchImgs[id];
               if(imgId){
                   const img = imgId.split("::")[1];
                   btnUI+= [`<button data-swatch-id="${item}" data-swatch-img="${img}" data-action="changeSwatch"`,
 `data-swatch-target=".UNX-img-block" class="${this.swatchClass}" style="background-color:${item}"> </button>`].join('')
               }
           });
           return `<div class="UNX-swatch-color-list">${btnUI}</div>`;
       }
   }
📘

NOTE

If you wants swatches, variants count should be higher, and “groupBy” field should be present in mapped fields config as shown below

variants:{
       enabled:false,
       count:5,
       groupBy:'v_colour',
       attributes:[
           "title",
           "v_imageUrl"
       ],
       mapping:{
           "image_url":"v_imageUrl"
       }
   }

Banner

Configure the banner display by setting the “banner” config object.

The following options are available under the object:

OPTIONDATATYPEDEFAULT VALUEDESCRIPTION
enabledBooleanfalseEnables or disables the banner component
elElementnullElement in which the banner component will be rendered
templateFunction[default](https://github.com/unbxd/search-JS-library/blob/master/src/modules/banners/index.js)Custom function to define the banner’s HTML. Receives list of banners as parameter
countNumber1Number of banners to be displayed

Loader

Configure page loader to be shown when fetching search API results by setting the “loader” config object.

The following options are available under the object:

OPTIONDATATYPEDEFAULT VALUEDESCRIPTION
elElementnullElement in which to render the loader component
templateFunctionfunction(){ return '<div class="UNX-loader">Loading search results….</div>'; }Function to customize the loader UI. Should return HTML string for the loading indicator

NoResults

Configure the display to be rendered when there are no results by setting the “noResults” config object.

The following options are available under the object:

OPTIONDATATYPEDEFAULT VALUEDESCRIPTION
templateFunctionfunction(query){ return '<div class="UNX-no-results"> No Results found ' + query + '</div>'; }Function to customize the UI when no results are found. Receives the search query as the input parameter

Miscellaneous Configs

OPTIONDATATYPEDEFAULT VALUEDESCRIPTION
siteKeyStringNAUnique Site Key assigned by Unbxd (from the console dashboard). Refer to this section for steps to get the Site Key for your account.
apiKeyStringNAUnique API Key assigned by Unbxd (from console dashboard). Refer to this section for steps to get the Site Key for your account.
searchBoxElElementnullDOM element selector for the search input box
searchButtonElElementNADOM element selector for the search button. Clicking it triggers a search based on searchBoxEl value
unbxdAnalyticsBooleanfalseEnables Unbxd Analytics event tracking (requires including Unbxd Analytics SDK)
hashModeBooleanfalseEnables URL updates using hash (#) instead of query parameters
updateUrlsBooleantrueControls whether URLs update on search parameter change
actionBtnClassString"UNX-action-item"CSS class for elements that trigger click events
actionChangeClassString"UNX-action-change"CSS class for elements that trigger change events
onActionFunctionfunction(event, context) {}Callback on custom click or change event. Receives: event, context
onEventFunctionfunction(context, type) {}Callback for supported Unbxd lifecycle events. Event types: BEFORE_API_CALL, AFTER_API_CALL, BEFORE_RENDER, AFTER_RENDER, BEFORE_NO_RESULTS_RENDER, AFTER_NO_RESULTS_RENDER, FACETS_CLICK, DELETE_FACET, PAGE_NEXT, etc.
extraParamsObject{ "version": "V2" }Additional custom parameters to include in search API calls
productIdString"uniqueId"Field representing the unique product identifier
defaultFiltersObjectnullSet default filters to be applied with every API request
searchQueryParamString"q"Custom query param name to send search term (e.g., "query" instead of "q")
searchEndPointString"https://search.unbxd.io"The domain name of the Unbxd search endpoint
searchPathString""Additional path to append to search URL (useful for SPAs or subpaths)
getCategoryIdFunctionnullCustom function to return category ID (default comes from unbxdPageConf)
setCategoryIdFunctionnullCustom function to define logic for category navigation via breadcrumbs

Instance Methods

This section documents the different methods exposed by the Library that you can use to perform various actions.

📘

Note

All the below methods can be called on the instance object returned by UnbxdSearch constructor.

updateConfig

FunctionPurposeArgumentsUsage Example
updateConfig(configObj)Dynamically update the config object; merges with existing settingsconfigObj (Object)unbxdSearch.updateConfig({ sort: { el: document.getElementById("sortWrapper"), options: [{ value: "sortPrice desc", text: "Price High to Low" }, { value: "sortPrice asc", text: "Price Low to High" }] }})
getResults()Refetch search results for a given queryquery (String)unbxdSearch.getResults("dress")
getCategoryPage()Render category page resultsNoneunbxdSearch.getCategoryPage()
getBrowsePage()Render browse page resultsNoneunbxdSearch.getBrowsePage()
reRender()Re-render UI components, useful on layout or screen changesNoneunbxdSearch.reRender()
resetFacets()Manually reset all selected facetsNoneunbxdSearch.resetFacets()
resetAll()Reset entire search state (facets, sort, pagination, etc.)NoneunbxdSearch.resetAll()
setPageStart(pageNo)Set specific page number to start frompageNo (Number)unbxdSearch.setPageStart(1)
setRangeSlider(config)Update range slider filter manually{ start, end, facetName, gap }unbxdSearch.setRangeSlider({ start: 0, end: 573, facetName: "price", gap: 200 })

For any issue that you face during integration or need updates on the changes, follow these tips, raise issues, or track log changes.

💡

Tips & Tricks

  • If you are including our Search JS Library, Autosuggest Library & Analytics Library in your HTML page, the order of the files is important.
  • Include the Search JS Library, followed by Autosuggest Library and the Analytics JS Library. The code to invoke the library should follow.
  • Always ensure you are invoking the library (i.e., calling the UnbxdSearch constructor) after you have included it either via URL or via npm
  • Include the CSS inside the <head> tag of your HTML page & the scripts at the end of the body tag. This will ensure that the page rendering is not blocked by the JavaScript files.

Raise Issues
Facing some issues? Look for solutions or create an issue here.

Stay up to date
Look at the changelog to see the latest version & history.

List of available Configurations
You can find the list of the available configurations in this Github link.