1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-19 23:41:51 +02:00

Merge pull request #292 from tomahawk-player/scorefixes

Improve scoring
This commit is contained in:
Christian Muehlhaeuser 2015-04-05 01:53:11 +02:00
commit e755b02f00
19 changed files with 55 additions and 82 deletions

View File

@ -105,7 +105,7 @@ Api_v1_5::playback( QxtWebRequestEvent* event, const QString& command )
} else {
trackInfo.insert( "resolvedBy", "<unknown resolver>" );
}
trackInfo.insert( "score", currentTrack->score() );
//FIXME? trackInfo.insert( "score", currentTrack->score() );
trackInfo.insert( "album", currentTrack->track()->album() );
trackInfo.insert( "albumpos", currentTrack->track()->albumpos() );
trackInfo.insert( "artist", currentTrack->track()->artist() );

View File

@ -387,8 +387,7 @@ Pipeline::addResultsToQuery( const query_ptr& query, const QList< result_ptr >&
QList< result_ptr > cleanResults;
foreach ( const result_ptr& r, results )
{
r->setScore( query->howSimilar( r ) );
if ( !query->isFullTextQuery() && r->score() < MINSCORE )
if ( !query->isFullTextQuery() && query->howSimilar( r ) < MINSCORE )
continue;
cleanResults << r;

View File

@ -122,6 +122,7 @@ Query::Query( const track_ptr& track, const result_ptr& result )
d->results << result;
d->playable = result->playable();
d->solved = true;
d->score = 1.0;
connect( result.data(), SIGNAL( statusChanged() ), SLOT( onResultStatusChanged() ) );
}
@ -151,6 +152,7 @@ Query::init()
d->solved = false;
d->playable = false;
d->saveResultHint = false;
d->score = 0.0;
}
@ -196,7 +198,7 @@ Query::addResults( const QList< Tomahawk::result_ptr >& newresults )
}*/
d->results << newresults;
qStableSort( d->results.begin(), d->results.end(), Query::resultSorter );
qStableSort( d->results.begin(), d->results.end(), std::bind( &Query::resultSorter, this, std::placeholders::_1, std::placeholders::_2 ) );
// hook up signals, and check solved status
foreach( const result_ptr& rp, newresults )
@ -265,8 +267,8 @@ Query::onResultStatusChanged()
{
Q_D( Query );
QMutexLocker lock( &d->mutex );
if ( d->results.count() )
qStableSort( d->results.begin(), d->results.end(), Query::resultSorter );
if ( !d->results.isEmpty() )
qStableSort( d->results.begin(), d->results.end(), std::bind( &Query::resultSorter, this, std::placeholders::_1, std::placeholders::_2 ) );
}
checkResults();
@ -404,8 +406,8 @@ Query::id() const
bool
Query::resultSorter( const result_ptr& left, const result_ptr& right )
{
const float ls = left->isOnline() ? left->score() : 0.0;
const float rs = right->isOnline() ? right->score() : 0.0;
const float ls = left->isOnline() ? howSimilar( left ) : 0.0;
const float rs = right->isOnline() ? howSimilar( right ) : 0.0;
if ( ls == rs )
{
@ -509,6 +511,15 @@ void
Query::checkResults()
{
Q_D( Query );
if ( !d->results.isEmpty() )
{
d->score = howSimilar( d->results.first() );
}
else
{
d->score = 0.0;
}
bool playable = false;
bool solved = false;
@ -521,7 +532,7 @@ Query::checkResults()
if ( rp->playable() )
playable = true;
if ( rp->isOnline() && rp->score() > 0.99 )
if ( rp->isOnline() && howSimilar( rp ) > 0.99 )
{
solved = true;
}
@ -602,6 +613,14 @@ Query::toString() const
}
float
Query::score() const
{
Q_D( const Query );
return d->score;
}
// TODO make clever (ft. featuring live (stuff) etc)
float
Query::howSimilar( const Tomahawk::result_ptr& r )
@ -716,4 +735,3 @@ Query::setWeakRef( QWeakPointer<Query> weakRef )
Q_D( Query );
d->ownRef = weakRef;
}

View File

@ -79,6 +79,8 @@ public:
/// true when any result has been found (score may be less than 1.0)
bool playable() const;
float score() const;
Tomahawk::Resolver* currentResolver() const;
QList< QPointer< Tomahawk::Resolver > > resolvedBy() const;
@ -109,7 +111,7 @@ public:
void setWeakRef( QWeakPointer< Tomahawk::Query > weakRef );
/// sorter for list of results
static bool resultSorter( const result_ptr& left, const result_ptr& right );
bool resultSorter( const result_ptr& left, const result_ptr& right );
signals:
void resultsAdded( const QList<Tomahawk::result_ptr>& );

View File

@ -39,6 +39,8 @@ private:
QList< Tomahawk::artist_ptr > artists;
QList< Tomahawk::album_ptr > albums;
QList< Tomahawk::result_ptr > results;
float score;
bool solved;
bool playable;
bool resolveFinished;

View File

@ -104,7 +104,6 @@ Result::Result( const QString& url, const track_ptr& track )
, m_bitrate( 0 )
, m_size( 0 )
, m_modtime( 0 )
, m_score( 0 )
, m_fileId( 0 )
, m_track( track )
{
@ -178,13 +177,6 @@ Result::mimetype() const
}
float
Result::score() const
{
return m_score;
}
RID
Result::id() const
{
@ -216,10 +208,8 @@ Result::playable() const
{
return resolvedByCollection()->isOnline();
}
else
{
return score() > 0.0;
}
return true;
}
@ -235,7 +225,7 @@ Result::toVariant() const
m.insert( "size", size() );
m.insert( "bitrate", bitrate() );
m.insert( "duration", m_track->duration() );
m.insert( "score", score() );
// m.insert( "score", score() );
m.insert( "sid", id() );
m.insert( "discnumber", m_track->discnumber() );
m.insert( "albumpos", m_track->albumpos() );
@ -254,9 +244,8 @@ Result::toString() const
{
if ( m_track )
{
return QString( "Result(%1, score: %2) %3 - %4%5 (%6)" )
return QString( "Result(%1) %2 - %3%4 (%5)" )
.arg( id() )
.arg( m_score )
.arg( m_track->artist() )
.arg( m_track->track() )
.arg( m_track->album().isEmpty() ? QString() : QString( " on %1" ).arg( m_track->album() ) )
@ -264,9 +253,8 @@ Result::toString() const
}
else
{
return QString( "Result(%1, score: %2) (%3)" )
return QString( "Result(%1) (%2)" )
.arg( id() )
.arg( m_score )
.arg( m_url );
}
}
@ -496,13 +484,6 @@ Result::modificationTime() const
}
void
Result::setScore( float score )
{
m_score = score;
}
void
Result::setFileId( unsigned int id )
{

View File

@ -89,7 +89,6 @@ public:
*/
ResultProvider* resolvedBy() const;
float score() const;
RID id() const;
bool isOnline() const;
bool playable() const;
@ -113,7 +112,6 @@ public:
unsigned int size() const;
unsigned int modificationTime() const;
void setScore( float score );
void setFileId( unsigned int id );
void setRID( RID id ) { m_rid = id; }
@ -177,8 +175,6 @@ private:
unsigned int m_bitrate;
unsigned int m_size;
unsigned int m_modtime;
float m_score;
unsigned int m_fileId;
track_ptr m_track;

View File

@ -866,7 +866,6 @@ AudioEngine::play( const QUrl& url )
result->setMimetype( tags["mimetype"].toString() );
}
result->setScore( 1.0 );
result->setResolvedByCollection( SourceList::instance()->getLocal()->collections().first(), false );
// Tomahawk::query_ptr qry = Tomahawk::Query::get( t );

