search(string) { return this.index.search(string, { expand: true }); }
constructor(basePath) { this.basePath = basePath; this.index = elasticlunr(function () { this.setRef('file'); this.addField('filename'); this.addField('content'); }); this.files = []; }
updateIndexForFile(file) { const filePath = path.relative(this.basePath, file); this.files.push(filePath); return fs.readFile(path.join(this.basePath, filePath), 'utf8') .then(content => { const doc = { file: filePath, filename: path.basename(filePath, path.extname(filePath)), content }; this.index[this.index.documentStore.hasDoc(filePath) ? 'updateDoc' : 'addDoc'](doc); return doc; }); }
getContent(file) { return this.index.documentStore.getDoc(file).content; }
const run = async () => { await folderToDocuments(linksPath, {arrayMod}) .each(result => index.addDoc(result)) .toPromise(Promise); console.log('Successfully generated index!');