mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 16:44:05 +02:00
Decouple FuzzyIndex from DbCmd
This commit is contained in:
@@ -240,7 +240,8 @@ list(APPEND libSources
|
|||||||
collection/TracksRequest.cpp
|
collection/TracksRequest.cpp
|
||||||
|
|
||||||
database/Database.cpp
|
database/Database.cpp
|
||||||
database/FuzzyIndex.cpp
|
database/fuzzyindex/FuzzyIndex.cpp
|
||||||
|
database/fuzzyindex/DatabaseFuzzyIndex.cpp
|
||||||
database/DatabaseCollection.cpp
|
database/DatabaseCollection.cpp
|
||||||
database/LocalCollection.cpp
|
database/LocalCollection.cpp
|
||||||
database/DatabaseWorker.cpp
|
database/DatabaseWorker.cpp
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
#include <QSqlRecord>
|
#include <QSqlRecord>
|
||||||
|
|
||||||
#include "DatabaseImpl.h"
|
#include "DatabaseImpl.h"
|
||||||
#include "FuzzyIndex.h"
|
#include "fuzzyindex/DatabaseFuzzyIndex.h"
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
#include "TomahawkSqlQuery.h"
|
#include "TomahawkSqlQuery.h"
|
||||||
#include "jobview/IndexingJobItem.h"
|
#include "jobview/IndexingJobItem.h"
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
#include "Album.h"
|
#include "Album.h"
|
||||||
#include "Artist.h"
|
#include "Artist.h"
|
||||||
#include "FuzzyIndex.h"
|
#include "fuzzyindex/DatabaseFuzzyIndex.h"
|
||||||
#include "PlaylistEntry.h"
|
#include "PlaylistEntry.h"
|
||||||
#include "Result.h"
|
#include "Result.h"
|
||||||
#include "SourceList.h"
|
#include "SourceList.h"
|
||||||
@@ -89,7 +89,7 @@ Tomahawk::DatabaseImpl::DatabaseImpl( const QString& dbname )
|
|||||||
query.exec( "UPDATE source SET isonline = 'false'" );
|
query.exec( "UPDATE source SET isonline = 'false'" );
|
||||||
query.exec( "DELETE FROM oplog WHERE source IS NULL AND singleton = 'true'" );
|
query.exec( "DELETE FROM oplog WHERE source IS NULL AND singleton = 'true'" );
|
||||||
|
|
||||||
m_fuzzyIndex = new FuzzyIndex( this, schemaUpdated );
|
m_fuzzyIndex = new Tomahawk::DatabaseFuzzyIndex( this, schemaUpdated );
|
||||||
|
|
||||||
tDebug( LOGVERBOSE ) << "Loaded index:" << t.elapsed();
|
tDebug( LOGVERBOSE ) << "Loaded index:" << t.elapsed();
|
||||||
if ( qApp->arguments().contains( "--dumpdb" ) )
|
if ( qApp->arguments().contains( "--dumpdb" ) )
|
||||||
|
@@ -37,18 +37,18 @@
|
|||||||
#include "TomahawkSqlQuery.h"
|
#include "TomahawkSqlQuery.h"
|
||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
|
|
||||||
class FuzzyIndex;
|
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
|
|
||||||
class Database;
|
class Database;
|
||||||
|
class DatabaseFuzzyIndex;
|
||||||
|
|
||||||
class DLLEXPORT DatabaseImpl : public QObject
|
class DLLEXPORT DatabaseImpl : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
friend class FuzzyIndex;
|
friend class DatabaseFuzzyIndex;
|
||||||
friend class DatabaseCommand_UpdateSearchIndex;
|
friend class DatabaseCommand_UpdateSearchIndex;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -93,7 +93,7 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
DatabaseImpl( const QString& dbname, bool internal );
|
DatabaseImpl( const QString& dbname, bool internal );
|
||||||
void setFuzzyIndex( FuzzyIndex* fi ) { m_fuzzyIndex = fi; }
|
void setFuzzyIndex( DatabaseFuzzyIndex* fi ) { m_fuzzyIndex = fi; }
|
||||||
void setDatabaseID( const QString& dbid ) { m_dbid = dbid; }
|
void setDatabaseID( const QString& dbid ) { m_dbid = dbid; }
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
@@ -109,7 +109,7 @@ private:
|
|||||||
int m_lastartid, m_lastalbid, m_lasttrkid;
|
int m_lastartid, m_lastalbid, m_lasttrkid;
|
||||||
|
|
||||||
QString m_dbid;
|
QString m_dbid;
|
||||||
FuzzyIndex* m_fuzzyIndex;
|
Tomahawk::DatabaseFuzzyIndex* m_fuzzyIndex;
|
||||||
mutable QMutex m_mutex;
|
mutable QMutex m_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
22
src/libtomahawk/database/fuzzyindex/DatabaseFuzzyIndex.cpp
Normal file
22
src/libtomahawk/database/fuzzyindex/DatabaseFuzzyIndex.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include "DatabaseFuzzyIndex.h"
|
||||||
|
|
||||||
|
#include "database/DatabaseImpl.h"
|
||||||
|
#include "database/Database.h"
|
||||||
|
|
||||||
|
namespace Tomahawk {
|
||||||
|
|
||||||
|
DatabaseFuzzyIndex::DatabaseFuzzyIndex( QObject* parent, bool wipe )
|
||||||
|
: FuzzyIndex( parent, "tomahawk.lucene", wipe )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DatabaseFuzzyIndex::updateIndex()
|
||||||
|
{
|
||||||
|
Tomahawk::DatabaseCommand* cmd = new Tomahawk::DatabaseCommand_UpdateSearchIndex();
|
||||||
|
Tomahawk::Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Tomahawk
|
18
src/libtomahawk/database/fuzzyindex/DatabaseFuzzyIndex.h
Normal file
18
src/libtomahawk/database/fuzzyindex/DatabaseFuzzyIndex.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef TOMAHAWK_DATABASEFUZZYINDEX_H
|
||||||
|
#define TOMAHAWK_DATABASEFUZZYINDEX_H
|
||||||
|
|
||||||
|
#include "FuzzyIndex.h"
|
||||||
|
|
||||||
|
namespace Tomahawk {
|
||||||
|
|
||||||
|
class DatabaseFuzzyIndex : public FuzzyIndex
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit DatabaseFuzzyIndex( QObject* parent, bool wipe = false );
|
||||||
|
|
||||||
|
virtual void updateIndex();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Tomahawk
|
||||||
|
|
||||||
|
#endif // TOMAHAWK_DATABASEFUZZYINDEX_H
|
@@ -18,12 +18,9 @@
|
|||||||
|
|
||||||
#include "FuzzyIndex.h"
|
#include "FuzzyIndex.h"
|
||||||
|
|
||||||
#include "collection/Collection.h"
|
|
||||||
#include "utils/TomahawkUtils.h"
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include "DatabaseImpl.h"
|
#include "database/DatabaseImpl.h"
|
||||||
#include "Database.h"
|
|
||||||
#include "PlaylistEntry.h"
|
#include "PlaylistEntry.h"
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
#include "Track.h"
|
#include "Track.h"
|
||||||
@@ -44,12 +41,12 @@ using namespace lucene::queryParser;
|
|||||||
using namespace lucene::search;
|
using namespace lucene::search;
|
||||||
|
|
||||||
|
|
||||||
FuzzyIndex::FuzzyIndex( QObject* parent, bool wipe )
|
FuzzyIndex::FuzzyIndex( QObject* parent, const QString& filename, bool wipe )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
, m_luceneReader( 0 )
|
, m_luceneReader( 0 )
|
||||||
, m_luceneSearcher( 0 )
|
, m_luceneSearcher( 0 )
|
||||||
{
|
{
|
||||||
QString m_lucenePath = TomahawkUtils::appDataDir().absoluteFilePath( "tomahawk.lucene" );
|
m_lucenePath = TomahawkUtils::appDataDir().absoluteFilePath( filename );
|
||||||
QByteArray path = m_lucenePath.toUtf8();
|
QByteArray path = m_lucenePath.toUtf8();
|
||||||
const char* cPath = path.constData();
|
const char* cPath = path.constData();
|
||||||
|
|
||||||
@@ -95,17 +92,16 @@ FuzzyIndex::wipeIndex()
|
|||||||
beginIndexing();
|
beginIndexing();
|
||||||
endIndexing();
|
endIndexing();
|
||||||
|
|
||||||
QTimer::singleShot( 0, this, SLOT( updateIndex() ) );
|
QTimer::singleShot( 0, this, SLOT( updateIndexSlot() ) );
|
||||||
|
|
||||||
return true; // FIXME
|
return true; // FIXME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FuzzyIndex::updateIndex()
|
FuzzyIndex::updateIndexSlot()
|
||||||
{
|
{
|
||||||
Tomahawk::DatabaseCommand* cmd = new Tomahawk::DatabaseCommand_UpdateSearchIndex();
|
updateIndex();
|
||||||
Tomahawk::Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -216,7 +212,7 @@ FuzzyIndex::search( const Tomahawk::query_ptr& query )
|
|||||||
{
|
{
|
||||||
if ( !m_luceneReader )
|
if ( !m_luceneReader )
|
||||||
{
|
{
|
||||||
if ( !IndexReader::indexExists( TomahawkUtils::appDataDir().absoluteFilePath( "tomahawk.lucene" ).toStdString().c_str() ) )
|
if ( !IndexReader::indexExists( m_lucenePath.toStdString().c_str() ) )
|
||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "index didn't exist.";
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "index didn't exist.";
|
||||||
return resultsmap;
|
return resultsmap;
|
||||||
@@ -307,7 +303,7 @@ FuzzyIndex::searchAlbum( const Tomahawk::query_ptr& query )
|
|||||||
{
|
{
|
||||||
if ( !m_luceneReader )
|
if ( !m_luceneReader )
|
||||||
{
|
{
|
||||||
if ( !IndexReader::indexExists( TomahawkUtils::appDataDir().absoluteFilePath( "tomahawk.lucene" ).toStdString().c_str() ) )
|
if ( !IndexReader::indexExists( m_lucenePath.toStdString().c_str() ) )
|
||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "index didn't exist.";
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "index didn't exist.";
|
||||||
return resultsmap;
|
return resultsmap;
|
@@ -26,7 +26,7 @@
|
|||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
|
||||||
#include "Query.h"
|
#include "Query.h"
|
||||||
#include "DatabaseCommand_UpdateSearchIndex.h"
|
#include "database/DatabaseCommand_UpdateSearchIndex.h"
|
||||||
|
|
||||||
namespace lucene
|
namespace lucene
|
||||||
{
|
{
|
||||||
@@ -54,13 +54,15 @@ class FuzzyIndex : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FuzzyIndex( QObject* parent, bool wipe = false );
|
explicit FuzzyIndex( QObject* parent, const QString& filename, bool wipe = false );
|
||||||
~FuzzyIndex();
|
virtual ~FuzzyIndex();
|
||||||
|
|
||||||
void beginIndexing();
|
void beginIndexing();
|
||||||
void endIndexing();
|
void endIndexing();
|
||||||
void appendFields( const Tomahawk::IndexData& data );
|
void appendFields( const Tomahawk::IndexData& data );
|
||||||
|
|
||||||
|
virtual void updateIndex() = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void indexReady();
|
void indexReady();
|
||||||
|
|
||||||
@@ -71,7 +73,7 @@ public slots:
|
|||||||
QMap< int, float > searchAlbum( const Tomahawk::query_ptr& query );
|
QMap< int, float > searchAlbum( const Tomahawk::query_ptr& query );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateIndex();
|
void updateIndexSlot();
|
||||||
bool wipeIndex();
|
bool wipeIndex();
|
||||||
|
|
||||||
private:
|
private:
|
Reference in New Issue
Block a user