1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-18 23:09:42 +01:00

Add basic JS fuzzy resolve implementations

This commit is contained in:
Uwe L. Korn 2014-06-02 22:53:34 +01:00
parent 216a9f5593
commit b0c23a0740
5 changed files with 92 additions and 0 deletions

View File

@ -195,6 +195,25 @@ FuzzyIndex::appendFields( const Tomahawk::IndexData& data )
}
void
FuzzyIndex::deleteIndex()
{
if ( m_luceneReader != 0 )
{
tDebug( LOGVERBOSE ) << "Deleting old lucene stuff.";
m_luceneSearcher->close();
m_luceneReader->close();
delete m_luceneSearcher;
delete m_luceneReader;
m_luceneSearcher = 0;
m_luceneReader = 0;
}
TomahawkUtils::removeDirectory( m_lucenePath );
}
void
FuzzyIndex::loadLuceneIndex()
{

View File

@ -61,6 +61,13 @@ public:
void endIndexing();
void appendFields( const Tomahawk::IndexData& data );
/**
* Delete the index from the harddrive.
*
* You should no longer use this FuzzyIndex object after this call.
*/
void deleteIndex();
virtual void updateIndex() = 0;
signals:

View File

@ -487,6 +487,59 @@ JSResolverHelper::reportStreamUrl( const QString& qid,
}
bool
JSResolverHelper::hasFuzzyIndex()
{
return !m_resolver->d_func()->fuzzyIndex.isNull();
}
void
JSResolverHelper::createFuzzyIndex( const QVariantList& list )
{
// TODO
}
void
JSResolverHelper::addToFuzzyIndex( const QVariantList& list )
{
// TODO
}
QMap<int, float>
JSResolverHelper::searchFuzzyIndex( const QString& query )
{
if ( m_resolver->d_func()->fuzzyIndex )
{
return m_resolver->d_func()->fuzzyIndex->search( Query::get( query, QString() ) );
}
return QMap<int, float>();
}
QMap<int, float>
JSResolverHelper::resolveFromFuzzyIndex( const QString& artist, const QString& album, const QString& track )
{
if ( m_resolver->d_func()->fuzzyIndex )
{
// Important: Do not autoresolve!
query_ptr query = Query::get( artist, album, track, QString(), false );
return m_resolver->d_func()->fuzzyIndex->search( query );
}
return QMap<int, float>();
}
void
JSResolverHelper::deleteFuzzyIndex()
{
m_resolver->d_func()->fuzzyIndex->deleteIndex();
m_resolver->d_func()->fuzzyIndex->deleteLater();
}
void
JSResolverHelper::returnStreamUrl( const QString& streamUrl, const QMap<QString, QString>& headers,
boost::function< void( const QString&, QSharedPointer< QIODevice >& ) > callback )

View File

@ -47,6 +47,17 @@ public:
Q_INVOKABLE void reportStreamUrl( const QString& qid, const QString& streamUrl );
Q_INVOKABLE void reportStreamUrl( const QString& qid, const QString& streamUrl, const QVariantMap& headers );
/**
* Clucene indices for JS resolvers
**/
Q_INVOKABLE bool hasFuzzyIndex();
Q_INVOKABLE void createFuzzyIndex( const QVariantList& list );
Q_INVOKABLE void addToFuzzyIndex( const QVariantList& list );
Q_INVOKABLE QMap<int, float> searchFuzzyIndex( const QString& query );
Q_INVOKABLE QMap<int, float> resolveFromFuzzyIndex( const QString& artist, const QString& album, const QString& tracks );
Q_INVOKABLE void deleteFuzzyIndex();
void customIODeviceFactory( const Tomahawk::result_ptr&, const QString& url,
boost::function< void( const QString&, QSharedPointer< QIODevice >& ) > callback ); // async

View File

@ -25,6 +25,7 @@
#include "JSResolver.h"
#include "JSResolverHelper.h"
#include "database/fuzzyindex/FuzzyIndex.h"
class JSResolverPrivate
{
@ -57,6 +58,7 @@ private:
Tomahawk::ExternalResolver::ErrorState error;
JSResolverHelper* resolverHelper;
QScopedPointer<FuzzyIndex> fuzzyIndex;
QPointer< AccountConfigWidget > configWidget;
QList< QVariant > dataWidgets;
QStringList requiredScriptPaths;