Wow! Really nice man. I&#39;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">&lt;<a href="mailto:ruslan.spivak@gmail.com">ruslan.spivak@gmail.com</a>&gt;</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 &lt;<a href="mailto:vanderson.mota@gmail.com">vanderson.mota@gmail.com</a>&gt; writes:<br>
<br>
</div><div><div></div><div class="h5">&gt; Hi,<br>
&gt;<br>
&gt; I&#39;m developing with some friends a &quot;real world&quot; grok application, and by<br>
&gt; now, i&#39;ve used the hurry.query, according with the site documentation.<br>
&gt;<br>
&gt; I would like to know if is there any implementation of catalog like plone&#39;s<br>
&gt; portal_catalog, because i don&#39;t want to create a new grok.Indexes class just<br>
&gt; to index some attribute in a diferent model/context.<br>
&gt;<br>
&gt; If such thing doesn&#39;t exists, can someone give an opnion about building it<br>
&gt; or if is there a better option instead of making a centralized catalog<br>
&gt; utility?<br>
&gt;<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>
    &quot;&quot;&quot;Custom indexes to populate catalog&quot;&quot;&quot;<br>
<br>
    # index_name, index_class,<br>
    # attr_name, attr_interface, attr_is_callable<br>
    indexes = (<br>
        (&#39;title&#39;, TextIndex,<br>
         &#39;title&#39;, None, False),<br>
<br>
        (&#39;created&#39;, FieldIndex,<br>
         &#39;created&#39;, IZopeDublinCore, False),<br>
<br>
        (&#39;searchable&#39;, TextIndex,<br>
         &#39;getSearchableText&#39;, 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&#39;s IndexesSetupSubscriber<br>
class CustomIndexesSetupSubscriber(IndexesSetupSubscriber):<br>
<br>
    def __init__(self):<br>
        &quot;&quot;&quot;Override base class constructor.&quot;&quot;&quot;<br>
        self.catalog_name = u&#39;&#39;<br>
<br>
    def __call__(self, site, event):<br>
        &quot;&quot;&quot;Override base class&#39;s __call__&quot;&quot;&quot;<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&#39;s IObjectAddedEvent<br>
<br>
2) use Grok&#39;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&#39;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>