]> gitweb.pimeys.fr Git - bots/parrot.git/commitdiff
[quotes] Nan mais en fait la recherche avec et sans regexp *c'est* différent, on...
authorVincent Le Gallic <legallic@crans.org>
Sat, 12 Mar 2016 13:41:07 +0000 (14:41 +0100)
committerVincent Le Gallic <legallic@crans.org>
Sat, 12 Mar 2016 13:41:07 +0000 (14:41 +0100)
quotes.py

index 80fea5328eafd7f25bd41a373f2be71d565551be..0dcdabbe4411f08cf2f7ace767805b55fa6faede 100644 (file)
--- a/quotes.py
+++ b/quotes.py
@@ -194,24 +194,31 @@ class QuoteDB(object):
         Si ``regexp=True``, utilise directement les termes comme des regexp.
         """
         params = [inquote, author]
-        regexps = []
-        for param in params:
-            if param is None:
-                param = u".*"
-            elif not regexp:
-                param = u".*%s.*" % param
-            regexps.append(re.compile(param, flags=re.UNICODE + re.IGNORECASE))
-        l = [q for q in self.quotelist if all([reg.match(truc) for (reg, truc) in zip(regexps, [q.content, q.author])])]
+        if regexp:
+            regexps = []
+            for param in params:
+                if param is None:
+                    param = u".*"
+                regexps.append(re.compile(param, flags=re.UNICODE + re.IGNORECASE))
+            l = [q for q in self.quotelist if all([reg.match(truc) for (reg, truc) in zip(regexps, [q.content, q.author, q.proper_place])])]
+        else:
+            for (i, param) in enumerate(params):
+                if param is None:
+                    params[i] = u""
+            l = [q for q in self.quotelist if all([param.lower() in truc.lower() for (param, truc) in zip(params, [q.content, q.author, q.proper_place])])]
         return l
     
     def search_authors(self, author=None, regexp=False):
         """Renvoie la liste des auteurs contenant ``author`` ou qui matchent la regexp."""
-        if author is None:
-            author = u".*"
-        elif not regexp:
-            author = u".*%s.*" % author
-        areg = re.compile(author, flags=re.UNICODE + re.IGNORECASE)
-        l = list(set([q.author for q in self.quotelist if areg.match(q.author)]))
+        if regexp:
+            if author is None:
+                author = u".*"
+            areg = re.compile(author, flags=re.UNICODE + re.IGNORECASE)
+            l = list(set([q.author for q in self.quotelist if areg.match(q.author)]))
+        else:
+            if author is None:
+                author = u""
+            l = list(set([q.author for q in self.quotelist if author.lower() in q.author.lower()]))
         return l
 
 def dump(quotedb, dump_file=None):