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:
parent
75efbfb38a
commit
a7351c0cff
3 changed files with 19 additions and 8 deletions
|
@ -187,10 +187,12 @@ concepts) that are direct or indirect children of jim.
|
||||||
>>> sorted(o.title for o in getObjects((qu & fltr.query()).apply()))
|
>>> sorted(o.title for o in getObjects((qu & fltr.query()).apply()))
|
||||||
[u'Doc 001', u'Doc 003']
|
[u'Doc 001', u'Doc 003']
|
||||||
|
|
||||||
>>> #fltr.check(concepts['d001.txt'])
|
>>> #fltr.check(resources['d001.txt'])
|
||||||
>>> #fltr.check(concepts['d002.txt'])
|
>>> #fltr.check(resources['d002.txt'])
|
||||||
>>> #objs = fltr.apply(objs)
|
>>> r1 = qu.apply()
|
||||||
>>> #sorted(o.title for o in objs.values())
|
>>> 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
|
Organizing Queries and Filters with Query Instances
|
||||||
|
|
|
@ -28,22 +28,31 @@ from zope.interface import implements
|
||||||
from cybertools.catalog.query import And
|
from cybertools.catalog.query import And
|
||||||
from loops.expert.interfaces import IFilter
|
from loops.expert.interfaces import IFilter
|
||||||
from loops.expert.query import Children as ChildrenQuery
|
from loops.expert.query import Children as ChildrenQuery
|
||||||
|
from loops import util
|
||||||
|
|
||||||
|
|
||||||
class Filter(object):
|
class Filter(object):
|
||||||
|
|
||||||
implements(IFilter)
|
implements(IFilter)
|
||||||
|
|
||||||
|
query = None
|
||||||
|
|
||||||
def __init__(self, **kw):
|
def __init__(self, **kw):
|
||||||
self.kwargs = kw
|
self.kwargs = kw
|
||||||
|
|
||||||
def apply(self, objects, queryInstance=None):
|
def apply(self, objects, queryInstance=None):
|
||||||
|
qu = self.query()
|
||||||
|
#if qu is not None:
|
||||||
|
# return set(objects).intersection(qu.apply())
|
||||||
result = IOBTree()
|
result = IOBTree()
|
||||||
for uid, obj in objects:
|
for uid, obj in objects.items():
|
||||||
if self.check(obj, queryInstance):
|
if self.check(uid, obj, queryInstance):
|
||||||
result[uid] = obj
|
result[uid] = obj
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def check(self, uid, obj, queryInstance=None):
|
||||||
|
return uid in self.query().apply() #.keys()
|
||||||
|
|
||||||
|
|
||||||
class Children(Filter):
|
class Children(Filter):
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ from zope.interface import Interface, Attribute
|
||||||
|
|
||||||
|
|
||||||
class IQuery(Interface):
|
class IQuery(Interface):
|
||||||
""" A query or
|
""" A query.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def apply():
|
def apply():
|
||||||
|
@ -68,7 +68,7 @@ class IFilter(Interface):
|
||||||
intermediate results.
|
intermediate results.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def check(obj, queryInstance=None):
|
def check(uid, obj, queryInstance=None):
|
||||||
""" Return True if the object given should be included in the
|
""" Return True if the object given should be included in the
|
||||||
filter's result set, False otherwise.
|
filter's result set, False otherwise.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue