Any good guides and/or advice for indexing my objects in zodb?
Asked Answered
C

2

6

I'm going to be writing a general object class for use with zodb. These objects will add themselves to a btree index once they are persisted to the zodb object graph.

I've never really worked with any of this before, but would anyone have any resources and/or advice on doing this?

With zodb's power when dealing with object references and a good indexing strategy, I could end up getting the best of both database worlds.

Any other thoughts are more than welcome, thanks!

Courtesan answered 21/4, 2010 at 17:36 Comment(1)
One possible answer would be zcatalog or a standalone equivalent of it. That said, I'm not familiar enough with zope in general to understand if I'd be forced into adopting some of it's own approaches. If anyone has guidance on this, please submit an answer!Courtesan
N
2

Have a look at repoze.catalog:

repoze.catalog is a Python indexing and searching framework. It relies on zope.index and most of its internals are taken from zope.app.catalog. Unlike zope.app.catalog, however, it is meant to be useful outside of the larger Zope framework within arbitrary Python applications.

Novelia answered 22/4, 2010 at 8:5 Comment(1)
I can't seem to find any comprehensive tutorials for zope.index? It's homepage is apparently the pypi page, rather than a zope one... Hmmm...Courtesan
L
0

Depends on your indexing needs, but when all that you need is accessibility by an id, you probably don't need any fancy indexing package.

These objects will add themselves to a btree index once they are persisted to the zodb object graph.

Well, "add themselves" would imply, that they hold a reference to their BTree / index solution. On the other side you're talking about "once they are persited", which implies some kind of "put them into the DB"-function. So I suggest, just do the persisting and indexing of the objects in one go with something like that:

def persist_obj(db, obj):
    tree = db.root()['mybtree']
    id = tree.maxKey() + 1
    obj.id = id
    tree[id] = obj

If you have a wrapper for your database, putting this in a member function of wour wrapper would be the natural location for that.

Lelialelith answered 28/9, 2012 at 11:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.