Wow! Really nice man. I'll implement it here and return the results.<br>
<br>
thanks a lot!<br><br><br><br><div class="gmail_quote">2009/3/25 Ruslan Spivak <span dir="ltr"><<a href="mailto:ruslan.spivak@gmail.com">ruslan.spivak@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">Vanderson Mota dos Santos <<a href="mailto:vanderson.mota@gmail.com">vanderson.mota@gmail.com</a>> writes:<br>
<br>
</div><div><div></div><div class="h5">> Hi,<br>
><br>
> I'm developing with some friends a "real world" grok application, and by<br>
> now, i've used the hurry.query, according with the site documentation.<br>
><br>
> I would like to know if is there any implementation of catalog like plone's<br>
> portal_catalog, because i don't want to create a new grok.Indexes class just<br>
> to index some attribute in a diferent model/context.<br>
><br>
> If such thing doesn't exists, can someone give an opnion about building it<br>
> or if is there a better option instead of making a centralized catalog<br>
> utility?<br>
><br>
<br>
</div></div>I whipped out some code that you can use a basis for registering indexes<br>
<div><div></div><div class="h5">in one place:<br>
<br>
import grok<br>
<br>
from grok.meta import IndexesSetupSubscriber<br>
from zope.app.catalog.field import FieldIndex<br>
from zope.app.catalog.text import TextIndex<br>
from zc.catalog.catalogindex import SetIndex<br>
<br>
# Your interfaces<br>
from zope.dublincore.interfaces import IZopeDublinCore<br>
from zope.index.text.interfaces import ISearchableText<br>
<br>
def setup_indexes(catalog):<br>
"""Custom indexes to populate catalog"""<br>
<br>
# index_name, index_class,<br>
# attr_name, attr_interface, attr_is_callable<br>
indexes = (<br>
('title', TextIndex,<br>
'title', None, False),<br>
<br>
('created', FieldIndex,<br>
'created', IZopeDublinCore, False),<br>
<br>
('searchable', TextIndex,<br>
'getSearchableText', ISearchableText, True),<br>
)<br>
<br>
for (index_name, index_class,<br>
name, iface, callable) in indexes:<br>
<br>
catalog[index_name] = index_class(<br>
field_name=name,<br>
interface=iface,<br>
field_callable=callable<br>
)<br>
<br>
# Hack Grok's IndexesSetupSubscriber<br>
class CustomIndexesSetupSubscriber(IndexesSetupSubscriber):<br>
<br>
def __init__(self):<br>
"""Override base class constructor."""<br>
self.catalog_name = u''<br>
<br>
def __call__(self, site, event):<br>
"""Override base class's __call__"""<br>
self._createIntIds(site)<br>
catalog = self._createCatalog(site)<br>
<br>
setup_indexes(catalog)<br>
<br>
<br>
</div></div># Your application class<br>
<div class="im">class Sample(grok.Application, grok.Container):<br>
pass<br>
<br>
@grok.subscribe(Sample, grok.IObjectAddedEvent)<br>
def registerCatalogIndexes(app, event):<br>
subscriber = CustomIndexesSetupSubscriber()<br>
# call it to set up catalog and indexes<br>
subscriber(app, event)<br>
<br>
<br>
</div>Main steps:<br>
1) subscriber handler for your site's IObjectAddedEvent<br>
<br>
2) use Grok's IndexesSetupSubscriber with overridden<br>
__init__ and __call__ and hook your index creation<br>
routine (as done above).<br>
<br>
3) add indexes to catalog without using Grok's Indexes<br>
<div class="im"> machinery<br>
<br>
For more information about indexes and catalog check out:<br>
<br>
<a href="http://svn.zope.org/zope.catalog/trunk/src/zope/catalog/" target="_blank">http://svn.zope.org/zope.catalog/trunk/src/zope/catalog/</a><br>
</div><a href="http://svn.zope.org/zope.index/trunk/src/zope/index/" target="_blank">http://svn.zope.org/zope.index/trunk/src/zope/index/</a><br>
<div class="im"><a href="http://svn.zope.org/zc.catalog/trunk/src/zc/catalog/" target="_blank">http://svn.zope.org/zc.catalog/trunk/src/zc/catalog/</a><br>
<br>
</div><div><div></div><div class="h5">Hope it helps you to move further.<br>
<br>
Cheers,<br>
Ruslan<br>
--<br>
<br>
<a href="http://ruslanspivak.com" target="_blank">http://ruslanspivak.com</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Vanderson Mota dos Santos<br><br>