Created
February 2, 2018 00:36
-
-
Save samdutton/7973dcff2c2c14ae28339148c7290a2f to your computer and use it in GitHub Desktop.
Create Elasticlunr search index
This file contains hidden or 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
// node index.js | |
// get documents to be indexed. | |
const docs = getDocs(); | |
const index = elasticlunr(function() { | |
// Set fields to index. | |
this.addField('name'); | |
this.addField('description'); | |
// Set the field used to identify documents. | |
this.setRef('id'); | |
// Include product data with the index data. | |
this.saveDocument(true); | |
for (let doc of docs) { | |
this.addDoc(doc); | |
} | |
}); | |
// Write the index file. | |
saveIndex(JSON.stringify(index)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment