Created
April 29, 2019 00:07
-
-
Save tmtk75/8a3e00c9b2c251bc46ade88b5c506bc4 to your computer and use it in GitHub Desktop.
Lunr sample
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
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