I have an ASP.NET app with openlayers and JS, inside the web map app I have a seachbox where the text I enter is modified to match different characters (e.g. the character 'i' can be 'i', 'í' or 'ì'). Also I need to find different words that can be incomplete and separated, so if I search 'graf de orca cio' the text below should appear as a result:
"Base topogràfica de l'illa de Menorca, realitzada a partir de l'actualització"
This becomes slower when I search trough hundreds (between 100 and 200) of capabilities like this one below:
I search the fields inside the tags 'Name', 'Title', 'Keyword' and 'Abstract', the last one seems to be the one with longer texts.
The text I enter goes through a piece of code so "graf de orca cio" becomes ".*?(gr(a|á|à)f).*?(d(e|é|è)).*?((o|ó|ò)rc(a|á|à)).*?(c(i|í)(o|ó|ò)).*?" and that is the regular expression used to search. The code i use to make the transformation is this:
this.patternFn = function (t) {
t = t.replace(/[^a-z\dáàéèíóòúüñ]/gi, '\\' + '$&');
t = t.replace(/(a|á|à)/gi, "(a|á|à)");
t = t.replace(/(e|é|è)/gi, "(e|é|è)");
t = t.replace(/(i|í)/gi, "(i|í)");
t = t.replace(/(o|ó|ò)/gi, "(o|ó|ò)");
t = t.replace(/(u|ú|ü)/gi, "(u|ú|ü)");
t = t.replace(/n/gi, "(n|ñ)");
t = ".*?(" + t + ").*?";
t = t.replace(/\\ /gi, ").*?(");
return t;
This whole thing seems to be not the most efficient way to do this, so sometimes the search freezes the app some seconds. Any idea on how to make this work faster?