Commit bda58f12 authored by Hanno Schlichting's avatar Hanno Schlichting

Move index restriction to _sorted_search_indexes method

parent ed315987
...@@ -470,7 +470,8 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -470,7 +470,8 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
def _sorted_search_indexes(self, query): def _sorted_search_indexes(self, query):
# Simple implementation doing no ordering. # Simple implementation doing no ordering.
return self.indexes.keys() query_keys = query.keys()
return [i for i in self.indexes.keys() if i in query_keys]
def search(self, query, sort_index=None, reverse=0, limit=None, merge=1): def search(self, query, sort_index=None, reverse=0, limit=None, merge=1):
"""Iterate through the indexes, applying the query to each one. If """Iterate through the indexes, applying the query to each one. If
...@@ -500,11 +501,6 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -500,11 +501,6 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
cr.start() cr.start()
for i in self._sorted_search_indexes(query): for i in self._sorted_search_indexes(query):
if i not in query_keys:
# Do not ask indexes to restrict the result, which aren't
# part of the query
continue
index = self.getIndex(i) index = self.getIndex(i)
_apply_index = getattr(index, "_apply_index", None) _apply_index = getattr(index, "_apply_index", None)
if _apply_index is None: if _apply_index is None:
......
...@@ -199,7 +199,6 @@ class TestCatalog(CatalogBase, unittest.TestCase): ...@@ -199,7 +199,6 @@ class TestCatalog(CatalogBase, unittest.TestCase):
att3 = KeywordIndex('att3') att3 = KeywordIndex('att3')
num = FieldIndex('num') num = FieldIndex('num')
self._catalog.addIndex('att1', att1) self._catalog.addIndex('att1', att1)
self._catalog.addIndex('att2', att2) self._catalog.addIndex('att2', att2)
self._catalog.addIndex('att3', att3) self._catalog.addIndex('att3', att3)
...@@ -285,6 +284,20 @@ class TestCatalog(CatalogBase, unittest.TestCase): ...@@ -285,6 +284,20 @@ class TestCatalog(CatalogBase, unittest.TestCase):
# getIndexDataForRID # getIndexDataForRID
# make_query # make_query
# _sorted_search_indexes # _sorted_search_indexes
def test_sorted_search_indexes_empty(self):
result = self._catalog._sorted_search_indexes({})
self.assertEquals(len(result), 0)
def test_sorted_search_indexes_one(self):
result = self._catalog._sorted_search_indexes({'att1': 'a'})
self.assertEquals(result, ['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']))
# search # search
# sortResults # sortResults
# _get_sort_attr # _get_sort_attr
......
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