Fix to #114 - Accent insensitive search
This commit is contained in:
parent
82b2a0c95f
commit
699848283c
@ -482,7 +482,16 @@ angular.module('myApp.services', [])
|
|||||||
|
|
||||||
.service('SearchIndexManager', function () {
|
.service('SearchIndexManager', function () {
|
||||||
var badCharsRe = /[`~!@#$%^&*()\-_=+\[\]\\|{}'";:\/?.>,<\s]+/g,
|
var badCharsRe = /[`~!@#$%^&*()\-_=+\[\]\\|{}'";:\/?.>,<\s]+/g,
|
||||||
trimRe = /^\s+|\s$/g;
|
trimRe = /^\s+|\s$/g,
|
||||||
|
accentsReplace = {
|
||||||
|
a: /[áâäà]/g,
|
||||||
|
e: /[éêëè]/g,
|
||||||
|
i: /[íîïì]/g,
|
||||||
|
o: /[óôöò]/g,
|
||||||
|
u: /[úûüù]/g,
|
||||||
|
c: /ç/g,
|
||||||
|
ss: /ß/g
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
createIndex: createIndex,
|
createIndex: createIndex,
|
||||||
@ -504,6 +513,12 @@ angular.module('myApp.services', [])
|
|||||||
|
|
||||||
searchText = searchText.replace(badCharsRe, ' ').replace(trimRe, '').toLowerCase();
|
searchText = searchText.replace(badCharsRe, ' ').replace(trimRe, '').toLowerCase();
|
||||||
|
|
||||||
|
for (var key in accentsReplace) {
|
||||||
|
if (accentsReplace.hasOwnProperty(key)) {
|
||||||
|
searchText = searchText.replace(accentsReplace[key], key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!searchText.length) {
|
if (!searchText.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -533,6 +548,12 @@ angular.module('myApp.services', [])
|
|||||||
|
|
||||||
query = query.replace(badCharsRe, ' ').replace(trimRe, '').toLowerCase();
|
query = query.replace(badCharsRe, ' ').replace(trimRe, '').toLowerCase();
|
||||||
|
|
||||||
|
for (var key in accentsReplace) {
|
||||||
|
if (accentsReplace.hasOwnProperty(key)) {
|
||||||
|
query = query.replace(accentsReplace[key], key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var queryWords = query.split(' '),
|
var queryWords = query.split(' '),
|
||||||
foundObjs = false,
|
foundObjs = false,
|
||||||
newFoundObjs, i, j, searchText, found;
|
newFoundObjs, i, j, searchText, found;
|
||||||
|
Loading…
Reference in New Issue
Block a user