[Grok-dev] declaring catalog indexes

Martijn Faassen faassen at startifact.com
Sat Apr 14 12:38:40 EDT 2007

Hi there,

The current way to set up catalog indexes in Grok looks like this:

def setup_catalog(catalog):
    catalog['a_index'] = FieldIndex('a_attribute',
    catalog['b_index'] = TextIndex('b_attribute', 


class App(grok.Application):
    grok.local_utility(IntIds, provides=IIntIds)
       provides=ICatalog, name='my_catalog', setup=setup_catalog)

This will index everything providing ISomeInterface. We can also set up 
an adapter from our own objects to ISomeInterface and this will result 
in those objects being indexed as well.

This approach is pretty powerful. If I have an extension object that 
wants to be indexed, I merely have to implement the right interface on 
my object, or provide some adapter from my object to that interface.

The main drawback to this approach is that all indexes are set up 
centrally. Of course you can write code to adjust the catalog later (and 
have no setup_catalog), but are there patterns we can come up with to 
make the creation of indexes more easy?

Let's translate the above in another proposal:

class App(grok.Application):
     grok.local_utility(IntIds, provides=IIntIds)
     grok.local_utility(Catalog, provides=ICatalog, name='my_catalog')

class AIndex(grok.FieldIndex):
    grok.catalog(App, 'my_catalog')
    grok.attribute('a_attribute', ISomeInterface)

class BIndex(grok.TextIndex):
    grok.catalog(App, 'my_catalog')
    grok.attribute('b_attribute', ISomeInterface)

The indexes are grokked automatically and get created in the catalog 
when 'App' is created using a subscriber. This allows an extension 
modules to create new indexes in the core. Of course the app would still 
need to be reinstalled to enable those indexes, but with some clever 
event registration (IApplicationSetup event?) we might be able to handle 
that quite nicely as well.

One issue that this approach has is if indexes take other parameters 
than the three I know about (attribute name, interface, boolean on 
whether to call attribute or not). How do we pass them in? Does anyone 
have experience with indexes that can use extra information?

What do people think?



More information about the Grok-dev mailing list