View File

@ -161,7 +161,6 @@ DatabaseCommand_AllTracks::exec( DatabaseImpl* dbi )
result->setBitrate( bitrate );
result->setModificationTime( modificationTime );
result->setMimetype( mimetype );
result->setScore( 1.0f );
result->setResolvedByCollection( s->dbCollection(), false );
ql << Tomahawk::Query::getFixed( t, result );

View File

@ -83,7 +83,7 @@ DatabaseCommand_Resolve::resolve( DatabaseImpl* lib )
// STEP 1
QList< QPair<int, float> > tracks = lib->search( m_query );
if ( tracks.length() == 0 )
if ( tracks.isEmpty() )
{
qDebug() << "No candidates found in first pass, aborting resolve" << m_query->queryTrack()->toString();
emit results( m_query->id(), res );
@ -202,7 +202,7 @@ DatabaseCommand_Resolve::fullTextResolve( DatabaseImpl* lib )
emit albums( m_query->id(), albumList );
}
if ( trackPairs.length() == 0 )
if ( trackPairs.isEmpty() )
{
qDebug() << "No candidates found in first pass, aborting resolve" << m_query->fullTextQuery();
emit results( m_query->id(), res );
@ -279,15 +279,6 @@ DatabaseCommand_Resolve::fullTextResolve( DatabaseImpl* lib )
result->setRID( uuid() );
result->setResolvedByCollection( s->dbCollection() );
for ( int k = 0; k < trackPairs.count(); k++ )
{
if ( trackPairs.at( k ).first == (int)track->trackId() )
{
result->setScore( trackPairs.at( k ).second );
break;
}
}
res << result;
}

