Skip to content

Instantly share code, notes, and snippets.

@samdutton
Created February 2, 2018 00:36
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 samdutton/7973dcff2c2c14ae28339148c7290a2f to your computer and use it in GitHub Desktop.
Save samdutton/7973dcff2c2c14ae28339148c7290a2f to your computer and use it in GitHub Desktop.
Create Elasticlunr search index
// 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