Skip to content

Instantly share code, notes, and snippets.

@tmtk75
Created April 29, 2019 00:07
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 tmtk75/8a3e00c9b2c251bc46ade88b5c506bc4 to your computer and use it in GitHub Desktop.
Save tmtk75/8a3e00c9b2c251bc46ade88b5c506bc4 to your computer and use it in GitHub Desktop.
Lunr sample
const lunr = require("lunr");
const lunrstemmer = require("lunr-languages/lunr.stemmer.support");
const lunrtinyseg = require("lunr-languages/tinyseg");
const lunrja = require("lunr-languages/lunr.ja");
lunrstemmer(lunr);
lunrtinyseg(lunr);
lunrja(lunr);
// console.trace("init lunr");
const notes = require("./export-1.json").note;
// console.log(notes);
const idx = lunr(function() {
const a = this;
a.use(lunr.ja);
a.metadataWhitelist = ["position"];
a.ref("_id");
a.field("title");
a.field("body");
notes.forEach(doc => {
a.add(doc);
}, a);
});
console.log(idx);
const search_word = process.argv[2] || "markdown"
const r = idx.search(search_word);
console.log(r);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment