1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 08:34:34 +02:00

Decouple FuzzyIndex from DbCmd

This commit is contained in:
Uwe L. Korn
2014-06-01 20:07:56 +01:00
parent c56d5b90dc
commit a6c686a057
8 changed files with 63 additions and 24 deletions

View File

@@ -240,7 +240,8 @@ list(APPEND libSources
collection/TracksRequest.cpp
database/Database.cpp
database/FuzzyIndex.cpp
database/fuzzyindex/FuzzyIndex.cpp
database/fuzzyindex/DatabaseFuzzyIndex.cpp
database/DatabaseCollection.cpp
database/LocalCollection.cpp
database/DatabaseWorker.cpp

View File

@@ -22,7 +22,7 @@
#include <QSqlRecord>
#include "DatabaseImpl.h"
#include "FuzzyIndex.h"
#include "fuzzyindex/DatabaseFuzzyIndex.h"
#include "Source.h"
#include "TomahawkSqlQuery.h"
#include "jobview/IndexingJobItem.h"

View File

@@ -28,7 +28,7 @@
#include "Album.h"
#include "Artist.h"
#include "FuzzyIndex.h"
#include "fuzzyindex/DatabaseFuzzyIndex.h"
#include "PlaylistEntry.h"
#include "Result.h"
#include "SourceList.h"
@@ -89,7 +89,7 @@ Tomahawk::DatabaseImpl::DatabaseImpl( const QString& dbname )
query.exec( "UPDATE source SET isonline = 'false'" );
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();
if ( qApp->arguments().contains( "--dumpdb" ) )

View File

@@ -37,18 +37,18 @@
#include "TomahawkSqlQuery.h"
#include "Typedefs.h"
class FuzzyIndex;
namespace Tomahawk
{
class Database;
class DatabaseFuzzyIndex;
class DLLEXPORT DatabaseImpl : public QObject
{
Q_OBJECT
friend class FuzzyIndex;
friend class DatabaseFuzzyIndex;
friend class DatabaseCommand_UpdateSearchIndex;
public:
@@ -93,7 +93,7 @@ signals:
private:
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 init();
@@ -109,7 +109,7 @@ private:
int m_lastartid, m_lastalbid, m_lasttrkid;
QString m_dbid;
FuzzyIndex* m_fuzzyIndex;
Tomahawk::DatabaseFuzzyIndex* m_fuzzyIndex;
mutable QMutex m_mutex;
};

View 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

View 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

View File

@@ -18,12 +18,9 @@
#include "FuzzyIndex.h"
#include "collection/Collection.h"
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h"
#include "DatabaseImpl.h"
#include "Database.h"
#include "database/DatabaseImpl.h"
#include "PlaylistEntry.h"
#include "Source.h"
#include "Track.h"
@@ -44,12 +41,12 @@ using namespace lucene::queryParser;
using namespace lucene::search;
FuzzyIndex::FuzzyIndex( QObject* parent, bool wipe )
FuzzyIndex::FuzzyIndex( QObject* parent, const QString& filename, bool wipe )
: QObject( parent )
, m_luceneReader( 0 )
, m_luceneSearcher( 0 )
{
QString m_lucenePath = TomahawkUtils::appDataDir().absoluteFilePath( "tomahawk.lucene" );
m_lucenePath = TomahawkUtils::appDataDir().absoluteFilePath( filename );
QByteArray path = m_lucenePath.toUtf8();
const char* cPath = path.constData();
@@ -95,17 +92,16 @@ FuzzyIndex::wipeIndex()
beginIndexing();
endIndexing();
QTimer::singleShot( 0, this, SLOT( updateIndex() ) );
QTimer::singleShot( 0, this, SLOT( updateIndexSlot() ) );
return true; // FIXME
}
void
FuzzyIndex::updateIndex()
FuzzyIndex::updateIndexSlot()
{
Tomahawk::DatabaseCommand* cmd = new Tomahawk::DatabaseCommand_UpdateSearchIndex();
Tomahawk::Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
updateIndex();
}
@@ -216,7 +212,7 @@ FuzzyIndex::search( const Tomahawk::query_ptr& query )
{
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.";
return resultsmap;
@@ -307,7 +303,7 @@ FuzzyIndex::searchAlbum( const Tomahawk::query_ptr& query )
{
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.";
return resultsmap;

View File

@@ -26,7 +26,7 @@
#include <QMutex>
#include "Query.h"
#include "DatabaseCommand_UpdateSearchIndex.h"
#include "database/DatabaseCommand_UpdateSearchIndex.h"
namespace lucene
{
@@ -54,13 +54,15 @@ class FuzzyIndex : public QObject
Q_OBJECT
public:
explicit FuzzyIndex( QObject* parent, bool wipe = false );
~FuzzyIndex();
explicit FuzzyIndex( QObject* parent, const QString& filename, bool wipe = false );
virtual ~FuzzyIndex();
void beginIndexing();
void endIndexing();
void appendFields( const Tomahawk::IndexData& data );
virtual void updateIndex() = 0;
signals:
void indexReady();
@@ -71,7 +73,7 @@ public slots:
QMap< int, float > searchAlbum( const Tomahawk::query_ptr& query );
private slots:
void updateIndex();
void updateIndexSlot();
bool wipeIndex();
private: