Commit 33715661 authored by Hanno Schlichting's avatar Hanno Schlichting

Change the determine_value_indexes function to actually do what it promises

parent 966de0cd
......@@ -20,25 +20,26 @@ from Products.PluginIndexes.interfaces import IUniqueValueIndex
writelock = allocate_lock()
reports = {}
MAX_DISTINCT_VALUES = 20
MAX_DISTINCT_VALUES = 10
LOG = logging.getLogger('CatalogReport')
def determine_value_indexes(catalog):
# This function determines all indexes whose values should be respected
# in the prioritymap key. A index type needs to be registered in the
# VALUETYPES module global and the number of unique values needs to be
# in the report key. The number of unique values for the index needs to be
# lower than the MAX_DISTINCT_VALUES watermark.
valueindexes = []
for name, index in catalog.indexes.items():
if IUniqueValueIndex.providedBy(index):
if len(index) < MAX_DISTINCT_VALUES:
# Checking for len of an index should be fast. It's a stored
# BTrees.Length value and requires no calculation.
values = index.uniqueValues()
if values and len(values) < MAX_DISTINCT_VALUES:
# Only consider indexes which actually return a number
# greater than zero
valueindexes.append(name)
return frozenset(valueindexes)
def make_key(catalog,request):
valueindexes = determine_value_indexes(catalog)
......
......@@ -870,11 +870,10 @@ class TestCatalogReport(unittest.TestCase):
self.zcat.addIndex('title', 'TextIndex')
self.zcat._catalog.vocabulary = vocabulary
for i in range(10):
for i in range(9):
obj = zdummy(i)
obj.big = i > 5
self.zcat.catalog_object(obj, str(i))
def test_ReportLength(self):
""" tests the report aggregation """
......@@ -912,7 +911,7 @@ class TestCatalogReport(unittest.TestCase):
def test_ReportKey(self):
""" tests the query keys for uniqueness """
# query key 1
key = ('sort_on', ('big', 'True'))
self.zcat.manage_resetCatalogReport()
......@@ -933,21 +932,18 @@ class TestCatalogReport(unittest.TestCase):
self.assertEqual(r['query'],key)
self.assertEqual(r['counter'],1)
# query key 3
key = ('sort_on', ('num', '[3, 4, 5]'))
self.zcat.manage_resetCatalogReport()
self.zcat.searchResults(num=[5,4,3],sort_on='num')
self.zcat.searchResults(num=(3,4,5),sort_on='num')
self.zcat.searchResults(num=[5,4,3], sort_on='num')
self.zcat.searchResults(num=(3,4,5), sort_on='num')
r = self.zcat.getCatalogReport()[0]
#print 'hits: %(counter)s, mean duration: %(duration)3.2fms, key: %(query)s' % r
self.assertEqual(r['query'],key)
self.assertEqual(r['counter'],2)
self.assertEqual(r['query'], key)
self.assertEqual(r['counter'], 2)
def test_suite():
suite = unittest.TestSuite()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment