mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 20:00:13 +02:00
Cache track similarity in Query to speed up result insertion/removal
This commit is contained in:
@@ -622,6 +622,10 @@ float
|
|||||||
Query::howSimilar( const Tomahawk::result_ptr& r )
|
Query::howSimilar( const Tomahawk::result_ptr& r )
|
||||||
{
|
{
|
||||||
Q_D( Query );
|
Q_D( Query );
|
||||||
|
if (d->howSimilarCache.find(r->id()) != d->howSimilarCache.end())
|
||||||
|
{
|
||||||
|
return d->howSimilarCache[r->id()];
|
||||||
|
}
|
||||||
// result values
|
// result values
|
||||||
const QString& rArtistname = r->track()->artistSortname();
|
const QString& rArtistname = r->track()->artistSortname();
|
||||||
const QString& rAlbumname = r->track()->albumSortname();
|
const QString& rAlbumname = r->track()->albumSortname();
|
||||||
@@ -678,12 +682,16 @@ Query::howSimilar( const Tomahawk::result_ptr& r )
|
|||||||
const int mlatr = qMax( artistTrackname.length(), rArtistTrackname.length() );
|
const int mlatr = qMax( artistTrackname.length(), rArtistTrackname.length() );
|
||||||
const float dcatr = (float)( mlatr - atrdist ) / mlatr;
|
const float dcatr = (float)( mlatr - atrdist ) / mlatr;
|
||||||
|
|
||||||
return qMax( dctrk, qMax( dcatr, qMax( dcart, dcalb ) ) );
|
float resultScore = qMax( dctrk, qMax( dcatr, qMax( dcart, dcalb ) ) );
|
||||||
|
d->howSimilarCache[r->id()] = resultScore;
|
||||||
|
return resultScore;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// weighted, so album match is worth less than track title
|
// weighted, so album match is worth less than track title
|
||||||
return ( dcart * 4 + dcalb + dctrk * 5 ) / 10;
|
float resultScore = ( dcart * 4 + dcalb + dctrk * 5 ) / 10;
|
||||||
|
d->howSimilarCache[r->id()] = resultScore;
|
||||||
|
return resultScore;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
#include "Query.h"
|
#include "Query.h"
|
||||||
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
@@ -58,6 +59,8 @@ private:
|
|||||||
|
|
||||||
mutable QMutex mutex;
|
mutable QMutex mutex;
|
||||||
QWeakPointer< Tomahawk::Query > ownRef;
|
QWeakPointer< Tomahawk::Query > ownRef;
|
||||||
|
|
||||||
|
std::map<QString, float> howSimilarCache;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Tomahawk
|
} // Tomahawk
|
||||||
|
Reference in New Issue
Block a user