Skip to content

Commit 8e1cac3

Browse files
committed
Fixing accented search queries
1 parent e749b04 commit 8e1cac3

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/app/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ angular.module('spotmop', [
198198
* Search
199199
**/
200200
$scope.searchSubmit = function( query ){
201-
201+
202202
// track this navigation event
203203
Analytics.trackEvent('Search', 'Performed search', query);
204204

src/app/common/directives.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,29 @@ angular.module('spotmop.directives', [])
470470
})
471471

472472

473+
// replace accented characters with their un-accented counterparts
474+
// Credit: https://gist.github.com/monkeymonk/ccf698e7b71ba22f098a
475+
.filter('stripAccents', function(){
476+
return function (source) {
477+
var accent = [
478+
/[\300-\306]/g, /[\340-\346]/g, // A, a
479+
/[\310-\313]/g, /[\350-\353]/g, // E, e
480+
/[\314-\317]/g, /[\354-\357]/g, // I, i
481+
/[\322-\330]/g, /[\362-\370]/g, // O, o
482+
/[\331-\334]/g, /[\371-\374]/g, // U, u
483+
/[\321]/g, /[\361]/g, // N, n
484+
/[\307]/g, /[\347]/g, // C, c
485+
],
486+
noaccent = ['A','a','E','e','I','i','O','o','U','u','N','n','C','c'];
487+
488+
for (var i = 0; i < accent.length; i++){
489+
source = source.replace(accent[i], noaccent[i]);
490+
}
491+
492+
return source;
493+
};
494+
})
495+
473496
// get the appropriate sized image
474497
.filter('thumbnailImage', function(){
475498
return function( images ){

src/app/search/controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ angular.module('spotmop.search', [])
2121
/**
2222
* Main controller
2323
**/
24-
.controller('SearchController', function SearchController( $scope, $rootScope, $state, $stateParams, $timeout, SpotifyService ){
24+
.controller('SearchController', function SearchController( $scope, $rootScope, $state, $stateParams, $timeout, $filter, SpotifyService ){
2525

2626
$scope.tracklist = {tracks: [], type: 'track'};
2727
$scope.albums = [];
2828
$scope.artists = [];
2929
$scope.playlists = [];
3030
$scope.type = $stateParams.type;
31-
$scope.query = $stateParams.query;
31+
$scope.query = $filter('stripAccents')( $stateParams.query );
3232
$scope.loading = false;
3333
var searchDelayer;
3434

0 commit comments

Comments
 (0)