[Zope-CVS] CVS: Products/FieldedTextIndex - index.py:1.11
test.py:1.9
Casey Duncan
casey at zope.com
Mon Jan 19 23:13:37 EST 2004
Update of /cvs-repository/Products/FieldedTextIndex
In directory cvs.zope.org:/tmp/cvs-serv8609
Modified Files:
index.py test.py
Log Message:
Add tests for default weights. Make sure setDefaultWeights converts weight values to integers. Perform functional test in prep for 0.2 release.
=== Products/FieldedTextIndex/index.py 1.10 => 1.11 ===
--- Products/FieldedTextIndex/index.py:1.10 Mon Jan 19 01:45:54 2004
+++ Products/FieldedTextIndex/index.py Mon Jan 19 23:13:36 2004
@@ -124,7 +124,7 @@
def _mapWeights2Fields(self, weights):
weights2fields = {}
for fieldid, fname in enumerate(self._fields):
- weight = weights.get(fname, 1)
+ weight = int(weights.get(fname, 1))
if weight in weights2fields:
weights2fields[weight].insert(fieldid)
else:
=== Products/FieldedTextIndex/test.py 1.8 => 1.9 ===
--- Products/FieldedTextIndex/test.py:1.8 Mon Jan 19 01:45:54 2004
+++ Products/FieldedTextIndex/test.py Mon Jan 19 23:13:36 2004
@@ -331,6 +331,17 @@
expected.update(weights)
self.assertEqual(self.index.getDefaultWeights(), expected)
+ def test_weights_convert_to_ints(self):
+ self.index_one(1)
+ self.index_two(2)
+ weights = {'title':'3', 'izzy':'-1'}
+ self.index.setDefaultWeights(weights)
+ expected = {}
+ for f in self.index.fieldNames():
+ expected[f] = 1
+ expected.update({'title':3, 'izzy':-1})
+ self.assertEqual(self.index.getDefaultWeights(), expected)
+
def test_set_default_weights_resets_existing(self):
self.index_one(1)
self.index_two(2)
@@ -341,7 +352,24 @@
for f in self.index.fieldNames():
expected[f] = 1
expected.update(weights)
- self.assertEqual(self.index.getDefaultWeights(), expected)
+ self.assertEqual(self.index.getDefaultWeights(), expected)
+
+ def test_query_with_default_weights(self):
+ self.index_one(1)
+ self.index_two(2)
+ r1, used = self.index._apply_index({'fields':{'query':'title'}})
+ self.index.setDefaultWeights({'title':2})
+ r2, used = self.index._apply_index({'fields':{'query':'title'}})
+ self.failUnless(r1[1]*2 == r2[1])
+
+ def test_query_weights_override_defaults(self):
+ self.index_one(1)
+ self.index_two(2)
+ self.index.setDefaultWeights({'title':2})
+ r1, used = self.index._apply_index({'fields':{'query':'title'}})
+ r2, used = self.index._apply_index(
+ {'fields':{'query':'title', 'field_weights':{'title':1}}})
+ self.failUnless(r1[1] == r2[1]*2)
def test_suite():
return TestSuite((makeSuite(FieldedTextIndexTest),))
More information about the Zope-CVS
mailing list