<br><br><div class="gmail_quote">On Tue, Jun 26, 2012 at 1:17 PM, Sebastian Trüg <span dir="ltr"><<a href="mailto:trueg@kde.org" target="_blank">trueg@kde.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 06/25/2012 10:50 AM, Vishesh Handa wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hey Sebastian<br>
<br>
The reviewboard has gone insane and it refuses to let me upload my patch<br>
- "The file 'nepomuk/kioslaves/search/kio_<u></u>nepomuksearch.cpp' (r2311b7a)<br>
could not be found in the repository".<br>
<br>
The auto updates donot seem to work any more, so that really needs to be<br>
</blockquote>
><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
fixed or thrown away. I would prefer throwing it away, but it does have<br>
a valid use-case, though the implementation is horrible.<br>
</blockquote>
<br></div>
Why is the implementation horrible? I always thought it to be very clean. The concept is simple: the kio slave lists a folder which results in a KDirNotify signal which is used by the kded module to list the query in the query service. Since before that would </blockquote>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> have reused the same query folder there would have been no re-querying. The kded would simply subscribe to updates from the query service.<br>
</blockquote><div><br>I was referring to how the query service does the updates - It runs the queries every time any data has changed. The current implementation makes Nepomuk completely unusable. Mainly cause I have the telepathy-nepomuk-service running which updates the nepomuk repo any time the status of any of my contacts changes.<br>
<br>Right now, the query will be run both in the kio-slave, and in the queryservice. Maybe we could abstract away the queryservice code, and make it run in the kioslave itself. That way the kded will listen to the kioslave for updates, and the queries will not have to be run twice.<br>
 <br> <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
commit 1fba20495fddfc596591f6ea8535d5<u></u>fc6427c62b<br>
Author: Vishesh Handa<<a href="mailto:me@vhanda.in" target="_blank">me@vhanda.in</a>  <mailto:<a href="mailto:me@vhanda.in" target="_blank">me@vhanda.in</a>>><div><div class="h5"><br>
Date:   Sat Jun 16 02:57:57 2012 +0530<br>
<br>
     Avoid using the query service to run queries in the kioslave<br>
<br>
     Avoid creating a new thread in the query service, and parsing the<br>
     results over dbus. Instead just run the query manually in the kioslave.<br>
<br>
     We can do this cause kioslaves run in a separate process and are allowed<br>
     to be blocking.<br>
