programatic accent discount javascript (aka calm normalization unaccenting)
i need review 2 strings equal such these:
lubeck == lbeck
in javascript.
why? well, i have an auto-completion domain that's going out java use controlling lucene, where place names stored naturally (as lbeck), nonetheless also indexed normalized text,
import sun.text.normalizer;
odoc.setnamelc = normalizer.normalize(olocname, normalizer.decomp, 0)
.tolowercase().replaceall("[^\\p{ascii}]","");
this proceed some-one doesn't know form "mxico" form "mexico" review advantage "mxico" (among lot illusory hits, "caf mxico, dubai, uae").
now thing i don't have ability change use any highlighting server side, therefore i am highlighting fan javascript side something like:
return result.replace( input.replace(/[aeiou]/g,"."), "<b>$1</b>");
it's small some-more imagination since i am evading special regex characters input. glorious rudimentary matches during commencement hit, nonetheless unequivocally breaks down astonishing wish support multi-word matches "london cafe":
input = input.strip().tolowercase(); //fyi prototype's frame trim
re = new regex(input.replace(/[aeiou]/g,".").replace(/\s+/g,"|"),"gi");
return result.replace(re, "<b>$1</b>");
this doesn't work contend "london ca" (was typing london cafe), since symbol "jack london cabin, dawson city, canada" as: "ja<b>ck</b> <b>london</b> <b>ca</b>bin, dawson <b>ci</b>ty, <b>ca<b/>nada"
[note "ck" "ci" particularly]
therefore i'm arrange looking something that's crazy as:
input = input.strip().tolowercase();
input = input.replace(/a/g,"[]");
input = input.replace(/e/g,"[]");
// ditto i, o, u, y, c, n, maybe also d, g, h, j, k, l, r, s, t, w, z
re = new regex(input.replace(/\s+/g,"|"),"gi");
return result.replace(re, "<b>$1</b>");
is there collected list i ascribe mapping operation characters accented versions an impression character, i don't meant plain unicode chart. so, i prevaricate controlling weird, presumably slow, regex statements?
about bounty:
before i started payments there twin answers, indicating me doing ruby, wrote execution simple form i'd put question. don't me wrong, i unequivocally conclude operative out totally did, nonetheless i only wished there competence another way. seems distant everybody who's secluded feeling during doubt answer solid mizzardx covers only fine, have opposite approach. i prying opposite approach, simply isn't accessible before payments closes, mizzardx win payments (though barbarous twist, edits violent village wiki answer, i'm certain he'll bounty!)
Comments
Post a Comment