mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
* Make FuzzyIndex robuster.
This commit is contained in:
@@ -24,7 +24,9 @@
|
|||||||
#include <CLucene.h>
|
#include <CLucene.h>
|
||||||
#include <CLucene/queryParser/MultiFieldQueryParser.h>
|
#include <CLucene/queryParser/MultiFieldQueryParser.h>
|
||||||
|
|
||||||
|
#include "DatabaseCommand_UpdateSearchIndex.h"
|
||||||
#include "DatabaseImpl.h"
|
#include "DatabaseImpl.h"
|
||||||
|
#include "Database.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
@@ -38,7 +40,7 @@ using namespace lucene::queryParser;
|
|||||||
using namespace lucene::search;
|
using namespace lucene::search;
|
||||||
|
|
||||||
|
|
||||||
FuzzyIndex::FuzzyIndex( QObject* parent, bool wipeIndex )
|
FuzzyIndex::FuzzyIndex( QObject* parent, bool wipe )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
, m_luceneReader( 0 )
|
, m_luceneReader( 0 )
|
||||||
, m_luceneSearcher( 0 )
|
, m_luceneSearcher( 0 )
|
||||||
@@ -56,15 +58,11 @@ FuzzyIndex::FuzzyIndex( QObject* parent, bool wipeIndex )
|
|||||||
catch ( CLuceneError& error )
|
catch ( CLuceneError& error )
|
||||||
{
|
{
|
||||||
tDebug() << "Caught CLucene error:" << error.what();
|
tDebug() << "Caught CLucene error:" << error.what();
|
||||||
Q_ASSERT( false );
|
wipe = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( wipeIndex )
|
if ( wipe )
|
||||||
{
|
wipeIndex();
|
||||||
tLog( LOGVERBOSE ) << "Wiping fuzzy index...";
|
|
||||||
beginIndexing();
|
|
||||||
endIndexing();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -77,6 +75,27 @@ FuzzyIndex::~FuzzyIndex()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
FuzzyIndex::wipeIndex()
|
||||||
|
{
|
||||||
|
tLog( LOGVERBOSE ) << "Wiping fuzzy index...";
|
||||||
|
beginIndexing();
|
||||||
|
endIndexing();
|
||||||
|
|
||||||
|
QTimer::singleShot( 0, this, SLOT( updateIndex() ) );
|
||||||
|
|
||||||
|
return true; // FIXME
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FuzzyIndex::updateIndex()
|
||||||
|
{
|
||||||
|
DatabaseCommand* cmd = new DatabaseCommand_UpdateSearchIndex();
|
||||||
|
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FuzzyIndex::beginIndexing()
|
FuzzyIndex::beginIndexing()
|
||||||
{
|
{
|
||||||
@@ -170,7 +189,8 @@ FuzzyIndex::appendFields( const QMap< unsigned int, QMap< QString, QString > >&
|
|||||||
catch( CLuceneError& error )
|
catch( CLuceneError& error )
|
||||||
{
|
{
|
||||||
tDebug() << "Caught CLucene error:" << error.what();
|
tDebug() << "Caught CLucene error:" << error.what();
|
||||||
Q_ASSERT( false );
|
|
||||||
|
wipeIndex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +283,8 @@ FuzzyIndex::search( const Tomahawk::query_ptr& query )
|
|||||||
catch( CLuceneError& error )
|
catch( CLuceneError& error )
|
||||||
{
|
{
|
||||||
tDebug() << "Caught CLucene error:" << error.what();
|
tDebug() << "Caught CLucene error:" << error.what();
|
||||||
Q_ASSERT( false );
|
|
||||||
|
wipeIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultsmap;
|
return resultsmap;
|
||||||
@@ -317,7 +338,8 @@ FuzzyIndex::searchAlbum( const Tomahawk::query_ptr& query )
|
|||||||
catch( CLuceneError& error )
|
catch( CLuceneError& error )
|
||||||
{
|
{
|
||||||
tDebug() << "Caught CLucene error:" << error.what();
|
tDebug() << "Caught CLucene error:" << error.what();
|
||||||
Q_ASSERT( false );
|
|
||||||
|
wipeIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultsmap;
|
return resultsmap;
|
||||||
|
@@ -55,7 +55,7 @@ class FuzzyIndex : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FuzzyIndex( QObject* parent, bool wipeIndex = false );
|
explicit FuzzyIndex( QObject* parent, bool wipe = false );
|
||||||
~FuzzyIndex();
|
~FuzzyIndex();
|
||||||
|
|
||||||
void beginIndexing();
|
void beginIndexing();
|
||||||
@@ -71,7 +71,12 @@ public slots:
|
|||||||
QMap< int, float > search( const Tomahawk::query_ptr& query );
|
QMap< int, float > search( const Tomahawk::query_ptr& query );
|
||||||
QMap< int, float > searchAlbum( const Tomahawk::query_ptr& query );
|
QMap< int, float > searchAlbum( const Tomahawk::query_ptr& query );
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void updateIndex();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool wipeIndex();
|
||||||
|
|
||||||
QMutex m_mutex;
|
QMutex m_mutex;
|
||||||
QString m_lucenePath;
|
QString m_lucenePath;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user