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):
def _sorted_search_indexes(self, query):
# 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):
"""Iterate through the indexes, applying the query to each one. If
......@@ -500,11 +501,6 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
cr.start()
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)
_apply_index = getattr(index, "_apply_index", None)
if _apply_index is None:
......
......@@ -199,7 +199,6 @@ class TestCatalog(CatalogBase, unittest.TestCase):
att3 = KeywordIndex('att3')
num = FieldIndex('num')
self._catalog.addIndex('att1', att1)
self._catalog.addIndex('att2', att2)
self._catalog.addIndex('att3', att3)
......@@ -285,6 +284,20 @@ class TestCatalog(CatalogBase, unittest.TestCase):
# getIndexDataForRID
# make_query
# _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
# sortResults
# _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