[Zope-CVS] CVS: Products/ZCTextIndex/tests - mhindex.py:1.12
Guido van Rossum
guido@python.org
Thu, 23 May 2002 11:17:34 -0400
Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv20170
Modified Files:
mhindex.py
Log Message:
Add a primitive way to show the full message.
=== Products/ZCTextIndex/tests/mhindex.py 1.11 => 1.12 ===
text = ""
top = 0
+ results = []
while 1:
try:
line = raw_input("Query: ")
@@ -238,6 +239,9 @@
print "\nBye."
break
line = line.strip()
+ if line.startswith("/"):
+ self.specialcommand(line, results, top - nbest)
+ continue
if line:
text = line
top = 0
@@ -251,7 +255,6 @@
except:
reportexc()
text = ""
- top = 0
continue
if len(results) <= top:
if not n:
@@ -259,12 +262,37 @@
else:
print "No more hits for %r." % text
text = ""
- top = 0
continue
print "[Results %d-%d from %d" % (top+1, min(n, top+nbest), n),
print "for query %s]" % repr(text)
self.formatresults(text, results, maxlines, top, top+nbest)
top += nbest
+
+ def specialcommand(self, line, results, first):
+ assert line.startswith("/")
+ line = line[1:]
+ if not line:
+ n = first
+ else:
+ try:
+ n = int(line) - 1
+ except:
+ print "Huh?"
+ return
+ if n < 0 or n >= len(results):
+ print "Out of range"
+ return
+ docid, score = results[n]
+ path = self.docpaths[docid]
+ i = path.rfind("/")
+ assert i > 0
+ folder = path[:i]
+ n = path[i+1:]
+ cmd = "show +%s %s" % (folder, n)
+ if os.getenv("DISPLAY"):
+ os.system("xterm -e %s &" % cmd)
+ else:
+ os.system(cmd)
def query(self, text, nbest=NBEST, maxlines=MAXLINES):
results, n = self.timequery(text, nbest)