<br>
diff --git a/nepomuk/kioslaves/common/<u></u>resourcestat.cpp b/nepomuk/kioslaves/common/<u></u>resourcestat.cpp<br>
index a259ba5..8f3088e 100644<br>
--- a/nepomuk/kioslaves/common/<u></u>resourcestat.cpp<br>
+++ b/nepomuk/kioslaves/common/<u></u>resourcestat.cpp<br>
@@ -349,6 +349,7 @@ KUrl Nepomuk2::redirectionUrl( const Nepomuk2::Resource&  res )<br>
<br>
<br>
  namespace {<br>
+<br>
      /**<br>
       * Check if the resource represents a local file with an existing nie:url property.<br>
       */<br>
diff --git a/nepomuk/kioslaves/search/<u></u>kio_nepomuksearch.cpp b/nepomuk/kioslaves/search/<u></u>kio_nepomuksearch.cpp<br>
index 2311b7a..3c82796 100644<br>
--- a/nepomuk/kioslaves/search/<u></u>kio_nepomuksearch.cpp<br>
+++ b/nepomuk/kioslaves/search/<u></u>kio_nepomuksearch.cpp<br>
@@ -182,7 +182,7 @@ void Nepomuk2::SearchProtocol::<u></u>listDir( const KUrl&  url )<br>
          else {<br>
              SearchFolder folder( url, this );<br>
              updateQueryUrlHistory( url );<br>
-            folder.waitForListing();<br>
+            folder.list();<br>
              listEntry( KIO::UDSEntry(), true );<br>
              finished();<br>
          }<br>
@@ -315,7 +315,7 @@ void Nepomuk2::SearchProtocol::<u></u>listRoot()<br>
      if ( query.isValid() ) {<br>
          // FIXME: Avoid this useless conversion to searchUrl and back<br>
          SearchFolder folder( query.toSearchUrl(), this );<br>
-        folder.waitForListing();<br>
+        folder.list();<br>
      }<br>
<br>
      listEntry( KIO::UDSEntry(), true );<br>
diff --git a/nepomuk/kioslaves/search/<u></u>searchfolder.cpp b/nepomuk/kioslaves/search/<u></u>searchfolder.cpp<br>
index 3cd098a..38e4b1d 100644<br>
--- a/nepomuk/kioslaves/search/<u></u>searchfolder.cpp<br>
+++ b/nepomuk/kioslaves/search/<u></u>searchfolder.cpp<br>
@@ -32,15 +32,19 @@<br>
  #include<Nepomuk2/Thing><br>
  #include<Nepomuk2/Types/Class><br>
  #include<Nepomuk2/Query/Query><br>
-#include<Nepomuk2/Query/<u></u>QueryParser><br>
+#include<Nepomuk2/Query/<u></u>Result><br>
  #include<Nepomuk2/Query/<u></u>ResourceTypeTerm><br>
-#include<Nepomuk2/Query/<u></u>QueryServiceClient><br>
  #include<Nepomuk2/Vocabulary/<u></u>NFO><br>
  #include<Nepomuk2/Vocabulary/<u></u>NIE><br>
  #include<Nepomuk2/Vocabulary/<u></u>PIMO><br>
<br>
+#include<Nepomuk2/<u></u>ResourceManager><br>
+#include<Nepomuk2/Resource><br>
+<br>
  #include<QtCore/QMutexLocker><br>
  #include<QTextDocument><br>
+#include<Soprano/<u></u>QueryResultIterator><br>
+#include<Soprano/Model><br>
<br>
  #include<KUrl><br>
  #include<KDebug><br>
@@ -51,6 +55,8 @@<br>
  #include<KConfig><br>
  #include<KConfigGroup><br>
<br>
+using namespace Nepomuk2::Vocabulary;<br>
+using namespace Soprano::Vocabulary;<br>
<br>
  Nepomuk2::SearchFolder::<u></u>SearchFolder( const KUrl&  url, KIO::SlaveBase* slave )<br>
      : QObject( 0 ),<br>
@@ -60,23 +66,9 @@ Nepomuk2::SearchFolder::<u></u>SearchFolder( const KUrl&  url, KIO::SlaveBase* slave )<br>
      // parse URL (this may fail in which case we fall back to pure SPARQL below)<br>
      Query::parseQueryUrl( url, m_query, m_sparqlQuery );<br>
<br>
-    m_client = new Nepomuk2::Query::<u></u>QueryServiceClient();<br>
-<br>
-    connect( m_client, SIGNAL( newEntries( const QList<Nepomuk2::Query::Result><u></u>&  ) ),<br>
-             this, SLOT( slotNewEntries( const QList<Nepomuk2::Query::Result><u></u>&  ) ) );<br>
-    connect( m_client, SIGNAL( resultCount(int) ),<br>
-             this, SLOT( slotResultCount(int) ) );<br>
-    connect( m_client, SIGNAL( finishedListing() ),<br>
-             this, SLOT( slotFinishedListing() ) );<br>
-    connect( m_client, SIGNAL( error(QString) ),<br>
-             this, SLOT( slotFinishedListing() ) );<br>
-    connect( m_client, SIGNAL( finishedListing() ),<br>
-             m_client, SLOT( deleteLater() ) );<br>
-<br>
-    if ( m_query.isValid() )<br>
-        m_client->query( m_query );<br>
-    else<br>
-        m_client->sparqlQuery( m_sparqlQuery );<br>
+    if ( m_query.isValid() ) {<br>
+        m_sparqlQuery = m_query.toSparqlQuery();<br>
+    }<br>
  }<br>
<br>
<br>
@@ -84,36 +76,20 @@ Nepomuk2::SearchFolder::~<u></u>SearchFolder()<br>
  {<br>
  }<br>
