[Grok-dev] catalog indexes in Grok

Martijn Faassen faassen at startifact.com
Tue Apr 17 17:54:58 EDT 2007


Hi there,

I've been doing some work on the faassen-index branch to make it easier 
to declare catalog indexes in Grok. I'd like to ask people to play with 
this branch for a bit and give me some feedback.

The design is based on one that Philipp came up with during a discussion 
on this earlier. Here is an example:

class Herd(grok.Container, grok.Application):
     pass

class IMammoth(Interface):
     name = schema.TextLine(title=u'Name')
     age = schema.Int(title=u'Age')
     def message():
         """Message the mammoth has for the world."""

class MammothIndexes(grok.Indexes):
     grok.application(Herd)
     grok.context(IMammoth)

     name = index.Field()
     age = index.Field()
     message = index.Text()

The new bit is MammothIndexes. This says that:

* for all instances of the application Herd (grok.application)

* index all objects that provide IMammoth

* create an Field index for the name attribute

* another Field index for the age attribute

* and finally a Text index for the message method

After doing this and creating the Herd application, there will be a 
catalog available that has the correct indexes. That's all you need to 
do. You don't need to worry about setting up intids or a catalog 
yourself; that's all done for you automatically.

The grok.application directive is compulsory. You *have* to point it to 
an application, or to an interface implemented by an application. I 
don't know how to make up a sensible default for this yet. Installing 
the indexes automatically in all Grok-based applications seems 
excessive, so that one is out. Ideas?

Another directive you may choose to use is grok.name. This sets the name 
for the catalog. If you don't use it, an unnamed catalog is used.

You can use grok.context and point to a class instead of to an 
interface. This works, but currently means indexes are created that 
index *everything* (like in Zope 2). Indexing not restricted to that 
class. This is because zope.app.catalog.attribute, to my knowledge, 
currently doesn't have that facility. Anyway, if you don't use it, just 
use a schema and make sure the objects you want to index provide that 
schema or adapt to that schema.

Please tell us what you think!

Regards,

Martijn



More information about the Grok-dev mailing list