Browse Source

Fix to #114 - Accent insensitive search

master
Haktrum 11 years ago
parent
commit
699848283c
  1. 23
      app/js/services.js

23
app/js/services.js

@ -482,7 +482,16 @@ angular.module('myApp.services', []) @@ -482,7 +482,16 @@ angular.module('myApp.services', [])
.service('SearchIndexManager', function () {
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 {
createIndex: createIndex,
@ -504,6 +513,12 @@ angular.module('myApp.services', []) @@ -504,6 +513,12 @@ angular.module('myApp.services', [])
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) {
return false;
}
@ -533,6 +548,12 @@ angular.module('myApp.services', []) @@ -533,6 +548,12 @@ angular.module('myApp.services', [])
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(' '),
foundObjs = false,
newFoundObjs, i, j, searchText, found;

Loading…
Cancel
Save