chore: Import search-assets and refactor data source/push

This commit is contained in:
Bouncey
2019-03-07 13:57:15 +00:00
committed by mrugesh
parent 3552fd392a
commit 2789824374
16 changed files with 5977 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
const { client } = require('../../algolia');
const debug = require('debug');
const getChallengeData = require('../../data-sources/challenges');
const log = debug('fcc:search:init:challenge');
const index = client.initIndex('challenge');
index.setSettings(
{
searchableAttributes: ['title', 'description', 'blockName'],
distinct: true,
attributeForDistinct: 'id',
attributesForFaceting: ['blockName']
},
(err, response) => {
if (err) {
log(err.message);
log(err.debugData);
throw new Error(err);
}
log('setSettings\n\n' + JSON.stringify(response, null, 2));
}
);
exports.insertChallenges = function insertChallenges() {
return getChallengeData().subscribe(
challenges => {
index.addObjects(challenges, err => {
if (err) {
throw new Error(err);
}
});
},
err => {
throw new Error(err);
},
() => log('complete')
);
};