@unbxd-ui/unbxd-search-core

0.5.11 • Public • Published

search-JS-core

Core library for Search JS

Getting started

this library is the dependancy for search-JS-library and react-search-JS-SDK, provides the api for interacting with search api.

Prerequisites

Install npm

Setting Up

  • use node 14.15.0

Install the npm packages & start the dev server using following commands

npm install
npm run start

ES6

Install @unbxd-ui/unbxd-search-core using npm.

npm install @unbxd-ui/unbxd-search-core --save

Import the UnbxdSearchCore function in your project

import  UnbxdSearchCore  from  "@unbxd-ui/unbxd-search-core";

Basic Implementation

      const unbxdCore =  new UnbxdSearch({
          siteKey: "demo-unbxd700181503576558",
          apiKey: "fb853e3332f2645fac9d71dc63e09ec1",
          searchEndPoint:"https://search.unbxd.io/",
          productType:"SEARCH",
          searchQueryParam:"q",
          browseQueryParam:"p",
          updateUrls:true,
          productAttributes: ['title','uniqueId'],
          platform: "IO",
          onEvent:unbxdCallback,
          facetMultiSelect: true,
          defaultFilters :null,
          spellCheck: true,
          pageSize: 5,
          sortOptions : [
              {
                  value:"price desc",
                  text:"Price High to Low"
              },
              {
                  value:"price asc",
                  text:" Price Low to High"
              }
          ],
          variants:{
            enabled:false,
            count:1,
            groupBy:'',
            attributes:[],
            mapping:{
                "image_url":"v_image_url"
            }
        },
          facetMultilevel: true,
          facetMultilevelName: 'category',
          multiLevelFacetSelector:"bucketFacetElem",
          extraParams :{
              "version":"V2",
              "facet.multilevel":"categoryPath",
              "f.categoryPath.displayName":"category",
              "f.categoryPath.max.depth":"4",
              "f.categoryPath.facet.limit":"100"
          },
          facetDepth:4,
          breadcrumb:true,
          showSwatches:false,
          swatchMap:{
              "swatchList":"colours",
              "swatchImgs":"variant_metadata",
              "swatchColors":"unbxd_parentcolours"
          },
          hashMode:false,
          applyMultipleFilters:false,
          getCategoryId:()=>{
              return encodeURIComponent(window.UnbxdAnalyticsConf["page"])
          },
          setCategoryId:(param, self)=>{
            //you can set your category page ids
          },
              onQueryRedirect:(self, redirect, urlBeforeRedirect)=>{
    if(redirect) {
        const {
            value,
            type
        } = redirect;
        if(type === "url") {
            /** If opening in same tab */
            if(history.state && history.state.replace) {
                history.replaceState(null,"",urlBeforeRedirect);
            }
            
            location.href =  value;  

            /** If opening redirect in new tab (rare scenario), 
             * then browser back + history push on search should be handled by client 
             * (especially switching betsween category to search page scenarios)
             * Note: This is not recommended */                                                       
        }
        return false;
    }
},
onBackFromRedirect: (hashMode) => {
    let urlSearchParam = new URLSearchParams(hashMode ? location.hash.substring(1) : location.search);
    let backFromRedirect = urlSearchParam.get("redirected");
    if(backFromRedirect) {
        history.go(-1);
    }
},
      onNoUnbxdKeyRouting:() => {
            history.go();
      },
      
        setRoutingStrategies:(locationParam, newUrl, productType, isUnbxdKey, replace) => {
            if (locationParam === newUrl) {
                return;
            } else if (productType === "CATEGORY") {
                /** Do not navigate to base category page  */
                if (!isUnbxdKey) {
                    history.replaceState(null, "", newUrl);
                } else {
                    history.pushState(null, "", newUrl);
                }
            } else {
                if ((history.state && history.state.replace) || replace) {
                    history.replaceState(null, "", newUrl);
                } else {
                    history.pushState(null, "", newUrl);
                }
            }
        }
  });

SDK Apis

The available apis are listed here.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.4.23-beta.10beta
0.5.112latest

Version History

VersionDownloads (Last 7 Days)Published
0.5.112
0.5.1049
0.5.90
0.5.80
0.5.70
0.5.60
0.5.50
0.5.40
0.5.30
0.5.20
0.5.10
0.5.00
0.4.350
0.4.340
0.4.332
0.4.320
0.4.310
0.4.300
0.4.290
0.4.280
0.4.271
0.4.261
0.4.250
0.4.240
0.4.230
0.4.23-beta.10
0.4.220
0.4.22-beta.42
0.4.22-beta.31
0.4.22-beta.20
0.4.22-beta.10
0.4.210
0.4.202
0.4.190
0.4.180
0.4.170
0.4.161
0.4.150
0.4.141
0.4.130
0.4.120
0.4.110
0.4.101
0.4.92
0.4.81
0.4.70
0.4.60
0.4.50
0.4.40
0.4.31
0.4.20
0.4.10
0.4.00
0.3.92
0.3.80
0.3.70
0.3.60
0.3.50
0.3.40
0.3.30
0.3.20
0.3.10
0.3.01
0.2.92
0.2.80
0.2.70
0.2.60
0.2.51
0.2.40
0.2.30
0.2.20
0.2.10
0.2.00
0.1.90
0.1.81
0.1.70
0.1.61
0.1.51
0.1.40
0.1.30
0.1.20
0.1.10
0.1.00
0.0.91
0.0.81
0.0.72
0.0.61
0.0.52
0.0.41
0.0.20
0.0.10

Package Sidebar

Install

npm i @unbxd-ui/unbxd-search-core

Weekly Downloads

70

Version

0.5.11

License

ISC

Unpacked Size

857 kB

Total Files

4

Last publish

Collaborators

  • priyal-jain
  • archit.sagar
  • sanskratiagrawal306
  • akshayunbxd
  • divyadaglia