mikealmond / MusicBrainz

A PHP library to access MusicBrainz's Web Service v2
http://musicbrainz.org/doc/Development
MIT License
64 stars 26 forks source link

Scoring filter of 100 in first-recording-search.php #32

Open hawkwynd opened 5 years ago

hawkwynd commented 5 years ago

I've found that on many searches, results scoring < 100 actually contain the correct release I am looking for. Here's a snippet of the code which I am currently using to obtain the first-known-release of a recording by artist.

foreach($recordings as $recording){
        // If recording score is lower than what we have now, we want 100, but have found
        // 99 is acceptable in most cases to properly match on the original first recording
        // for this release.
         if (null != $lastScore && $lastScore < 99) {
            break;
         }      

        $lastScore        = $recording->getScore();
        $releaseDates     = $recording->getReleaseDates();
        $oldestReleaseKey = key($releaseDates);

        // Only compare the year of the release so we format the date field to just the year
        if( $releaseDates[$oldestReleaseKey]->format('Y') <= $firstRecording['releaseDate']->format('Y')){

            $firstRecording = array(
                'query'       => $args,
                'release'     => $recording->releases[$oldestReleaseKey],
                'releaseDate' => $recording->releases[$oldestReleaseKey]->getReleaseDate(),
                'release-count' => count($recording->releases),
                'recording'   => $recording,            
                'artist'      => $recording->getArtist(),
                'recordingId' => $recording->getId(),
                'trackLength' => $recording->getLength(),
                'execution'   => new stdClass(), // used for debugging 
                );

        }
    }

While, it's not really an issue, I thought it best to share this here. For some reason, I have found that many scores of 99 are being returned with the correct results, while scores of 100 have sometimes been returning incorrect results. By lowering the score threshold to 99, it seems to be giving me results much closer to the actual "First" recording.