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

List:       kde-commits
Subject:    [kdevplatform] /: Quick open filtering: do path fuzzy matching only on file name
From:       Sven Brauch <svenbrauch () googlemail ! com>
Date:       2014-01-31 23:22:43
Message-ID: E1W9NQ3-00041H-6T () scm ! kde ! org
[Download RAW message or body]

Git commit 245743bb877e3ed5cfd9c94a313393bacd96e1e4 by Sven Brauch.
Committed on 31/01/2014 at 23:17.
Pushed by brauch into branch 'master'.

Quick open filtering: do path fuzzy matching only on file name

Matching the whole path generated lots and lots of unrelated results,
especially for shorter queries. And because it is inherently hard to sort
that kind of fuzzy matches, they couldn't even be sorted by match quality.
That was overall not beneficial to QuickOpen's usefulness in practice.
Thus, the next attempt is to only do the fuzzy matching on the last
path segment; that still allows things like "btbrowser" for
"backtracebrowser.cpp" or "cml" for "CMakeLists.txt", but "hello" no longer
matches "/home/user/log/foo.log" or so.
CCMAIL:kevin@kfunk.org

M  +11   -17   language/interfaces/abbreviations.cpp
M  +1    -7    language/interfaces/abbreviations.h
M  +2    -3    language/interfaces/quickopenfilter.h
M  +4    -5    plugins/quickopen/tests/quickopentest.cpp

http://commits.kde.org/kdevplatform/245743bb877e3ed5cfd9c94a313393bacd96e1e4

diff --git a/language/interfaces/abbreviations.cpp \
b/language/interfaces/abbreviations.cpp index b9b5ee0..8df0504 100644
--- a/language/interfaces/abbreviations.cpp
+++ b/language/interfaces/abbreviations.cpp
@@ -102,27 +102,19 @@ bool matchesAbbreviation(const QStringRef &word, const QString \
&typed)  return matchesAbbreviationHelper(word, typed, offsets, depth);
 }
 
-AbbreviationMatchQuality matchesPath(const QVector< QString > &path, const QString \
&typed) +bool matchesPath(const QString &path, const QString &typed)
 {
   int consumed = 0;
-  bool sequential = true;
-  for ( const QString& item: path ) {
-    int pos = 0;
-    // try to find all the characters in typed in the right order in the path;
-    // jumps are allowed everywhere
-    bool componentHasMatch = false;
-    while ( consumed < typed.size() && pos < item.size() ) {
-      if ( typed.at(consumed).toLower() == item.at(pos).toLower() ) {
-        consumed++;
-        componentHasMatch = true;
-      }
-      else if ( componentHasMatch ) {
-        sequential = false;
-      }
-      pos++;
+  int pos = 0;
+  // try to find all the characters in typed in the right order in the path;
+  // jumps are allowed everywhere
+  while ( consumed < typed.size() && pos < path.size() ) {
+    if ( typed.at(consumed).toLower() == path.at(pos).toLower() ) {
+      consumed++;
     }
+    pos++;
   }
-  return consumed == typed.size() ? (sequential ? MatchesSequentially : \
MatchesSomewhere) : NoMatch; +  return consumed == typed.size();
 }
 
 bool matchesAbbreviationMulti(const QString &word, const QStringList \
&typedFragments) @@ -156,3 +148,5 @@ bool matchesAbbreviationMulti(const QString \
&word, const QStringList &typedFragm  }
   return matchedFragments == typedFragments.size();
 }
+
+// kate: space-indent on; indent-width 2
diff --git a/language/interfaces/abbreviations.h \
b/language/interfaces/abbreviations.h index 3ffca31..6adddb7 100644
--- a/language/interfaces/abbreviations.h
+++ b/language/interfaces/abbreviations.h
@@ -33,13 +33,7 @@ KDEVPLATFORMLANGUAGE_EXPORT bool matchesAbbreviationHelper(const \
QStringRef& wor  
 KDEVPLATFORMLANGUAGE_EXPORT bool matchesAbbreviation(const QStringRef& word, const \
QString& typed);  
-enum AbbreviationMatchQuality {
-  NoMatch,
-  MatchesSomewhere,
-  MatchesSequentially
-};
-
-KDEVPLATFORMLANGUAGE_EXPORT AbbreviationMatchQuality matchesPath(const \
QVector<QString>& path, const QString& typed); +KDEVPLATFORMLANGUAGE_EXPORT bool \
matchesPath(const QString& path, const QString& typed);  
 /**
  * @brief Matches a word against a list of search fragments.
diff --git a/language/interfaces/quickopenfilter.h \
b/language/interfaces/quickopenfilter.h index a27d9ec..65eb9d7 100644
--- a/language/interfaces/quickopenfilter.h
+++ b/language/interfaces/quickopenfilter.h
@@ -244,15 +244,14 @@ public:
                 ++pathIndex;
             }
 
-            AbbreviationMatchQuality fuzzyMatch = NoMatch;
             if (searchIndex != text.size()) {
-                if ( (fuzzyMatch = matchesPath(segments, joinedText)) == NoMatch ) {
+                if ( ! matchesPath(segments.last(), joinedText) ) {
                     continue;
                 }
             }
 
             // prefer matches whose last element starts with the filter
-            if ((pathIndex == segments.size() && lastMatchIndex == 0) || fuzzyMatch \
== MatchesSequentially) { +            if (pathIndex == segments.size() && \
lastMatchIndex == 0) {  startMatches << data;
             } else {
                 otherMatches << data;
diff --git a/plugins/quickopen/tests/quickopentest.cpp \
b/plugins/quickopen/tests/quickopentest.cpp index 139c871..0020f5f 100644
--- a/plugins/quickopen/tests/quickopentest.cpp
+++ b/plugins/quickopen/tests/quickopentest.cpp
@@ -111,13 +111,12 @@ void QuickOpenTest::testAbbreviations_data()
     const QStringList items = QStringList()
         << "/foo/bar/caz/a.h"
         << "/KateThing/CMakeLists.txt"
-        << "/FooBar/FooBar/Foo.h";
+        << "/FooBar/FooBar/Footestfoo.h";
 
-    QTest::newRow("path_segments") << items << "fbc" << ( QStringList() << \
                items.first() );
-    QTest::newRow("path_segment_abbrev") << items << "kthing" << ( QStringList() << \
                items.at(1) );
-    QTest::newRow("path_segment_abbrev_multi") << items << "kthingcml" << ( \
QStringList() << items.at(1) ); +    QTest::newRow("path_segments") << items << "fbc" \
<< ( QStringList() ); +    QTest::newRow("path_segment_abbrev") << items << "cmli" << \
                ( QStringList() << items.at(1) );
     QTest::newRow("path_segment_old") << items << "kate/cmake" << ( QStringList() << \
                items.at(1) );
-    QTest::newRow("path_segment_multi_mixed") << items << "fbfb/foo.h" << ( \
QStringList() << items.at(2) ); +    QTest::newRow("path_segment_multi_mixed") << \
items << "ftfoo.h" << ( QStringList() << items.at(2) );  }
 
 void QuickOpenTest::testSorting()


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

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