diff --git a/app/js/services.js b/app/js/services.js index f6f3d62d..f17f660d 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -192,7 +192,7 @@ angular.module('myApp.services', []) apiUser.rFirstName = RichTextProcessor.wrapRichText(apiUser.last_name, {noLinks: true, noLinebreaks: true}) || apiUser.rPhone || 'DELETED'; apiUser.rFullName = RichTextProcessor.wrapRichText(apiUser.last_name, {noLinks: true, noLinebreaks: true}) || apiUser.rPhone || 'DELETED'; } - apiUser.sortName = $.trim((apiUser.last_name || '') + ' ' + apiUser.first_name); + apiUser.sortName = SearchIndexManager.cleanSearchText(apiUser.first_name + ' ' + (apiUser.last_name || '')); apiUser.sortStatus = apiUser.status && (apiUser.status.expires || apiUser.status.was_online) || 0; @@ -511,6 +511,7 @@ angular.module('myApp.services', []) return { createIndex: createIndex, indexObject: indexObject, + cleanSearchText: cleanSearchText, search: search }; @@ -521,19 +522,25 @@ angular.module('myApp.services', []) } } - function indexObject (id, searchText, searchIndex) { - if (searchIndex.fullTexts[id] !== undefined) { - return false; - } - - searchText = searchText.replace(badCharsRe, ' ').replace(trimRe, '').toLowerCase(); + function cleanSearchText (text) { + text = text.replace(badCharsRe, ' ').replace(trimRe, '').toLowerCase(); for (var key in accentsReplace) { if (accentsReplace.hasOwnProperty(key)) { - searchText = searchText.replace(accentsReplace[key], key); + text = text.replace(accentsReplace[key], key); } } + return text; + } + + function indexObject (id, searchText, searchIndex) { + if (searchIndex.fullTexts[id] !== undefined) { + return false; + } + + searchText = cleanSearchText(searchText); + if (!searchText.length) { return false; } @@ -561,13 +568,7 @@ angular.module('myApp.services', []) var shortIndexes = searchIndex.shortIndexes, fullTexts = searchIndex.fullTexts; - query = query.replace(badCharsRe, ' ').replace(trimRe, '').toLowerCase(); - - for (var key in accentsReplace) { - if (accentsReplace.hasOwnProperty(key)) { - query = query.replace(accentsReplace[key], key); - } - } + query = cleanSearchText(query); var queryWords = query.split(' '), foundObjs = false,