work in progress: filters

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@3457 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2009-07-16 06:04:35 +00:00
parent 75efbfb38a
commit a7351c0cff
3 changed files with 19 additions and 8 deletions

View file

@ -187,10 +187,12 @@ concepts) that are direct or indirect children of jim.
>>> sorted(o.title for o in getObjects((qu & fltr.query()).apply()))
[u'Doc 001', u'Doc 003']
>>> #fltr.check(concepts['d001.txt'])
>>> #fltr.check(concepts['d002.txt'])
>>> #objs = fltr.apply(objs)
>>> #sorted(o.title for o in objs.values())
>>> #fltr.check(resources['d001.txt'])
>>> #fltr.check(resources['d002.txt'])
>>> r1 = qu.apply()
>>> r2 = fltr.apply(dict(zip(r1, getObjects(r1))))
>>> sorted(o.title for o in r2.values())
[u'Doc 001', u'Doc 003']
Organizing Queries and Filters with Query Instances

View file

@ -28,22 +28,31 @@ from zope.interface import implements
from cybertools.catalog.query import And
from loops.expert.interfaces import IFilter
from loops.expert.query import Children as ChildrenQuery
from loops import util
class Filter(object):
implements(IFilter)
query = None
def __init__(self, **kw):
self.kwargs = kw
def apply(self, objects, queryInstance=None):
qu = self.query()
#if qu is not None:
# return set(objects).intersection(qu.apply())
result = IOBTree()
for uid, obj in objects:
if self.check(obj, queryInstance):
for uid, obj in objects.items():
if self.check(uid, obj, queryInstance):
result[uid] = obj
return result
def check(self, uid, obj, queryInstance=None):
return uid in self.query().apply() #.keys()
class Children(Filter):

View file

@ -26,7 +26,7 @@ from zope.interface import Interface, Attribute
class IQuery(Interface):
""" A query or
""" A query.
"""
def apply():
@ -68,7 +68,7 @@ class IFilter(Interface):
intermediate results.
"""
def check(obj, queryInstance=None):
def check(uid, obj, queryInstance=None):
""" Return True if the object given should be included in the
filter's result set, False otherwise.