Created
April 30, 2022 14:40
-
-
Save Yudhajitadhikary/d02f88ef49447a3cea6978972e642959 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const constants=require('../data') | |
const IndexManager=require('./algoliaIndexManager') | |
function getFieldObject(name,value=''){ | |
if(value===null){ | |
value='' | |
} | |
return{ | |
[name]:value | |
} | |
} | |
async function push(){ | |
console.log('starting to push data to Algolia') | |
if(constants.data.length>0){ | |
let pushedData=[] | |
const {replaceAll,setSettings,createReplica} =new IndexManager('Demo-Index') | |
constants.data.forEach((node)=>{ | |
if(node){ | |
pushedData.push({ | |
...getFieldObject('image',node.imgUrl), | |
...getFieldObject('name',node.name), | |
...getFieldObject('price',node.price), | |
...getFieldObject('facetCollection',node.facets) | |
}) | |
} | |
}) | |
try{ | |
await replaceAll(pushedData) | |
await setSettings(['name']) | |
await createReplica([ | |
'Demo-Index-desc(name)', | |
'Demo-Index-desc(price)' | |
]) | |
console.info('Pushing Data successfull') | |
} | |
catch(err){ | |
console.error('Error Pushing data to Algolia completed') | |
} | |
} | |
} | |
push() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment