1
0
Fork 0

Merge pull request #5 from endore-me/weight-for-name

give hight weight for name matching
This commit is contained in:
Gregory Eremin 2012-07-04 01:26:16 -07:00
commit e238727b1b
2 changed files with 13 additions and 1 deletions

View File

@ -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

View File

@ -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')