From 699848283c9217ac3be1472b69135cf0c200de56 Mon Sep 17 00:00:00 2001 From: Haktrum Date: Mon, 3 Mar 2014 00:10:51 -0300 Subject: [PATCH] Fix to #114 - Accent insensitive search --- app/js/services.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/app/js/services.js b/app/js/services.js index c7078cba..27ca4cd2 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -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', []) 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', []) 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;