Skip to content

Commit

Permalink
* Filter word by word, not the total term, e.g. 'rock you we will' fi…
Browse files Browse the repository at this point in the history
…nds 'we will rock you'.
  • Loading branch information
muesli committed Sep 5, 2011
1 parent 079f758 commit 71117d3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/libtomahawk/database/databasecommand_allartists.cpp
Expand Up @@ -21,6 +21,7 @@
#include <QSqlQuery>

#include "databaseimpl.h"
#include "utils/tomahawkutils.h"
#include "utils/logger.h"


Expand All @@ -45,8 +46,14 @@ DatabaseCommand_AllArtists::exec( DatabaseImpl* dbi )

if ( !m_filter.isEmpty() )
{
filterToken = QString( "AND file_join.album = album.id AND file_join.track = track.id "
"AND ( artist.name LIKE :filterA OR album.name LIKE :filterB OR track.name LIKE :filterC )" );
QString filtersql;
QStringList sl = m_filter.split( " ", QString::SkipEmptyParts );
foreach( QString s, sl )
{
filtersql += QString( " AND ( artist.name LIKE '%%1%' OR album.name LIKE '%%1%' OR track.name LIKE '%%1%' )" ).arg( TomahawkUtils::sqlEscape( s ) );
}

filterToken = QString( "AND file_join.album = album.id AND file_join.track = track.id %1" ).arg( filtersql );
tables = "artist, track, album, file, file_join";
}
else
Expand All @@ -66,13 +73,6 @@ DatabaseCommand_AllArtists::exec( DatabaseImpl* dbi )
.arg( m_amount > 0 ? QString( "LIMIT 0, %1" ).arg( m_amount ) : QString() );

query.prepare( sql );
if ( !m_filter.isEmpty() )
{
query.bindValue( ":filterA", QString( "%%1%" ).arg( m_filter ) );
query.bindValue( ":filterB", QString( "%%1%" ).arg( m_filter ) );
query.bindValue( ":filterC", QString( "%%1%" ).arg( m_filter ) );
}

query.exec();

while( query.next() )
Expand Down
7 changes: 7 additions & 0 deletions src/libtomahawk/utils/tomahawkutils.cpp
Expand Up @@ -174,6 +174,13 @@ appLogDir()
}


QString
sqlEscape( QString sql )
{
return sql.replace( "'", "''" );
}


QString
timeToString( int seconds )
{
Expand Down
1 change: 1 addition & 0 deletions src/libtomahawk/utils/tomahawkutils.h
Expand Up @@ -75,6 +75,7 @@ namespace TomahawkUtils
DLLEXPORT QDir appDataDir();
DLLEXPORT QDir appLogDir();

DLLEXPORT QString sqlEscape( QString sql );
DLLEXPORT QString timeToString( int seconds );
DLLEXPORT QString ageToString( const QDateTime& time );
DLLEXPORT QString filesizeToString( unsigned int size );
Expand Down

0 comments on commit 71117d3

Please sign in to comment.