[Zope-CVS] CVS: Products/ZCTextIndex/tests - mhindex.py:1.6 testLexicon.py:1.3
Guido van Rossum
guido@python.org
Thu, 16 May 2002 15:51:13 -0400
Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv16536/tests
Modified Files:
mhindex.py testLexicon.py
Log Message:
Fix queries of the form 'extension module C'.
=== Products/ZCTextIndex/tests/mhindex.py 1.5 => 1.6 ===
continue
try:
- n, results = self.timequery(text, top + nbest)
+ results, n = self.timequery(text, top + nbest)
except:
reportexc()
text = ""
@@ -163,7 +163,7 @@
top += nbest
def query(self, text, nbest=NBEST, maxlines=MAXLINES):
- n, results = self.timequery(text, nbest)
+ results, n = self.timequery(text, nbest)
if not n:
print "No hits for %r." % text
return
@@ -173,11 +173,11 @@
def timequery(self, text, nbest):
t0 = time.time()
c0 = time.clock()
- n, results = self.index.query(text, nbest)
+ results, n = self.index.query(text, nbest)
t1 = time.time()
c1 = time.clock()
print "[Query time: %.3f real, %.3f user]" % (t1-t0, c1-c0)
- return n, results
+ return results, n
def formatresults(self, text, results, maxlines=MAXLINES,
lo=0, hi=sys.maxint):
@@ -397,9 +397,11 @@
parser = QueryParser()
tree = parser.parseQuery(query)
results = tree.executeQuery(self.index)
+ if results is None:
+ return [], 0
chooser = NBest(nbest)
chooser.addmany(results.items())
- return len(results), chooser.getbest()
+ return chooser.getbest(), len(results)
def query_weight(self, query):
parser = QueryParser()
=== Products/ZCTextIndex/tests/testLexicon.py 1.2 => 1.3 ===
wids = lexicon.sourceToWordIds('cats and dogs')
wids = lexicon.termToWordIds('boxes')
- self.assertEqual(wids, [])
+ self.assertEqual(wids, [0])
def testOnePipelineElement(self):
lexicon = Lexicon(Splitter(), StupidPipelineElement('dogs', 'fish'))
@@ -94,7 +94,7 @@
lexicon = Lexicon(Splitter())
wids = lexicon.sourceToWordIds('CATS and dogs')
wids = lexicon.termToWordIds('cats and dogs')
- self.assertEqual(wids, [2, 3])
+ self.assertEqual(wids, [0, 2, 3])
def testTwoElementPipeline(self):
lexicon = Lexicon(Splitter(),