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

List:       kde-commits
Subject:    branches/KDE/4.4/kdebase/runtime/nepomuk/services/strigi
From:       Sebastian Trueg <sebastian () trueg ! de>
Date:       2010-03-10 14:55:23
Message-ID: 1268232923.237577.1597.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1101677 by trueg:

Backport: Fixed filter creation for removing unwanted entries. This fixes the bug of \
files being re-indexed all the time in case one has configured more than one \
top-level index folder.

CCMAIL: nlecureuil@mandriva.com


 M  +54 -9     indexscheduler.cpp  


--- branches/KDE/4.4/kdebase/runtime/nepomuk/services/strigi/indexscheduler.cpp \
#1101676:1101677 @@ -533,10 +533,27 @@
 
 
 namespace {
+    /**
+     * Returns true if the specified folder f would already be included or excluded \
using the list +     * folders
+     */
+    bool alreadyInList( const QList<QPair<QString, bool> >& folders, const QString& \
f, bool include ) +    {
+        bool included = false;
+        for ( int i = 0; i < folders.count(); ++i ) {
+            if ( f != folders[i].first &&
+                 f.startsWith( folders[i].first ) )
+                included = folders[i].second;
+        }
+        return included == include;
+    }
+
+    /**
+     * Simple insertion sort
+     */
     void insertSortFolders( const QStringList& folders, bool include, \
QList<QPair<QString, bool> >& result )  {
         foreach( const QString& f, folders ) {
-            // insertion sort
             int pos = 0;
             while ( result.count() > pos &&
                     result[pos].first < f )
@@ -545,9 +562,27 @@
         }
     }
 
-    QString constructFolderFilter( const QList<QPair<QString, bool> > folders, int& \
index ) +    /**
+     * Remove useless entries which would confuse the algo below.
+     * This makes sure all top-level items are include folders.
+     * This runs in O(n^2) and could be optimized but what for.
+     */
+    void cleanupList( QList<QPair<QString, bool> >& result )
     {
-        const QString path = folders[index].first;
+        int i = 0;
+        while ( i < result.count() ) {
+            if ( alreadyInList( result, result[i].first, result[i].second ) )
+                result.removeAt( i );
+            else
+                ++i;
+        }
+    }
+
+    QString constructFolderSubFilter( const QList<QPair<QString, bool> > folders, \
int& index ) +    {
+        QString path = folders[index].first;
+        if ( !path.endsWith( '/' ) )
+            path += '/';
         const bool include = folders[index].second;
 
         ++index;
@@ -555,7 +590,7 @@
         QStringList subFilters;
         while ( index < folders.count() &&
                 folders[index].first.startsWith( path ) ) {
-            subFilters << constructFolderFilter( folders, index );
+            subFilters << constructFolderSubFilter( folders, index );
         }
 
         QString thisFilter = QString::fromLatin1( "REGEX(STR(?url),'^file://%1')" \
).arg( path ); @@ -573,6 +608,20 @@
             return subFilters.first();
         }
     }
+
+    QString constructFolderFilter()
+    {
+        QList<QPair<QString, bool> > folders;
+        insertSortFolders( Nepomuk::StrigiServiceConfig::self()->folders(), true, \
folders ); +        insertSortFolders( \
Nepomuk::StrigiServiceConfig::self()->excludeFolders(), false, folders ); +        \
cleanupList( folders ); +        int index = 0;
+        QStringList subFilters;
+        while ( index < folders.count() ) {
+            subFilters << constructFolderSubFilter( folders, index );
+        }
+        return subFilters.join(" && ");
+    }
 }
 
 void Nepomuk::IndexScheduler::removeOldAndUnwantedEntries()
@@ -581,11 +630,7 @@
     // We now query all indexed files that are in folders that should not
     // be indexed at once.
     //
-    QList<QPair<QString, bool> > folders;
-    insertSortFolders( StrigiServiceConfig::self()->folders(), true, folders );
-    insertSortFolders( StrigiServiceConfig::self()->excludeFolders(), false, folders \
                );
-    int i = 0;
-    QString folderFilter = constructFolderFilter( folders, i );
+    QString folderFilter = constructFolderFilter();
 
     //
     // We query all files that should not be in the store


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

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