Replaced the custom weighting calculation by making use of MusicBrainz scoring scheme.
This commit is contained in:
@@ -46,19 +46,6 @@ module MusicBrainz
|
||||
:query => CGI.escape(name).gsub(/\!/, '\!') + '~',
|
||||
:limit => 50
|
||||
})
|
||||
artists.each { |artist|
|
||||
if artist[:name].downcase == name.downcase
|
||||
artist[:weight] += 80
|
||||
elsif artist[:name].downcase.gsub(/\s/, "") == name.downcase.gsub(/\s/, "")
|
||||
artist[:weight] += 25
|
||||
elsif artist[:aliases].include? name
|
||||
artist[:weight] += 20
|
||||
elsif artist[:aliases].map { |item| item.downcase }.include?(name.downcase)
|
||||
artist[:weight] += 10
|
||||
elsif artist[:aliases].map { |item| item.downcase.gsub(/\s/, "") }.include?(name.downcase.gsub(/\s/, ""))
|
||||
artist[:weight] += 5
|
||||
end
|
||||
}
|
||||
artists.sort{ |a, b| b[:weight] <=> a[:weight] }.take(10)
|
||||
end
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ module MusicBrainz
|
||||
artists << {
|
||||
:name => a.first_element_child.text.gsub(/[`’]/, "'"),
|
||||
:sort_name => safe_get_value(a, "sort-name").gsub(/[`’]/, "'"),
|
||||
:weight => 0,
|
||||
:score => (safe_get_attr(a, nil, "score") .to_i rescue 0),
|
||||
:desc => safe_get_value(a, "disambiguation"),
|
||||
:type => safe_get_attr(a, nil, "type"),
|
||||
:mbid => safe_get_attr(a, nil, "id"),
|
||||
|
||||
Reference in New Issue
Block a user