<br>
-void Nepomuk2::SearchFolder::<u></u>waitForListing()<br>
-{<br>
-    m_eventLoop.exec();<br>
-}<br>
-<br>
-void Nepomuk2::SearchFolder::<u></u>slotNewEntries( const QList<Nepomuk2::Query::Result><u></u>&  results )<br>
+void Nepomuk2::SearchFolder::list()<br>
  {<br>
-    KIO::UDSEntryList entryList;<br>
-    foreach(const Query::Result&  result, results ) {<br>
+    //FIXME: Do the result count as well?<br>
+    Soprano::Model* model = ResourceManager::instance()-><u></u>mainModel();<br>
+    Soprano::QueryResultIterator it = model->executeQuery( m_sparqlQuery, Soprano::Query::<u></u>QueryLanguageSparql );<br>
+    while( it.next() ) {<br>
+        Query::Result result = extractResult( it );<br>
          KIO::UDSEntry uds = statResult( result );<br>
          if ( uds.count() ) {<br>
-            //kDebug()<<  "listing"  <<  result.resource().resourceUri(<u></u>);<br>
              m_slave->listEntry(uds, false);<br>
          }<br>
      }<br>
  }<br>
<br>
-<br>
-void Nepomuk2::SearchFolder::<u></u>slotResultCount( int count )<br>
-{<br>
-    m_slave->totalSize( count );<br>
-}<br>
-<br>
-<br>
-void Nepomuk2::SearchFolder::<u></u>slotFinishedListing()<br>
-{<br>
-    m_eventLoop.exit();<br>
-}<br>
-<br>
-<br>
  namespace {<br>
      bool statFile( const KUrl&  url, const KUrl&  fileUrl, KIO::UDSEntry&  uds )<br>
      {<br>
@@ -146,7 +122,7 @@ KIO::UDSEntry Nepomuk2::SearchFolder::<u></u>statResult( const Query::Result&  result )<br>
  {<br>
      Resource res( result.resource() );<br>
      const KUrl uri( res.resourceUri() );<br>
-    KUrl nieUrl( result[Nepomuk2::Vocabulary::<u></u>NIE::url()].uri() );<br>
+    KUrl nieUrl( result[NIE::url()].uri() );<br>
<br>
      // the additional bindings that we only have on unix systems<br>
      // Either all are bound or none of them.<br>
@@ -263,3 +239,36 @@ KIO::UDSEntry Nepomuk2::SearchFolder::<u></u>statResult( const Query::Result&  result )<br>
<br>
      return uds;<br>
  }<br>
+<br>
+// copied from the QueryService<br>
+Nepomuk2::Query::Result Nepomuk2::SearchFolder::<u></u>extractResult(const Soprano::QueryResultIterator&  it) const<br>
+{<br>
+    Query::Result result( Resource::fromResourceUri( it[0].uri() ) );<br>
+    const Query::RequestPropertyMap map = m_query.requestPropertyMap();<br>
+    for( Query::RequestPropertyMap::<u></u>const_iterator rit = map.begin(); rit != map.constEnd(); rit++ ) {<br>
+        result.addRequestProperty( rit.value(), it.binding( rit.key() ) );<br>
+    }<br>
+<br>
+    // make sure we do not store values twice<br>
+    QStringList names = it.bindingNames();<br>
+    names.removeAll( QLatin1String("r"  ) );<br>
+<br>
+    static const char* s_scoreVarName ="_n_f_t_m_s_";<br>
+    static const char* s_excerptVarName ="_n_f_t_m_ex_";<br>
+<br>
+    Soprano::BindingSet set;<br>
+    int score = 0;<br>
+    Q_FOREACH( const QString&  var, names ) {<br>
+        if ( var == QLatin1String( s_scoreVarName ) )<br>
+            score = it[var].literal().toInt();<br>
+        else if ( var == QLatin1String( s_excerptVarName ) )<br>
+            result.setExcerpt( it[var].toString() );<br>
+        else<br>
+            set.insert( var, it[var] );<br>
+    }<br>
+<br>
+    result.setAdditionalBindings( set );<br>
+    result.setScore( ( double )score );<br>
+<br>
+    return result;<br>
+}<br>
\ No newline at end of file<br>
diff --git a/nepomuk/kioslaves/search/<u></u>searchfolder.h b/nepomuk/kioslaves/search/<u></u>searchfolder.h<br>
index 794baaa..b475402 100644<br>
--- a/nepomuk/kioslaves/search/<u></u>searchfolder.h<br>
+++ b/nepomuk/kioslaves/search/<u></u>searchfolder.h<br>
@@ -36,6 +36,9 @@<br>
  #include<Nepomuk2/Resource><br>
  #include<KUrl><br>
<br>
+namespace Soprano {<br>
+    class QueryResultIterator;<br>
+}<br>
<br>
  namespace Nepomuk2 {<br>
      namespace Query {<br>
@@ -76,17 +79,7 @@ namespace Nepomuk2 {<br>
          /**<br>
           * List the results directly on the parent slave.<br>
           */<br>
-        void waitForListing();<br>
-<br>
-    private Q_SLOTS:<br>
-        /// connected to the QueryServiceClient in the search thread<br>
-        void slotNewEntries( const QList<Nepomuk2::Query::Result><u></u>&  );<br>
-<br>
-        /// connected to the QueryServiceClient in the search thread<br>
-        void slotResultCount( int );<br>
-<br>
-        /// connected to the QueryServiceClient in the search thread<br>
-        void slotFinishedListing();<br>
+        void list();<br>
<br>
      private:<br>
          /**<br>
@@ -94,6 +87,8 @@ namespace Nepomuk2 {<br>
           */<br>
          KIO::UDSEntry statResult( const Query::Result&  result );<br>
<br>
+        Query::Result extractResult( const Soprano::QueryResultIterator&  it ) const;<br>
+<br>
          // folder properties<br>
          KUrl m_url;<br>
<br>
<br>
<br>
<br>
--<br>
Vishesh Handa<br>
<br>
</div></div></blockquote>
</blockquote></div><br><br clear="all"><br>-- <br><span style="color:rgb(192,192,192)">Vishesh Handa</span><br><br>