@@ -386,22 +386,43 @@ def do_search(self):
386386 if not query :
387387 self .error ("Empty query string!" )
388388 return
389- self .prologue (T_SEARCH )
390- if self .ui .querytype != 'regex' :
389+ if self .ui .querytype == 'simple' :
391390 for c in '\\ .[]?+^$*' :
392391 if c in query :
393392 query = replace (query , c , '\\ ' + c )
394- if self .ui .casefold == 'no' :
395- p = regex .compile (query )
393+ queries = [query ]
394+ elif self .ui .querytype in ('anykeywords' , 'allkeywords' ):
395+ import regsub
396+ words = string .split (regsub .gsub ('[^a-zA-Z0-9]+' , ' ' , query ))
397+ if not words :
398+ self .error ("No keywords specified!" )
399+ return
400+ words = map (lambda w : '\<%s\>' % w , words )
401+ if self .ui .querytype [:3 ] == 'any' :
402+ queries = [string .join (words , '\|' )]
403+ else :
404+ queries = words
396405 else :
397- p = regex .compile (query , regex .casefold )
406+ # Default to regex
407+ queries = [query ]
408+ self .prologue (T_SEARCH )
409+ progs = []
410+ for query in queries :
411+ if self .ui .casefold == 'no' :
412+ p = regex .compile (query )
413+ else :
414+ p = regex .compile (query , regex .casefold )
415+ progs .append (p )
398416 hits = []
399417 for file in self .dir .list ():
400418 try :
401419 entry = self .dir .open (file )
402420 except FileError :
403421 constants
404- if p .search (entry .title ) >= 0 or p .search (entry .body ) >= 0 :
422+ for p in progs :
423+ if p .search (entry .title ) < 0 and p .search (entry .body ) < 0 :
424+ break
425+ else :
405426 hits .append (file )
406427 if not hits :
407428 emit (NO_HITS , self .ui , count = 0 )
0 commit comments