Skip to content

an extension to lunr.js to normalize unicode characters by removing all diacritical marks

License

Notifications You must be signed in to change notification settings

dhdaines/lunr-folding

 
 

Repository files navigation

lunr-folding

An extension to lunr.js to do basic character folding, converting various accented and non-ASCII characters to their (presumed) ASCII equivalents.

For example, searching for "facade" will return results for "façade" and searching for for "façade" will return results for "facade."

Usage

Install via npm npm install lunr-folding. After lunr is loaded do:

require("lunr-folding")(lunr);

Or in TypeScript:

import folding from "lunr-folding";
folding(lunr)

You can now create indexes with accented characters and search them without accents, for example:

folding(lunr);
const idx = lunr(function () {
    this.ref("id");
    this.field("text");
    this.add({ id: "1", text: "Étape 1: Collecter des bobettes" });
    this.add({ id: "2", text: "Étape 2: ???" });
    this.add({ id: "3", text: "Étape 3: Profit" });
});
const results = idx.search("etape 3");
console.log(JSON.stringify(results[0]));

Credits

Based on the original lunr.unicodeNormalizer.js by Christopher Van and the NPM-ified version by Dániel Boros

About

an extension to lunr.js to normalize unicode characters by removing all diacritical marks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%