Created
March 6, 2020 06:15
-
-
Save nmabhinandan/414be56e688b670f223ff321722affd3 to your computer and use it in GitHub Desktop.
lunr search index builder
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
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