diff --git a/lib/models/music_brainz/artist.rb b/lib/models/music_brainz/artist.rb index 447b8df..fe1aa03 100644 --- a/lib/models/music_brainz/artist.rb +++ b/lib/models/music_brainz/artist.rb @@ -60,7 +60,13 @@ module MusicBrainz :mbid => self.safe_get_attr(a, nil, 'id') } aliases = a.css('alias-list > alias').map{ |item| item.text } - if aliases.include? name + if artist[:name] == name + artist[:weight] += 100 + elsif artist[:name].downcase == name.downcase + artist[:weight] += 50 + elsif artist[:name].downcase.gsub(/\s/, '') == name.downcase.gsub(/\s/, '') + artist[:weight] += 25 + elsif aliases.include? name artist[:weight] += 20 elsif aliases.map{ |item| item.downcase }.include? name.downcase artist[:weight] += 10 diff --git a/test/test_musicbrainz_artist.rb b/test/test_musicbrainz_artist.rb index df21a4f..6977c88 100644 --- a/test/test_musicbrainz_artist.rb +++ b/test/test_musicbrainz_artist.rb @@ -13,6 +13,12 @@ class TestMusicbrainzArtist < Test::Unit::TestCase assert_operator(0, :<, matches.length) assert_equal("Kasabian", matches.first[:name]) end + + should "find name first than alias" do + matches = MusicBrainz::Artist.search('Chris Martin') + assert_operator(0, :<, matches.length) + assert_equal("Chris Martin", matches.first[:name]) + end should "get correct result by name" do @artist = MusicBrainz::Artist.find_by_name('Kasabian')