1
0
Fork 0

Improving vkontakte search

This commit is contained in:
magnolia-fan 2011-12-07 09:08:18 +04:00
parent bc98085090
commit 3ef7caf20d
2 changed files with 9 additions and 4 deletions

View File

@ -40,5 +40,5 @@ $('#search-form').live 'submit', ->
_search.loadArtistData $('#search').val() _search.loadArtistData $('#search').val()
false false
$('.data.artist').live 'click', -> $('.data.artist').live 'click', ->
_ajax.go "/artist/"+$(this).html().split(' ').join('+') _ajax.go "/artist/"+$(this).html().split(' ').join('+')+"/"
false false

View File

@ -10,7 +10,7 @@ class window.VkontakteMusic
query_results: {} query_results: {}
search: (artist, track, duration, callback, return_all = false) -> 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 if @query_results[query]? and not return_all
callback @query_results[query] callback @query_results[query]
that = this that = this
@ -58,8 +58,13 @@ class window.VkontakteMusic
b.score - a.score b.score - a.score
data data
prepareQuery: (artist, track) -> prepareQueryPart: (string) ->
artist+" "+this.trim(/[a-zA-Zа-яА-Я0-9\s-]+/.exec(track)[0]).replace(/\(.*\)/i, '').split('/')[0] this.trim string
.replace(/,\./, ' ')
.match(/[a-zA-Zа-яА-ЯёЁ0-9\s-']+/g).join(' ')
.replace(/(?:^|\s)?The\s/i, '')
.replace(/\(.*\)/i, '')
.split('/')[0]
trim: (str) -> trim: (str) ->
while str.indexOf(' ') isnt -1 while str.indexOf(' ') isnt -1