Bug 48009 - search should be smarter
Summary: search should be smarter
Status: RESOLVED FIXED
Alias: None
Product: kfind
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR wishlist
Target Milestone: ---
Assignee: Eric Coquelle
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-09-18 11:23 UTC by julo
Modified: 2003-03-04 19:37 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
patch for search behaviour (2.43 KB, patch)
2003-02-13 19:28 UTC, Klas Kalass
Details

Note You need to log in before you can comment on or make changes to this bug.
Description julo 2002-09-18 11:23:31 UTC
Version:            (using KDE KDE 3.0.7)
Installed from:    Compiled From Sources

I think the default behaviour of kfind isn't really well thought.

For example, if you have a file that you remember contains the word "project", just typing "project" in kfind's text field will return files strictly named "project".

First, the default option should NOT be case sensitive because you often don't remember whether the file you search for has capital letters or not.

Then, the default behaviour should be to search for "project", "*project", "project*" and "*project*" automatically because if you don't know how to use regular expressions, you have to search for those 4 possibilities in order to find a file whose name contains "project".

I think that's the way Windows works and that's IMO the good way to go.
Comment 1 hughjonesd 2003-02-01 14:08:59 UTC
Me too! 
 
I think the ideal would be to make it like the Kate find dialog. By default it would find filenames 
containing the text entered. However there would also be a regular expression option with a 
button to use the graphical regular expression editor. 
Comment 2 Klas Kalass 2003-02-13 19:28:38 UTC
Created attachment 953 [details]
patch for search behaviour

With the patch, the search will be sloppy (i.e. find 'patch.diff' if 'patch' is
the search-word) and do an exact match if a wildcard is used (i.e. does not
find 'patch.diff' if '*patch' is the search-word).

Since this wish pops up every now and again I think this patch should be
applied, thanks.

This version of the patch is pretty runtime efficient since it caches the
information wether a search pattern contains a wildcard.
Comment 3 Klas Kalass 2003-03-04 19:37:57 UTC
Subject: kdebase/kfind

CVS commit by kalass: 

CCMAIL: 48009-done@bugs.kde.org
better default search behaviour, approved by the kfind maintainer Eric Coquelle


  M +15 -8     kquery.cpp   1.16
  M +1 -0      kquery.h   1.8


--- kdebase/kfind/kquery.cpp  #1.15:1.16
@@ -75,10 +75,10 @@ void KQuery::slotListEntries( KIO::Job *
     
     bool matched=false;
-    
-    for ( filename_match = m_regexps.first(); !matched && filename_match; filename_match = m_regexps.next() )
+    QValueList<bool>::iterator m_regexpsContainsGlobsIterator = m_regexpsContainsGlobs.begin();
+    for ( filename_match = m_regexps.first(); !matched && filename_match && m_regexpsContainsGlobsIterator != m_regexpsContainsGlobs.end(); filename_match = m_regexps.next(), m_regexpsContainsGlobsIterator++ )
       {
-        
-        matched |=  filename_match->isEmpty()  ||
-          (filename_match->exactMatch( file->url().fileName( true ) ) );
+          matched = (*m_regexpsContainsGlobsIterator)
+                    ? filename_match->exactMatch( file->url().fileName( true ) )
+                    : filename_match->search(file->url().fileName( true )) > -1;
       }
     if (!matched)
@@ -276,9 +276,16 @@ void KQuery::setGroupname(QString groupn
 void KQuery::setRegExp(const QString &regexp, bool caseSensitive)
 {
+  QRegExp *regExp;
   QRegExp sep(";");
   QStringList strList=QStringList::split( sep, regexp, false);
+  QRegExp globChars ("[\\*\\?\\[\\]]", TRUE,  FALSE);
+
   m_regexps.clear();
-  for ( QStringList::Iterator it = strList.begin(); it != strList.end(); ++it )
-     m_regexps.append(new QRegExp((*it),caseSensitive,true));
+  m_regexpsContainsGlobs.clear();
+  for ( QStringList::Iterator it = strList.begin(); it != strList.end(); ++it ) {
+    regExp = new QRegExp((*it),caseSensitive,true);
+    m_regexpsContainsGlobs.append(regExp->pattern().contains(globChars));
+    m_regexps.append(regExp);
+  }
 }
 

--- kdebase/kfind/kquery.h  #1.7:1.8
@@ -65,4 +65,5 @@ class KQuery : public QObject
   bool m_regexpForContent;
   QPtrList<QRegExp> m_regexps;// regexps for file name
+  QValueList<bool> m_regexpsContainsGlobs;
   KIO::ListJob *job;
 };