Commit fee8d6ac authored by Hanno Schlichting's avatar Hanno Schlichting

Sort indexes according to ILimitedResultIndex support. Indexes without the...

Sort indexes according to ILimitedResultIndex support. Indexes without the support are queried first, so the indexes supporting the feature already get a limited result set.
parent bda58f12
......@@ -471,7 +471,13 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
def _sorted_search_indexes(self, query):
# Simple implementation doing no ordering.
query_keys = query.keys()
return [i for i in self.indexes.keys() if i in query_keys]
order = []
for name, index in self.indexes.items():
if name not in query_keys:
continue
order.append((ILimitedResultIndex.providedBy(index), name))
order.sort()
return order
def search(self, query, sort_index=None, reverse=0, limit=None, merge=1):
"""Iterate through the indexes, applying the query to each one. If
......@@ -495,21 +501,15 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
# Canonicalize the request into a sensible query before passing it on
query = self.make_query(query)
query_keys = query.keys()
cr = self.getCatalogReport(query)
cr.start()
for i in self._sorted_search_indexes(query):
for limit_result, i in self._sorted_search_indexes(query):
index = self.getIndex(i)
_apply_index = getattr(index, "_apply_index", None)
if _apply_index is None:
continue
limit_result = False
if ILimitedResultIndex.providedBy(index):
limit_result = True
cr.split(i)
if limit_result:
r = _apply_index(query, rs)
......
......@@ -291,12 +291,19 @@ class TestCatalog(CatalogBase, unittest.TestCase):
def test_sorted_search_indexes_one(self):
result = self._catalog._sorted_search_indexes({'att1': 'a'})
self.assertEquals(result, ['att1'])
self.assertEquals(result, [(True, 'att1')])
def test_sorted_search_indexes_many(self):
query = {'att1': 'a', 'att2': 'b', 'num': 1}
result = self._catalog._sorted_search_indexes(query)
self.assertEquals(set(result), set(['att1', 'att2', 'num']))
indexes = [r[1] for r in result]
self.assertEquals(set(indexes), set(['att1', 'att2', 'num']))
def test_sorted_search_indexes_priority(self):
# att2 and col2 don't support ILimitedResultIndex, att1 does
query = {'att1': 'a', 'att2': 'b', 'col2': 'c'}
result = self._catalog._sorted_search_indexes(query)
self.assertEquals(result.index((True, 'att1')), 2)
# search
# sortResults
......
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