Added keyword searching.
This commit is contained in:
parent
d993695b0f
commit
8cde0b47b8
|
@ -386,22 +386,43 @@ class FaqWizard:
|
||||||
if not query:
|
if not query:
|
||||||
self.error("Empty query string!")
|
self.error("Empty query string!")
|
||||||
return
|
return
|
||||||
self.prologue(T_SEARCH)
|
if self.ui.querytype == 'simple':
|
||||||
if self.ui.querytype != 'regex':
|
|
||||||
for c in '\\.[]?+^$*':
|
for c in '\\.[]?+^$*':
|
||||||
if c in query:
|
if c in query:
|
||||||
query = replace(query, c, '\\'+c)
|
query = replace(query, c, '\\'+c)
|
||||||
|
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:
|
||||||
|
# Default to regex
|
||||||
|
queries = [query]
|
||||||
|
self.prologue(T_SEARCH)
|
||||||
|
progs = []
|
||||||
|
for query in queries:
|
||||||
if self.ui.casefold == 'no':
|
if self.ui.casefold == 'no':
|
||||||
p = regex.compile(query)
|
p = regex.compile(query)
|
||||||
else:
|
else:
|
||||||
p = regex.compile(query, regex.casefold)
|
p = regex.compile(query, regex.casefold)
|
||||||
|
progs.append(p)
|
||||||
hits = []
|
hits = []
|
||||||
for file in self.dir.list():
|
for file in self.dir.list():
|
||||||
try:
|
try:
|
||||||
entry = self.dir.open(file)
|
entry = self.dir.open(file)
|
||||||
except FileError:
|
except FileError:
|
||||||
constants
|
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)
|
hits.append(file)
|
||||||
if not hits:
|
if not hits:
|
||||||
emit(NO_HITS, self.ui, count=0)
|
emit(NO_HITS, self.ui, count=0)
|
||||||
|
|
Loading…
Reference in New Issue