Hey Sebastian The reviewboard has gone insane and it refuses to let me upload my patch - "The file 'nepomuk/kioslaves/search/kio_nepomuksearch.cpp' (r2311b7a) could not be found in the repository".
The auto updates donot seem to work any more, so that really needs to be fixed or thrown away. I would prefer throwing it away, but it does have a valid use-case, though the implementation is horrible. commit 1fba20495fddfc596591f6ea8535d5fc6427c62b Author: Vishesh Handa <[email protected]> Date: Sat Jun 16 02:57:57 2012 +0530 Avoid using the query service to run queries in the kioslave Avoid creating a new thread in the query service, and parsing the results over dbus. Instead just run the query manually in the kioslave. We can do this cause kioslaves run in a separate process and are allowed to be blocking. diff --git a/nepomuk/kioslaves/common/resourcestat.cpp b/nepomuk/kioslaves/common/resourcestat.cpp index a259ba5..8f3088e 100644 --- a/nepomuk/kioslaves/common/resourcestat.cpp +++ b/nepomuk/kioslaves/common/resourcestat.cpp @@ -349,6 +349,7 @@ KUrl Nepomuk2::redirectionUrl( const Nepomuk2::Resource& res ) namespace { + /** * Check if the resource represents a local file with an existing nie:url property. */ diff --git a/nepomuk/kioslaves/search/kio_nepomuksearch.cpp b/nepomuk/kioslaves/search/kio_nepomuksearch.cpp index 2311b7a..3c82796 100644 --- a/nepomuk/kioslaves/search/kio_nepomuksearch.cpp +++ b/nepomuk/kioslaves/search/kio_nepomuksearch.cpp @@ -182,7 +182,7 @@ void Nepomuk2::SearchProtocol::listDir( const KUrl& url ) else { SearchFolder folder( url, this ); updateQueryUrlHistory( url ); - folder.waitForListing(); + folder.list(); listEntry( KIO::UDSEntry(), true ); finished(); } @@ -315,7 +315,7 @@ void Nepomuk2::SearchProtocol::listRoot() if ( query.isValid() ) { // FIXME: Avoid this useless conversion to searchUrl and back SearchFolder folder( query.toSearchUrl(), this ); - folder.waitForListing(); + folder.list(); } listEntry( KIO::UDSEntry(), true ); diff --git a/nepomuk/kioslaves/search/searchfolder.cpp b/nepomuk/kioslaves/search/searchfolder.cpp index 3cd098a..38e4b1d 100644 --- a/nepomuk/kioslaves/search/searchfolder.cpp +++ b/nepomuk/kioslaves/search/searchfolder.cpp @@ -32,15 +32,19 @@ #include <Nepomuk2/Thing> #include <Nepomuk2/Types/Class> #include <Nepomuk2/Query/Query> -#include <Nepomuk2/Query/QueryParser> +#include <Nepomuk2/Query/Result> #include <Nepomuk2/Query/ResourceTypeTerm> -#include <Nepomuk2/Query/QueryServiceClient> #include <Nepomuk2/Vocabulary/NFO> #include <Nepomuk2/Vocabulary/NIE> #include <Nepomuk2/Vocabulary/PIMO> +#include <Nepomuk2/ResourceManager> +#include <Nepomuk2/Resource> + #include <QtCore/QMutexLocker> #include <QTextDocument> +#include <Soprano/QueryResultIterator> +#include <Soprano/Model> #include <KUrl> #include <KDebug> @@ -51,6 +55,8 @@ #include <KConfig> #include <KConfigGroup> +using namespace Nepomuk2::Vocabulary; +using namespace Soprano::Vocabulary; Nepomuk2::SearchFolder::SearchFolder( const KUrl& url, KIO::SlaveBase* slave ) : QObject( 0 ), @@ -60,23 +66,9 @@ Nepomuk2::SearchFolder::SearchFolder( const KUrl& url, KIO::SlaveBase* slave ) // parse URL (this may fail in which case we fall back to pure SPARQL below) Query::parseQueryUrl( url, m_query, m_sparqlQuery ); - m_client = new Nepomuk2::Query::QueryServiceClient(); - - connect( m_client, SIGNAL( newEntries( const QList<Nepomuk2::Query::Result>& ) ), - this, SLOT( slotNewEntries( const QList<Nepomuk2::Query::Result>& ) ) ); - connect( m_client, SIGNAL( resultCount(int) ), - this, SLOT( slotResultCount(int) ) ); - connect( m_client, SIGNAL( finishedListing() ), - this, SLOT( slotFinishedListing() ) ); - connect( m_client, SIGNAL( error(QString) ), - this, SLOT( slotFinishedListing() ) ); - connect( m_client, SIGNAL( finishedListing() ), - m_client, SLOT( deleteLater() ) ); - - if ( m_query.isValid() ) - m_client->query( m_query ); - else - m_client->sparqlQuery( m_sparqlQuery ); + if ( m_query.isValid() ) { + m_sparqlQuery = m_query.toSparqlQuery(); + } } @@ -84,36 +76,20 @@ Nepomuk2::SearchFolder::~SearchFolder() { } -void Nepomuk2::SearchFolder::waitForListing() -{ - m_eventLoop.exec(); -} - -void Nepomuk2::SearchFolder::slotNewEntries( const QList<Nepomuk2::Query::Result>& results ) +void Nepomuk2::SearchFolder::list() { - KIO::UDSEntryList entryList; - foreach(const Query::Result& result, results ) { + //FIXME: Do the result count as well? + Soprano::Model* model = ResourceManager::instance()->mainModel(); + Soprano::QueryResultIterator it = model->executeQuery( m_sparqlQuery, Soprano::Query::QueryLanguageSparql ); + while( it.next() ) { + Query::Result result = extractResult( it ); KIO::UDSEntry uds = statResult( result ); if ( uds.count() ) { - //kDebug() << "listing" << result.resource().resourceUri(); m_slave->listEntry(uds, false); } } } - -void Nepomuk2::SearchFolder::slotResultCount( int count ) -{ - m_slave->totalSize( count ); -} - - -void Nepomuk2::SearchFolder::slotFinishedListing() -{ - m_eventLoop.exit(); -} - - namespace { bool statFile( const KUrl& url, const KUrl& fileUrl, KIO::UDSEntry& uds ) { @@ -146,7 +122,7 @@ KIO::UDSEntry Nepomuk2::SearchFolder::statResult( const Query::Result& result ) { Resource res( result.resource() ); const KUrl uri( res.resourceUri() ); - KUrl nieUrl( result[Nepomuk2::Vocabulary::NIE::url()].uri() ); + KUrl nieUrl( result[NIE::url()].uri() ); // the additional bindings that we only have on unix systems // Either all are bound or none of them. @@ -263,3 +239,36 @@ KIO::UDSEntry Nepomuk2::SearchFolder::statResult( const Query::Result& result ) return uds; } + +// copied from the QueryService +Nepomuk2::Query::Result Nepomuk2::SearchFolder::extractResult(const Soprano::QueryResultIterator& it) const +{ + Query::Result result( Resource::fromResourceUri( it[0].uri() ) ); + const Query::RequestPropertyMap map = m_query.requestPropertyMap(); + for( Query::RequestPropertyMap::const_iterator rit = map.begin(); rit != map.constEnd(); rit++ ) { + result.addRequestProperty( rit.value(), it.binding( rit.key() ) ); + } + + // make sure we do not store values twice + QStringList names = it.bindingNames(); + names.removeAll( QLatin1String( "r" ) ); + + static const char* s_scoreVarName = "_n_f_t_m_s_"; + static const char* s_excerptVarName = "_n_f_t_m_ex_"; + + Soprano::BindingSet set; + int score = 0; + Q_FOREACH( const QString& var, names ) { + if ( var == QLatin1String( s_scoreVarName ) ) + score = it[var].literal().toInt(); + else if ( var == QLatin1String( s_excerptVarName ) ) + result.setExcerpt( it[var].toString() ); + else + set.insert( var, it[var] ); + } + + result.setAdditionalBindings( set ); + result.setScore( ( double )score ); + + return result; +} \ No newline at end of file diff --git a/nepomuk/kioslaves/search/searchfolder.h b/nepomuk/kioslaves/search/searchfolder.h index 794baaa..b475402 100644 --- a/nepomuk/kioslaves/search/searchfolder.h +++ b/nepomuk/kioslaves/search/searchfolder.h @@ -36,6 +36,9 @@ #include <Nepomuk2/Resource> #include <KUrl> +namespace Soprano { + class QueryResultIterator; +} namespace Nepomuk2 { namespace Query { @@ -76,17 +79,7 @@ namespace Nepomuk2 { /** * List the results directly on the parent slave. */ - void waitForListing(); - - private Q_SLOTS: - /// connected to the QueryServiceClient in the search thread - void slotNewEntries( const QList<Nepomuk2::Query::Result>& ); - - /// connected to the QueryServiceClient in the search thread - void slotResultCount( int ); - - /// connected to the QueryServiceClient in the search thread - void slotFinishedListing(); + void list(); private: /** @@ -94,6 +87,8 @@ namespace Nepomuk2 { */ KIO::UDSEntry statResult( const Query::Result& result ); + Query::Result extractResult( const Soprano::QueryResultIterator& it ) const; + // folder properties KUrl m_url; -- Vishesh Handa
_______________________________________________ Nepomuk mailing list [email protected] https://mail.kde.org/mailman/listinfo/nepomuk
