Browse Source

Merge pull request #119 from Haktrum/accent-insensitive-search-114

Fix to #114 - Accent insensitive search
master
Igor Zhukov 11 years ago
parent
commit
491817658a
  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