[Zope-CVS] CVS: Products/ZCTextIndex/tests - mhindex.py:1.7 testQueryEngine.py:1.3 testQueryParser.py:1.4 testZCTextIndex.py:1.26
Guido van Rossum
guido@python.org
Sun, 19 May 2002 08:57:08 -0400
Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv22007/tests
Modified Files:
mhindex.py testQueryEngine.py testQueryParser.py
testZCTextIndex.py
Log Message:
QueryParser refactoring step 1: add the lexicon to the constructor args.
=== Products/ZCTextIndex/tests/mhindex.py 1.6 => 1.7 ===
def query(self, query, nbest=10):
# returns a total hit count and a mapping from docids to scores
- parser = QueryParser()
+ parser = QueryParser(self.lexicon)
tree = parser.parseQuery(query)
results = tree.executeQuery(self.index)
if results is None:
@@ -404,7 +404,7 @@
return chooser.getbest(), len(results)
def query_weight(self, query):
- parser = QueryParser()
+ parser = QueryParser(self.lexicon)
tree = parser.parseQuery(query)
terms = tree.terms()
return self.index.query_weight(terms)
=== Products/ZCTextIndex/tests/testQueryEngine.py 1.2 => 1.3 ===
from Products.ZCTextIndex.QueryParser import QueryParser
from Products.ZCTextIndex.ParseTree import ParseError, QueryError
+from Products.ZCTextIndex.Lexicon import Lexicon, Splitter
class FauxIndex:
@@ -34,7 +35,8 @@
class TestQueryEngine(TestCase):
def setUp(self):
- self.parser = QueryParser()
+ self.lexicon = Lexicon(Splitter())
+ self.parser = QueryParser(self.lexicon)
self.index = FauxIndex()
def compareSet(self, set, dict):
=== Products/ZCTextIndex/tests/testQueryParser.py 1.3 => 1.4 ===
from Products.ZCTextIndex.ParseTree import OrNode, AndNode, NotNode
from Products.ZCTextIndex.ParseTree import AtomNode, PhraseNode, GlobNode
+from Products.ZCTextIndex.Lexicon import Lexicon, Splitter
class TestQueryParser(TestCase):
@@ -54,7 +55,8 @@
self.assertRaises(ParseError, self.p.parseQuery, input)
def setUp(self):
- self.p = QueryParser()
+ self.lexicon = Lexicon(Splitter())
+ self.p = QueryParser(self.lexicon)
def testParseQuery(self):
self.expect("foo", AtomNode("foo"))
=== Products/ZCTextIndex/tests/testZCTextIndex.py 1.25 => 1.26 ===
for i in range(len(queries)):
raw = queries[i]
- q = QueryParser().parseQuery(raw)
+ q = QueryParser(self.lexicon).parseQuery(raw)
wq = self.index.query_weight(q.terms())
eq(wq, scaled_int(wqs[i]))
r, n = self.zc_index.query(raw)
@@ -428,10 +428,11 @@
extra = Extra()
extra.doc_attr = 'text'
extra.lexicon_id = 'lexicon'
- caller = LexiconHolder(Lexicon(Splitter(), CaseNormalizer(),
- StopWordRemover()))
+ self.lexicon = Lexicon(Splitter(), CaseNormalizer(),
+ StopWordRemover())
+ caller = LexiconHolder(self.lexicon)
self.zc_index = ZCTextIndex('name', extra, caller, self.IndexFactory)
- self.p = self.parser = QueryParser()
+ self.p = self.parser = QueryParser(self.lexicon)
self.index = self.zc_index.index
self.add_docs()