コード例 #1
0
void
PipelineStatusItem::resolving( const Tomahawk::query_ptr& query )
{
    if ( query->isFullTextQuery() )
        m_latestQuery = query->fullTextQuery();
    else
        m_latestQuery = QString( "%1 - %2" ).arg( query->queryTrack()->artist() ).arg( query->queryTrack()->track() );

    Q_ASSERT( !m_latestQuery.isEmpty() );

    emit statusChanged();
}
コード例 #2
0
ファイル: FuzzyIndex.cpp プロジェクト: eartle/tomahawk
QMap< int, float >
FuzzyIndex::searchAlbum( const Tomahawk::query_ptr& query )
{
    Q_ASSERT( query->isFullTextQuery() );

    QMutexLocker lock( &m_mutex );

    QMap< int, float > resultsmap;
    try
    {
        if ( !m_luceneReader )
        {
            if ( !IndexReader::indexExists( TomahawkUtils::appDataDir().absoluteFilePath( "tomahawk.lucene" ).toStdString().c_str() ) )
            {
                qDebug() << Q_FUNC_INFO << "index didn't exist.";
                return resultsmap;
            }

            m_luceneReader = IndexReader::open( m_luceneDir );
            m_luceneSearcher = _CLNEW IndexSearcher( m_luceneReader );
        }

        QueryParser parser( _T( "album" ), m_analyzer );
        QString escapedName = QString::fromWCharArray( parser.escape( DatabaseImpl::sortname( query->fullTextQuery() ).toStdWString().c_str() ) );

        Query* qry = _CLNEW FuzzyQuery( _CLNEW Term( _T( "album" ), escapedName.toStdWString().c_str() ) );
        Hits* hits = m_luceneSearcher->search( qry );
        for ( uint i = 0; i < hits->length(); i++ )
        {
            Document* d = &hits->doc( i );

            float score = hits->score( i );
            int id = QString::fromWCharArray( d->get( _T( "albumid" ) ) ).toInt();

            if ( score > 0.30 )
            {
                resultsmap.insert( id, score );
//                tDebug() << "Index hit:" << id << score;
            }
        }

        delete hits;
        delete qry;
    }
    catch( CLuceneError& error )
    {
        tDebug() << "Caught CLucene error:" << error.what();
        Q_ASSERT( false );
    }

    return resultsmap;
}
コード例 #3
0
ファイル: FuzzyIndex.cpp プロジェクト: RahulKondi/tomahawk
QMap< int, float >
FuzzyIndex::searchAlbum( const Tomahawk::query_ptr& query )
{
    Q_ASSERT( query->isFullTextQuery() );

    QMutexLocker lock( &m_mutex );

    QMap< int, float > resultsmap;
    try
    {
        if ( !m_luceneReader )
        {
            if ( !IndexReader::indexExists( m_luceneDir ) )
            {
                tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "index didn't exist.";
                return resultsmap;
            }

            m_luceneReader = IndexReader::open( m_luceneDir );
            m_luceneSearcher = newLucene<IndexSearcher>( m_luceneReader );
        }

        QueryParserPtr parser = newLucene<QueryParser>( LuceneVersion::LUCENE_CURRENT, L"album", m_analyzer );
        QString q = Tomahawk::DatabaseImpl::sortname( query->fullTextQuery() );

        FuzzyQueryPtr qry = newLucene<FuzzyQuery>( newLucene<Term>( L"album", q.toStdWString() ) );
        TopScoreDocCollectorPtr collector = TopScoreDocCollector::create( 99999, false );
        m_luceneSearcher->search( boost::dynamic_pointer_cast<Query>( qry ), collector );
        Collection<ScoreDocPtr> hits = collector->topDocs()->scoreDocs;

        for ( int i = 0; i < collector->getTotalHits(); i++ )
        {
            DocumentPtr d = m_luceneSearcher->doc( hits[i]->doc );
            float score = hits[i]->score;
            int id = QString::fromStdWString( d->get( L"albumid" ) ).toInt();

            if ( score > 0.30 )
            {
                resultsmap.insert( id, score );
//                tDebug() << "Index hit:" << id << score;
            }
        }
    }
    catch( LuceneException& error )
    {
        tDebug() << "Caught Lucene error:" << error.what();

        QTimer::singleShot( 0, this, SLOT( wipeIndex() ) );
    }

    return resultsmap;
}
コード例 #4
0
ファイル: qtscriptresolver.cpp プロジェクト: xevix/tomahawk
void
QtScriptResolver::resolve( const Tomahawk::query_ptr& query )
{
    if ( QThread::currentThread() != thread() )
    {
        QMetaObject::invokeMethod( this, "resolve", Qt::QueuedConnection, Q_ARG(Tomahawk::query_ptr, query) );
        return;
    }

    QString eval;
    if ( !query->isFullTextQuery() )
    {
        eval = QString( RESOLVER_LEGACY_CODE2 "resolver.resolve( '%1', '%2', '%3', '%4' );" )
               .arg( query->id().replace( "'", "\\'" ) )
               .arg( query->artist().replace( "'", "\\'" ) )
               .arg( query->album().replace( "'", "\\'" ) )
               .arg( query->track().replace( "'", "\\'" ) );
    }
    else
    {
        eval = QString( "if(Tomahawk.resolver.instance !== undefined) {"
                        "   resolver.search( '%1', '%2' );"
                        "} else {"
                        "   resolve( '%1', '', '', '%2' );"
                        "}"
                      )
               .arg( query->id().replace( "'", "\\'" ) )
               .arg( query->fullTextQuery().replace( "'", "\\'" ) );
    }

    QVariantMap m = m_engine->mainFrame()->evaluateJavaScript( eval ).toMap();

    if( m.isEmpty() )
    {
        // if the resolver doesn't return anything, async api is used
        return;
    }

    qDebug() << "JavaScript Result:" << m;

    const QString qid = query->id();
    const QVariantList reslist = m.value( "results" ).toList();

    QList< Tomahawk::result_ptr > results = parseResultVariantList( reslist );

    Tomahawk::Pipeline::instance()->reportResults( qid, results );
}
コード例 #5
0
ファイル: FuzzyIndex.cpp プロジェクト: Alex237/tomahawk
QMap< int, float >
FuzzyIndex::searchAlbum( const Tomahawk::query_ptr& query )
{
    Q_ASSERT( query->isFullTextQuery() );

//    QMutexLocker lock( &m_mutex );
    QMap< int, float > resultsmap;
    if ( !m_luceneReader || !m_luceneSearcher )
        return resultsmap;

    try
    {
        QueryParserPtr parser = newLucene<QueryParser>( LuceneVersion::LUCENE_CURRENT, L"album", m_analyzer );
        const QString q = Tomahawk::DatabaseImpl::sortname( query->fullTextQuery() );

        FuzzyQueryPtr qry = newLucene<FuzzyQuery>( newLucene<Term>( L"album", q.toStdWString() ) );
        TopScoreDocCollectorPtr collector = TopScoreDocCollector::create( 99999, false );
        m_luceneSearcher->search( boost::dynamic_pointer_cast<Query>( qry ), collector );
        Collection<ScoreDocPtr> hits = collector->topDocs()->scoreDocs;

        for ( int i = 0; i < collector->getTotalHits(); i++ )
        {
            DocumentPtr d = m_luceneSearcher->doc( hits[i]->doc );
            float score = hits[i]->score;
            int id = QString::fromStdWString( d->get( L"albumid" ) ).toInt();

            if ( score > 0.30 )
            {
                resultsmap.insert( id, score );
//                tDebug() << "Index hit:" << id << score;
            }
        }
    }
    catch( LuceneException& error )
    {
        tDebug() << "Caught Lucene error:" << QString::fromWCharArray( error.getError().c_str() );
    }

    return resultsmap;
}
コード例 #6
0
ファイル: FuzzyIndex.cpp プロジェクト: eartle/tomahawk
QMap< int, float >
FuzzyIndex::search( const Tomahawk::query_ptr& query )
{
    QMutexLocker lock( &m_mutex );

    QMap< int, float > resultsmap;
    try
    {
        if ( !m_luceneReader )
        {
            if ( !IndexReader::indexExists( TomahawkUtils::appDataDir().absoluteFilePath( "tomahawk.lucene" ).toStdString().c_str() ) )
            {
                qDebug() << Q_FUNC_INFO << "index didn't exist.";
                return resultsmap;
            }

            m_luceneReader = IndexReader::open( m_luceneDir );
            m_luceneSearcher = _CLNEW IndexSearcher( m_luceneReader );
        }

        float minScore;
        const TCHAR** fields = 0;
        MultiFieldQueryParser parser( fields, m_analyzer );
        BooleanQuery* qry = _CLNEW BooleanQuery();

        if ( query->isFullTextQuery() )
        {
            QString escapedQuery = QString::fromWCharArray( parser.escape( DatabaseImpl::sortname( query->fullTextQuery() ).toStdWString().c_str() ) );

            Term* term = _CLNEW Term( _T( "track" ), escapedQuery.toStdWString().c_str() );
            Query* fqry = _CLNEW FuzzyQuery( term );
            qry->add( fqry, true, BooleanClause::SHOULD );

            term = _CLNEW Term( _T( "artist" ), escapedQuery.toStdWString().c_str() );
            fqry = _CLNEW FuzzyQuery( term );
            qry->add( fqry, true, BooleanClause::SHOULD );

            term = _CLNEW Term( _T( "fulltext" ), escapedQuery.toStdWString().c_str() );
            fqry = _CLNEW FuzzyQuery( term );
            qry->add( fqry, true, BooleanClause::SHOULD );

            minScore = 0.00;
        }
        else
        {
            QString track = QString::fromWCharArray( parser.escape( DatabaseImpl::sortname( query->track() ).toStdWString().c_str() ) );
            QString artist = QString::fromWCharArray( parser.escape( DatabaseImpl::sortname( query->artist() ).toStdWString().c_str() ) );
//            QString album = QString::fromWCharArray( parser.escape( query->album().toStdWString().c_str() ) );

            Term* term = _CLNEW Term( _T( "track" ), track.toStdWString().c_str() );
            Query* fqry = _CLNEW FuzzyQuery( term );
            qry->add( fqry, true, BooleanClause::MUST );

            term = _CLNEW Term( _T( "artist" ), artist.toStdWString().c_str() );
            fqry = _CLNEW FuzzyQuery( term );
            qry->add( fqry, true, BooleanClause::MUST );

            minScore = 0.00;
        }

        Hits* hits = m_luceneSearcher->search( qry );
        for ( uint i = 0; i < hits->length(); i++ )
        {
            Document* d = &hits->doc( i );

            float score = hits->score( i );
            int id = QString::fromWCharArray( d->get( _T( "trackid" ) ) ).toInt();

            if ( score > minScore )
            {
                resultsmap.insert( id, score );
//                tDebug() << "Index hit:" << id << score << QString::fromWCharArray( ((Query*)qry)->toString() );
            }
        }

        delete hits;
        delete qry;
    }
    catch( CLuceneError& error )
    {
        tDebug() << "Caught CLucene error:" << error.what();
        Q_ASSERT( false );
    }

    return resultsmap;
}
コード例 #7
0
ファイル: FuzzyIndex.cpp プロジェクト: RahulKondi/tomahawk
QMap< int, float >
FuzzyIndex::search( const Tomahawk::query_ptr& query )
{
    QMutexLocker lock( &m_mutex );

    QMap< int, float > resultsmap;
    try
    {
        if ( !m_luceneReader )
        {
            if ( !IndexReader::indexExists( m_luceneDir ) )
            {
                tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "index didn't exist.";
                return resultsmap;
            }

            m_luceneReader = IndexReader::open( m_luceneDir );
            m_luceneSearcher = newLucene<IndexSearcher>( m_luceneReader );
        }

        float minScore;
        Collection<String> fields; // = newCollection<String>();
        MultiFieldQueryParserPtr parser = newLucene<MultiFieldQueryParser>( LuceneVersion::LUCENE_CURRENT, fields, m_analyzer );
        BooleanQueryPtr qry = newLucene<BooleanQuery>();

        if ( query->isFullTextQuery() )
        {
            QString q = Tomahawk::DatabaseImpl::sortname( query->fullTextQuery() );

            FuzzyQueryPtr fqry = newLucene<FuzzyQuery>( newLucene<Term>( L"track", q.toStdWString() ) );
            qry->add( boost::dynamic_pointer_cast<Query>( fqry ), BooleanClause::SHOULD );

            FuzzyQueryPtr fqry2 = newLucene<FuzzyQuery>( newLucene<Term>( L"artist", q.toStdWString() ) );
            qry->add( boost::dynamic_pointer_cast<Query>( fqry2 ), BooleanClause::SHOULD );

            FuzzyQueryPtr fqry3 = newLucene<FuzzyQuery>( newLucene<Term>( L"fulltext", q.toStdWString() ) );
            qry->add( boost::dynamic_pointer_cast<Query>( fqry3 ), BooleanClause::SHOULD );

            minScore = 0.00;
        }
        else
        {
            QString track = Tomahawk::DatabaseImpl::sortname( query->queryTrack()->track() );
            QString artist = Tomahawk::DatabaseImpl::sortname( query->queryTrack()->artist() );
            //QString album = Tomahawk::DatabaseImpl::sortname( query->queryTrack()->album() );

            FuzzyQueryPtr fqry = newLucene<FuzzyQuery>( newLucene<Term>( L"track", track.toStdWString() ) );
            qry->add( boost::dynamic_pointer_cast<Query>( fqry ), BooleanClause::MUST );

            FuzzyQueryPtr fqry2 = newLucene<FuzzyQuery>( newLucene<Term>( L"artist", artist.toStdWString() ) );
            qry->add( boost::dynamic_pointer_cast<Query>( fqry2 ), BooleanClause::MUST );

            minScore = 0.00;
        }

        TopScoreDocCollectorPtr collector = TopScoreDocCollector::create( 50, false );
        m_luceneSearcher->search( qry, collector );
        Collection<ScoreDocPtr> hits = collector->topDocs()->scoreDocs;

        for ( int i = 0; i < collector->getTotalHits() && i < 50; i++ )
        {
            DocumentPtr d = m_luceneSearcher->doc( hits[i]->doc );
            float score = hits[i]->score;
            int id = QString::fromStdWString( d->get( L"trackid" ) ).toInt();

            if ( score > minScore )
            {
                resultsmap.insert( id, score );
//                tDebug() << "Index hit:" << id << score << QString::fromWCharArray( ((Query*)qry)->toString() );
            }
        }
    }
    catch( LuceneException& error )
    {
        tDebug() << "Caught Lucene error:" << error.what() << query->toString();

        QTimer::singleShot( 0, this, SLOT( wipeIndex() ) );
    }

    return resultsmap;
}
コード例 #8
0
ファイル: FuzzyIndex.cpp プロジェクト: Alex237/tomahawk
QMap< int, float >
FuzzyIndex::search( const Tomahawk::query_ptr& query )
{
//    QMutexLocker lock( &m_mutex );
    QMap< int, float > resultsmap;
    if ( !m_luceneReader || !m_luceneSearcher )
        return resultsmap;

    try
    {
//        float minScore = 0.00;
        Collection<String> fields; // = newCollection<String>();
        MultiFieldQueryParserPtr parser = newLucene<MultiFieldQueryParser>( LuceneVersion::LUCENE_CURRENT, fields, m_analyzer );
        BooleanQueryPtr qry = newLucene<BooleanQuery>();

        if ( query->isFullTextQuery() )
        {
            const QString q = Tomahawk::DatabaseImpl::sortname( query->fullTextQuery() );

            FuzzyQueryPtr fqry = newLucene<FuzzyQuery>( newLucene<Term>( L"track", q.toStdWString() ) );
            qry->add( boost::dynamic_pointer_cast<Query>( fqry ), BooleanClause::SHOULD );

            FuzzyQueryPtr fqry2 = newLucene<FuzzyQuery>( newLucene<Term>( L"artist", q.toStdWString() ) );
            qry->add( boost::dynamic_pointer_cast<Query>( fqry2 ), BooleanClause::SHOULD );

            FuzzyQueryPtr fqry3 = newLucene<FuzzyQuery>( newLucene<Term>( L"fulltext", q.toStdWString() ) );
            qry->add( boost::dynamic_pointer_cast<Query>( fqry3 ), BooleanClause::SHOULD );
        }
        else
        {
            const QString track = Tomahawk::DatabaseImpl::sortname( query->queryTrack()->track() );
            const QString artist = Tomahawk::DatabaseImpl::sortname( query->queryTrack()->artist() );
            //QString album = Tomahawk::DatabaseImpl::sortname( query->queryTrack()->album() );

            FuzzyQueryPtr fqry = newLucene<FuzzyQuery>( newLucene<Term>( L"track", track.toStdWString() ), 0.5, 3 );
            qry->add( boost::dynamic_pointer_cast<Query>( fqry ), BooleanClause::MUST );

            FuzzyQueryPtr fqry2 = newLucene<FuzzyQuery>( newLucene<Term>( L"artist", artist.toStdWString() ), 0.5, 3 );
            qry->add( boost::dynamic_pointer_cast<Query>( fqry2 ), BooleanClause::MUST );
        }

        TopScoreDocCollectorPtr collector = TopScoreDocCollector::create( 20, true );
        m_luceneSearcher->search( qry, collector );
        Collection<ScoreDocPtr> hits = collector->topDocs()->scoreDocs;

        for ( int i = 0; i < collector->getTotalHits() && i < 20; i++ )
        {
            DocumentPtr d = m_luceneSearcher->doc( hits[i]->doc );
            const float score = hits[i]->score;
            const int id = QString::fromStdWString( d->get( L"trackid" ) ).toInt();

//            if ( score > minScore )
            {
                resultsmap.insert( id, score );
//                tDebug() << "Index hit:" << id << score << QString::fromWCharArray( ((Query*)qry)->toString() );
            }
        }
    }
    catch( LuceneException& error )
    {
        tDebug() << "Caught Lucene error:" << QString::fromWCharArray( error.getError().c_str() ) << query->toString();
    }

    return resultsmap;
}