Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function buildSearchIndex(features) {
// index schema
const searchIndex = lunr(function didLoad() {
this.field('title', { boost: 100 });
this.field('slug', { boost: 100 });
this.field('summary', { boost: 10 });
this.field('category', { boost: 1 });
this.ref('slug');
});
searchIndex.pipeline.remove(lunr.stopWordFilter);
// ingest documents
features.forEach((doc) => {
// quick n dirty html strip. not for security.
doc.summary = doc.summary.replace(/<[^>]+>/g, '');
searchIndex.add(doc);
});
return searchIndex;
}
return lunr(function () {
this.ref('ref')
this.field('title', {boost: 3, extractor: titleExtractor})
this.field('doc')
this.metadataWhitelist = ['position']
this.pipeline.remove(lunr.stopWordFilter)
searchNodes.forEach(function (doc) {
this.add(doc)
}, this)
})
}
index = lunr(function () {
this.tokenizer.separator = separator;
this.pipeline.remove(lunr.stopWordFilter);
this.ref('id');
this.field('id');
this.field('description');
this.field('tags');
this.field('name');
files.forEach(function (doc) {
this.add(doc);
}, this);
});
}
this._index = lunr(function () {
this.ref('path')
this.field('title', {boost: 10})
this.field('text')
this.pipeline.remove(lunr.stopWordFilter)
})
function haveContiguousKeywords(phraseComponents, keywords) {
const path = []
for (const component of phraseComponents) {
if (!lunr.stopWordFilter(component)) { continue }
const stemmed = lunr.stemmer(new lunr.Token(component)).str
const positions = keywords.get(stemmed)
if (positions === undefined) {
return false
}
path.push(positions)
}
return haveContiguousPath(path)
}
index = lunr(function () {
this.tokenizer.separator = separator;
this.pipeline.remove(lunr.stopWordFilter);
this.ref('id');
this.field('id');
this.field('description');
this.field('tags');
this.field('name');
files.forEach(function (doc) {
this.add(doc);
}, this);
});
}