summaryrefslogtreecommitdiffstats
path: root/Tools/faqwiz
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-05-26 16:35:46 (GMT)
committerGuido van Rossum <guido@python.org>1997-05-26 16:35:46 (GMT)
commit8cde0b47b8e22f20f6cd7c077b0d66d841549f5e (patch)
tree6963e1254e35785aaf82c137ce7e46d3a797eadd /Tools/faqwiz
parentd993695b0ff2918e9bb9c3d0f7ec71606d18edf2 (diff)
downloadcpython-8cde0b47b8e22f20f6cd7c077b0d66d841549f5e.zip
cpython-8cde0b47b8e22f20f6cd7c077b0d66d841549f5e.tar.gz
cpython-8cde0b47b8e22f20f6cd7c077b0d66d841549f5e.tar.bz2
Added keyword searching.
Diffstat (limited to 'Tools/faqwiz')
-rw-r--r--Tools/faqwiz/faqwiz.py33
1 files changed, 27 insertions, 6 deletions
diff --git a/Tools/faqwiz/faqwiz.py b/Tools/faqwiz/faqwiz.py
index 2276498..17a79d6 100644
--- a/Tools/faqwiz/faqwiz.py
+++ b/Tools/faqwiz/faqwiz.py
@@ -386,22 +386,43 @@ class FaqWizard:
if not query:
self.error("Empty query string!")
return
- self.prologue(T_SEARCH)
- if self.ui.querytype != 'regex':
+ if self.ui.querytype == 'simple':
for c in '\\.[]?+^$*':
if c in query:
query = replace(query, c, '\\'+c)
- if self.ui.casefold == 'no':
- p = regex.compile(query)
+ queries = [query]
+ elif self.ui.querytype in ('anykeywords', 'allkeywords'):
+ import regsub
+ words = string.split(regsub.gsub('[^a-zA-Z0-9]+', ' ', query))
+ if not words:
+ self.error("No keywords specified!")
+ return
+ words = map(lambda w: '\<%s\>' % w, words)
+ if self.ui.querytype[:3] == 'any':
+ queries = [string.join(words, '\|')]
+ else:
+ queries = words
else:
- p = regex.compile(query, regex.casefold)
+ # Default to regex
+ queries = [query]
+ self.prologue(T_SEARCH)
+ progs = []
+ for query in queries:
+ if self.ui.casefold == 'no':
+ p = regex.compile(query)
+ else:
+ p = regex.compile(query, regex.casefold)
+ progs.append(p)
hits = []
for file in self.dir.list():
try:
entry = self.dir.open(file)
except FileError:
constants
- if p.search(entry.title) >= 0 or p.search(entry.body) >= 0:
+ for p in progs:
+ if p.search(entry.title) < 0 and p.search(entry.body) < 0:
+ break
+ else:
hits.append(file)
if not hits:
emit(NO_HITS, self.ui, count=0)