[Xfce4-commits] [apps/catfish] 01/01: Add support for quoted search strings (bug #14501)

noreply at xfce.org noreply at xfce.org
Sun Jan 20 13:07:20 CET 2019


This is an automated email from the git hooks/post-receive script.

b   l   u   e   s   a   b   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/catfish.

commit 35830d3e5b5adf3d55c095b59751ca400eb2c2c0
Author: Sean Davis <smd.seandavis at gmail.com>
Date:   Sun Jan 20 07:07:15 2019 -0500

    Add support for quoted search strings (bug #14501)
---
 catfish/CatfishSearchEngine.py | 32 +++++++++++++++++++-------------
 po/catfish.pot                 |  2 +-
 2 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/catfish/CatfishSearchEngine.py b/catfish/CatfishSearchEngine.py
index a9fef19..1cae6b1 100644
--- a/catfish/CatfishSearchEngine.py
+++ b/catfish/CatfishSearchEngine.py
@@ -20,6 +20,7 @@ import logging
 
 import io
 import os
+import re
 import signal
 import subprocess
 import time
@@ -50,11 +51,21 @@ else:
     locate_support = False
 FNULL.close()
 
+def get_keyword_list(keywords):
+    keywords = keywords.replace(",", " ").strip().lower()
+    kwords = []
+    matches = re.findall(r'\"(.+?)\"', keywords)
+    for match in matches:
+        newmatch = match.replace(" ", "\0")
+        newmatch = newmatch.replace("\"", "")
+        keywords = keywords.replace("\"%s\"" % match, newmatch)
+    for keyword in keywords.split(" "):
+        kwords.append(keyword.replace("\0", " "))
+    return kwords
 
 def string_regex(keywords, path):
     """Returns a string with the regular expression containing all combinations
     of the keywords."""
-    keywords = keywords.split()
     if len(keywords) == 0:
         return ''
     if len(keywords) == 1:
@@ -133,30 +144,25 @@ class CatfishSearchEngine:
         self.start_time = time.time()
         self.stop_time = 0
 
-        keywords = keywords.replace(',', ' ').strip().lower()
+        keywords = get_keyword_list(keywords)
+        self.keywords = " ".join(keywords)
 
         logger.debug("[%i] path: %s, keywords: %s, limit: %i, regex: %s",
                      self.engine_id, str(path), str(keywords), limit,
                      str(regex))
 
-        self.keywords = keywords
-
         wildcard_chunks = []
-        for key in self.keywords.split():
+        keys = []
+        for key in keywords:
             if '*' in key:
                 wildcard_chunks.append(key.split('*'))
-
-        keywords = keywords.replace('*', ' ')
+            else:
+                keys.append(key)
 
         # For simplicity, make sure the path contains a trailing '/'
         if not path.endswith('/'):
             path += '/'
 
-        # Transform the keywords into a clean list.
-        keys = []
-        for key in keywords.split():
-            keys.append(key.strip())
-
         # Path exclusions for efficiency
         exclude = []
         cache_path = os.path.expanduser("~/.cache")
@@ -376,7 +382,7 @@ class CatfishSearchMethod_Fulltext(CatfishSearchMethod):
                                     break
 
                                 if self.exact:
-                                    if keywords in line:
+                                    if " ".join(keywords) in line:
                                         yield os.path.join(root, filename)
                                         break
                                 else:
diff --git a/po/catfish.pot b/po/catfish.pot
index f94681a..a44fef1 100644
--- a/po/catfish.pot
+++ b/po/catfish.pot
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2019-01-19 23:28-0500\n"
+"POT-Creation-Date: 2019-01-20 07:06-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
 "Language-Team: LANGUAGE <LL at li.org>\n"

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list