Improving vkontakte search
This commit is contained in:
parent
bc98085090
commit
3ef7caf20d
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue