Ejemplo n.º 1
0
 def _search_for_items(self, query):
     result = None
     if IItemSubscriber.providedBy(query) or valid_signature(query):
         sresult = set()
         if not isinstance(query, tuple):
             query = query.signature()
         for idx in self.indexes:
             sresult = sresult | set(
                 self._search_for_items({idx: query}))
         return sorted(tuple(sresult))
     # search for specific subscription relationship name:
     for (k, v) in query.items():
         if str(k) in self.indexes:
             idx = self.indexes[str(k)]
             if IItemSubscriber.providedBy(v):
                 signature = v.signature()
             elif isinstance(v, tuple) and len(v) == 2:
                 signature = v
             else:
                 raise ValueError('unable to obtain subscriber signature')
             if result is None:
                 result = set(idx.item_uids_for(signature))
             else:
                 result = result & set(idx.item_uids_for(signature))
     if not result:
         return ()
     return tuple(result)
Ejemplo n.º 2
0
 def search(self, query):
     if isinstance(query, basestring):
         return self._search_for_subscribers(query)  # query: UID
     if IItemSubscriber.providedBy(query) or valid_signature(query):
         return self._search_for_items(query)  # query: sub or sig
     # query for named subscription relationships:
     k, v = query.items()[0]
     if IItemSubscriber.providedBy(v) or isinstance(v, tuple):
         return self._search_for_items(query)  # tuple of uids
     return self._search_for_subscribers(query)