View File

@ -323,7 +323,6 @@ Tomahawk::DatabaseImpl::file( int fid )
r->setMimetype( query.value( 4 ).toString() );
r->setBitrate( query.value( 6 ).toUInt() );
r->setResolvedByCollection( s->dbCollection() );
r->setScore( 1.0 );
r->setFileId( fid );
}
@ -642,7 +641,6 @@ Tomahawk::DatabaseImpl::resultFromHint( const Tomahawk::query_ptr& origquery )
// Return http resulthint directly
res = Tomahawk::Result::get( url, track );
res->setRID( uuid() );
res->setScore( 1.0 );
const QUrl u = QUrl::fromUserInput( url );
res->setFriendlySource( u.host() );
@ -722,7 +720,6 @@ Tomahawk::DatabaseImpl::resultFromHint( const Tomahawk::query_ptr& origquery )
res->setSize( query.value( 2 ).toUInt() );
res->setMimetype( query.value( 4 ).toString() );
res->setBitrate( query.value( 6 ).toInt() );
res->setScore( 1.0 );
res->setRID( uuid() );
res->setResolvedByCollection( s->dbCollection() );
}

View File

@ -103,7 +103,7 @@ ColumnItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option
}
else if ( !item->result().isNull() || !item->query().isNull() )
{
float opacity = item->result() && item->result()->isOnline() ? item->result()->score() : 0.0;
float opacity = item->result() && item->result()->isOnline() ? 1.0 : 0.0;
opacity = qMax( (float)0.3, opacity );
QColor textColor = TomahawkUtils::alphaBlend( option.palette.color( QPalette::Foreground ), option.palette.color( QPalette::Background ), opacity );

View File

@ -286,13 +286,7 @@ PlayableModel::queryData( const query_ptr& query, int column, int role ) const
case Score:
{
float score;
if ( query->results().first()->isOnline() )
score = query->results().first()->score();
else
score = 0.0;
return scoreText( score );
return scoreText( query->score() );
break;
}

View File

@ -470,7 +470,7 @@ PlayableProxyModel::lessThan( int column, const Tomahawk::query_ptr& q1, const T
mtime1 = r->modificationTime();
size1 = r->size();
year1 = r->track()->year();
score1 = r->score();
score1 = q1->score();
origin1 = r->friendlySource().toLower();
}
if ( !q2->results().isEmpty() )
@ -480,7 +480,7 @@ PlayableProxyModel::lessThan( int column, const Tomahawk::query_ptr& q1, const T
mtime2 = r->modificationTime();
size2 = r->size();
year2 = r->track()->year();
score2 = r->score();
score2 = q2->score();
origin2 = r->friendlySource().toLower();
}

View File

@ -291,7 +291,7 @@ ScriptAccount::parseResultVariantList( const QVariantList& reslist )
rp->setPreview( m.value( "preview" ).toBool() );
rp->setPurchaseUrl( m.value( "purchaseUrl" ).toString() );
rp->setLinkUrl( m.value( "linkUrl" ).toString() );
rp->setScore( m.value( "score" ).toFloat() );
//FIXME? rp->setScore( m.value( "score" ).toFloat() );
rp->setChecked( m.value( "checked" ).toBool() );
//FIXME

View File

@ -122,7 +122,6 @@ ScriptCommand_AllTracks::onTracksJobDone( const QVariantMap& result )
QList< Tomahawk::query_ptr > queries;
foreach ( const Tomahawk::result_ptr& result, t )
{
result->setScore( 1.0 );
result->setResolvedByCollection( m_collection );
queries.append( result->toQuery() );
}

View File

@ -835,7 +835,7 @@ prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, Pl
{
float opacity = 0.0;
if ( item->query() && !item->query()->results().isEmpty() && item->query()->results().first()->isOnline() )
opacity = item->query()->results().first()->score();
opacity = item->query()->score();
opacity = qMax( (float)0.3, opacity );
QColor textColor = alphaBlend( option->palette.color( QPalette::Text ), option->palette.color( QPalette::BrightText ), opacity );

View File

@ -1,6 +1,6 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2014, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2015, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2012 Leo Franchi <lfranchi@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -230,15 +230,11 @@ SearchWidget::SearchWidget( const QString& search, QWidget* parent )
m_albumsModel->startLoading();
m_resultsModel->startLoading();
m_queries << Tomahawk::Query::get( search, uuid() );
foreach ( const Tomahawk::query_ptr& query, m_queries )
{
connect( query.data(), SIGNAL( artistsAdded( QList<Tomahawk::artist_ptr> ) ), SLOT( onArtistsFound( QList<Tomahawk::artist_ptr> ) ) );
connect( query.data(), SIGNAL( albumsAdded( QList<Tomahawk::album_ptr> ) ), SLOT( onAlbumsFound( QList<Tomahawk::album_ptr> ) ) );
connect( query.data(), SIGNAL( resultsAdded( QList<Tomahawk::result_ptr> ) ), SLOT( onResultsFound( QList<Tomahawk::result_ptr> ) ) );
connect( query.data(), SIGNAL( resolvingFinished( bool ) ), SLOT( onQueryFinished() ) );
}
m_query = Tomahawk::Query::get( search, uuid() );
connect( m_query.data(), SIGNAL( artistsAdded( QList<Tomahawk::artist_ptr> ) ), SLOT( onArtistsFound( QList<Tomahawk::artist_ptr> ) ) );
connect( m_query.data(), SIGNAL( albumsAdded( QList<Tomahawk::album_ptr> ) ), SLOT( onAlbumsFound( QList<Tomahawk::album_ptr> ) ) );
connect( m_query.data(), SIGNAL( resultsAdded( QList<Tomahawk::result_ptr> ) ), SLOT( onResultsFound( QList<Tomahawk::result_ptr> ) ) );
connect( m_query.data(), SIGNAL( resolvingFinished( bool ) ), SLOT( onQueryFinished() ) );
TomahawkUtils::fixMargins( this );
}
@ -324,7 +320,7 @@ SearchWidget::onResultsFound( const QList<Tomahawk::result_ptr>& results )
if ( !found )
{
m_results.insert( query, result->score() );
m_results.insert( query, /*FIXME*/ query->score() );
queries << query;
}
@ -335,7 +331,7 @@ SearchWidget::onResultsFound( const QList<Tomahawk::result_ptr>& results )
while ( queries.count() )
{
query_ptr q = queries.takeFirst();
if ( !q->results().count() )
if ( q->results().isEmpty() )
continue;
bool done = false;
@ -344,7 +340,7 @@ SearchWidget::onResultsFound( const QList<Tomahawk::result_ptr>& results )
PlayableItem* item = m_resultsModel->itemFromIndex( m_resultsModel->index( i, 0, QModelIndex() ) );
if ( item && item->query() && item->query()->numResults( true ) )
{
if ( item->query()->results().first()->score() < q->results().first()->score() )
if ( m_query->howSimilar( item->query()->results().first() ) < m_query->howSimilar( q->results().first() ) )
{
m_resultsModel->insertQuery( q, i );
done = true;

View File

@ -91,7 +91,7 @@ private:
PlayableModel* m_resultsModel;
Tomahawk::playlistinterface_ptr m_plInterface;
QList< Tomahawk::query_ptr > m_queries;
Tomahawk::query_ptr m_query;
QMap< Tomahawk::artist_ptr, float > m_artists;
QMap< Tomahawk::album_ptr, float > m_albums;
QMap< Tomahawk::query_ptr, float > m_results;