Public feed
#724496
from axiom import store, attributes, item
class A(item.Item):
ref = attributes.reference()
key = attributes.text()
value = attributes.text()
class I(item.Item):
someInfo = attributes.text(allowNone=True)
def search(store, boolFunction, *path):
c = None
for key, value in path:
newC = attributes.AND(A.key==key,
A.value==value,
A.ref==I.storeID)
if c is None:
c = newC
else:
c = boolFunction(newC, c)
return store.query(I, c)
s = store.Store()
# add items
i1 = I(store=s, someInfo=u'i1')
i2 = I(store=s, someInfo=u'i2')
# add attrbutes
A(store=s, ref=i1, key=u'title', value=u'hello')
A(store=s, ref=i1, key=u'subtitle', value=u'world')
A(store=s, ref=i2, key=u'title', value=u'hello')
A(store=s, ref=i2, key=u'subtitle', value=u'sky')
# search for 'hello'
print "search for hello"
for result in search(s, attributes.AND, (u'title', u'hello')):
print repr(result)
print "search for hello, world"
# search for 'hello', 'world'
for result in search(s, attributes.AND, (u'title', u'hello'), (u'subtitle', u'world')):
print repr(result)