From 3ef7caf20d852c3550607fac69027c362a75d624 Mon Sep 17 00:00:00 2001 From: magnolia-fan Date: Wed, 7 Dec 2011 09:08:18 +0400 Subject: [PATCH] Improving vkontakte search --- app/assets/javascripts/search.coffee | 2 +- .../javascripts/vksearch/vkontakte_search.coffee | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/search.coffee b/app/assets/javascripts/search.coffee index 60dcd5b..3825292 100644 --- a/app/assets/javascripts/search.coffee +++ b/app/assets/javascripts/search.coffee @@ -40,5 +40,5 @@ $('#search-form').live 'submit', -> _search.loadArtistData $('#search').val() false $('.data.artist').live 'click', -> - _ajax.go "/artist/"+$(this).html().split(' ').join('+') + _ajax.go "/artist/"+$(this).html().split(' ').join('+')+"/" false diff --git a/app/assets/javascripts/vksearch/vkontakte_search.coffee b/app/assets/javascripts/vksearch/vkontakte_search.coffee index 240897f..e628341 100644 --- a/app/assets/javascripts/vksearch/vkontakte_search.coffee +++ b/app/assets/javascripts/vksearch/vkontakte_search.coffee @@ -10,7 +10,7 @@ class window.VkontakteMusic query_results: {} search: (artist, track, duration, callback, return_all = false) -> - query = this.prepareQuery artist, track + query = this.prepareQueryPart(artist)+" "+this.prepareQueryPart(track) if @query_results[query]? and not return_all callback @query_results[query] that = this @@ -58,8 +58,13 @@ class window.VkontakteMusic b.score - a.score data - prepareQuery: (artist, track) -> - artist+" "+this.trim(/[a-zA-Zа-яА-Я0-9\s-]+/.exec(track)[0]).replace(/\(.*\)/i, '').split('/')[0] + prepareQueryPart: (string) -> + this.trim string + .replace(/,\./, ' ') + .match(/[a-zA-Zа-яА-ЯёЁ0-9\s-']+/g).join(' ') + .replace(/(?:^|\s)?The\s/i, '') + .replace(/\(.*\)/i, '') + .split('/')[0] trim: (str) -> while str.indexOf(' ') isnt -1