Skip to content

Instantly share code, notes, and snippets.

@nmabhinandan
Created March 6, 2020 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmabhinandan/414be56e688b670f223ff321722affd3 to your computer and use it in GitHub Desktop.
Save nmabhinandan/414be56e688b670f223ff321722affd3 to your computer and use it in GitHub Desktop.
lunr search index builder
function createSearchIndex(tags, data) {
if (schema === null || !Array.isArray(tags)) {
return false;
}
if (data === null || !Array.isArray(data)) {
return false;
}
let searchIndex = lunr(function () {
this.ref('id')
this.field('name', { boost: 10 })
let that = this;
tags.forEach(function (tag) {
that.field(tag);
});
data.forEach(function (d) {
that.add(d);
});
});
return searchIndex;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment