[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/KDE/4.4/kdebase/runtime/nepomuk/services/queryservice
From:       Sebastian Trueg <sebastian () trueg ! de>
Date:       2010-03-24 18:39:35
Message-ID: 20100324183938.89505AC86A () svn ! kde ! org
[Download RAW message or body]

SVN commit 1107069 by trueg:

Backport: cleanup unused code and do not cache all results twice.


 M  +0 -1      CMakeLists.txt  
 M  +11 -23    folder.cpp  
 M  +3 -4      folder.h  
 M  +0 -2      queryservice.cpp  
 D             searchcore.cpp  
 D             searchcore.h  
 M  +19 -14    searchthread.cpp  
 M  +3 -3      searchthread.h  


--- branches/KDE/4.4/kdebase/runtime/nepomuk/services/queryservice/CMakeLists.txt \
#1107068:1107069 @@ -13,7 +13,6 @@
 
 set(queryservice_SRCS
   queryservice.cpp
-  searchcore.cpp
   searchthread.cpp
   folder.cpp
   folderconnection.cpp
--- branches/KDE/4.4/kdebase/runtime/nepomuk/services/queryservice/folder.cpp \
#1107068:1107069 @@ -1,5 +1,5 @@
 /*
-   Copyright (c) 2008-2009 Sebastian Trueg <trueg@kde.org>
+   Copyright (c) 2008-2010 Sebastian Trueg <trueg@kde.org>
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -39,13 +39,12 @@
     m_updateTimer.setSingleShot( true );
     m_updateTimer.setInterval( 2000 );
 
-    m_searchCore = new SearchCore( this );
+    m_searchThread = new SearchThread( this );
 
-    connect( m_searchCore, SIGNAL( newResult( const Nepomuk::Query::Result& ) ),
-             this, SLOT( slotSearchNewResult( const Nepomuk::Query::Result& ) ) );
-    connect( m_searchCore, SIGNAL( scoreChanged( const Nepomuk::Query::Result& ) ),
-             this, SLOT( slotSearchScoreChanged( const Nepomuk::Query::Result& ) ) \
                );
-    connect( m_searchCore, SIGNAL( finished() ),
+    connect( m_searchThread, SIGNAL( newResult( const Nepomuk::Query::Result& ) ),
+             this, SLOT( slotSearchNewResult( const Nepomuk::Query::Result& ) ),
+             Qt::QueuedConnection );
+    connect( m_searchThread, SIGNAL( finished() ),
              this, SLOT( slotSearchFinished() ) );
     connect( ResourceManager::instance()->mainModel(), SIGNAL( statementsAdded() ),
              this, SLOT( slotStorageChanged() ) );
@@ -58,14 +57,15 @@
 
 Nepomuk::Query::Folder::~Folder()
 {
+    m_searchThread->cancel();
 }
 
 
 void Nepomuk::Query::Folder::update()
 {
-    if ( !m_searchCore->isActive() ) {
+    if ( !m_searchThread->isRunning() ) {
         // run the search and forward signals to all connections that requested it
-        m_searchCore->query( m_query, m_requestProperties );
+        m_searchThread->query( m_query, m_requestProperties );
     }
 }
 
@@ -97,18 +97,6 @@
 }
 
 
-void Nepomuk::Query::Folder::slotSearchScoreChanged( const Nepomuk::Query::Result& )
-{
-    // TODO: implement this
-    if ( m_initialListingDone ) {
-
-    }
-    else {
-
-    }
-}
-
-
 void Nepomuk::Query::Folder::slotSearchFinished()
 {
     if ( m_initialListingDone ) {
@@ -135,7 +123,7 @@
 
 void Nepomuk::Query::Folder::slotStorageChanged()
 {
-    if ( !m_updateTimer.isActive() && !m_searchCore->isActive() ) {
+    if ( !m_updateTimer.isActive() && !m_searchThread->isRunning() ) {
         update();
     }
     else {
@@ -147,7 +135,7 @@
 // if there was a change in the nepomuk store we update
 void Nepomuk::Query::Folder::slotUpdateTimeout()
 {
-    if ( m_storageChanged && !m_searchCore->isActive() ) {
+    if ( m_storageChanged && !m_searchThread->isRunning() ) {
         m_storageChanged = false;
         update();
     }
--- branches/KDE/4.4/kdebase/runtime/nepomuk/services/queryservice/folder.h \
#1107068:1107069 @@ -1,5 +1,5 @@
 /*
-   Copyright (c) 2008-2009 Sebastian Trueg <trueg@kde.org>
+   Copyright (c) 2008-2010 Sebastian Trueg <trueg@kde.org>
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -28,7 +28,7 @@
 
 #include <KUrl>
 
-#include "searchcore.h"
+#include "searchthread.h"
 
 namespace Nepomuk {
     namespace Query {
@@ -73,7 +73,6 @@
 
         private Q_SLOTS:
             void slotSearchNewResult( const Nepomuk::Query::Result& );
-            void slotSearchScoreChanged( const Nepomuk::Query::Result& );
             void slotSearchFinished();
             void slotStorageChanged();
             void slotUpdateTimeout();
@@ -97,7 +96,7 @@
             QHash<QUrl, Result> m_results;    // the actual current results
             QHash<QUrl, Result> m_newResults; // the results gathered during an \
update, needed to find removed items  
-            SearchCore* m_searchCore;
+            SearchThread* m_searchThread;
 
             bool m_storageChanged;            // did the nepomuk store change after \
                the last update
             QTimer m_updateTimer;             // used to ensure that we do not \
                update all the time if the storage changes a lot
--- branches/KDE/4.4/kdebase/runtime/nepomuk/services/queryservice/queryservice.cpp \
#1107068:1107069 @@ -46,8 +46,6 @@
     : Service( parent ),
       m_folderConnectionCnt( 0 )
 {
-    ResourceManager::instance()->setOverrideMainModel( Service::mainModel() );
-
     Nepomuk::Query::registerDBusTypes();
 
     s_instance = this;
--- branches/KDE/4.4/kdebase/runtime/nepomuk/services/queryservice/searchthread.cpp \
#1107068:1107069 @@ -1,6 +1,6 @@
 /*
   This file is part of the Nepomuk KDE project.
-  Copyright (C) 2007-2009 Sebastian Trueg <trueg@kde.org>
+  Copyright (C) 2007-2010 Sebastian Trueg <trueg@kde.org>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
@@ -75,7 +75,7 @@
     m_canceled = false;
     m_sparqlQuery = query;
     m_requestProperties = requestProps;
-    m_cutOffScore = cutOffScore;
+    m_cutOffScore = qMin( 1.0, qMax( cutOffScore, 0.0 ) );
 
     start();
 }
@@ -93,18 +93,30 @@
     QTime time;
     time.start();
 
-    sparqlQuery( m_sparqlQuery, 1.0, true );
+    //
+    // To speed up the user experience and since in most cases users would only
+    // look at the first few results anyway, we run the query twice: once with a
+    // limit of 10 and once without a limit. To check if the query already has a
+    // limit or an offset we do not do any fancy things. We simply check if the
+    // query ends with a closing bracket which always suceeds for queries
+    // created via the Nepomuk query API.
+    //
+    if ( m_sparqlQuery.endsWith( QLatin1String( "}" ) ) ) {
+        sparqlQuery( m_sparqlQuery + QLatin1String( " LIMIT 10" ), 1.0 );
+        sparqlQuery( m_sparqlQuery + QLatin1String( " OFFSET 10" ), 1.0 );
+    }
+    else {
+        sparqlQuery( m_sparqlQuery, 1.0 );
+    }
 
     kDebug() << time.elapsed();
 }
 
 
-QHash<QUrl, Nepomuk::Query::Result> Nepomuk::Query::SearchThread::sparqlQuery( const \
QString& query, double baseScore, bool reportResults ) +void \
Nepomuk::Query::SearchThread::sparqlQuery( const QString& query, double baseScore )  \
{  kDebug() << query;
 
-    QHash<QUrl, Result> results;
-
     Soprano::QueryResultIterator hits = \
ResourceManager::instance()->mainModel()->executeQuery( query, \
Soprano::Query::QueryLanguageSparql );  while ( hits.next() ) {
         if ( m_canceled ) break;
@@ -114,15 +126,8 @@
 
         kDebug() << "Found result:" << result.resource().resourceUri();
 
-        // these are actual direct hits and we can report them right away
-        if ( reportResults ) {
-            emit newResult( result );
-        }
-
-        results.insert( result.resource().resourceUri(), result );
+        emit newResult( result );
     }
-
-    return results;
 }
 
 
--- branches/KDE/4.4/kdebase/runtime/nepomuk/services/queryservice/searchthread.h \
#1107068:1107069 @@ -1,6 +1,6 @@
 /*
    This file is part of the Nepomuk KDE project.
-   Copyright (C) 2007-2009 Sebastian Trueg <trueg@kde.org>
+   Copyright (C) 2007-2010 Sebastian Trueg <trueg@kde.org>
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -47,7 +47,7 @@
             /**
              * Use instead of QThread::start()
              */
-            void query( const QString& query, const RequestPropertyMap& \
requestProps, double cutOffScore ); +            void query( const QString& query, \
const RequestPropertyMap& requestProps, double cutOffScore = 0.0 );  void cancel();
 
             double cutOffScore() const { return m_cutOffScore; }
@@ -59,7 +59,7 @@
             void run();
 
         private:
-            QHash<QUrl, Nepomuk::Query::Result> sparqlQuery( const QString& query, \
double baseScore, bool reportResults ); +            void sparqlQuery( const QString& \
                query, double baseScore );
             Nepomuk::Query::Result extractResult( const \
Soprano::QueryResultIterator& it ) const;  
             QString m_sparqlQuery;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic