Hi Torkel,

On 18 June 2010 02:12, Torkel Lyng <[email protected]> wrote:
> I've created a dexterity content type and have added some indexes for it.
>
> class IMyContentType(form.Schema):
>
>      field ...
>
>      anotherfield ...
>
>
> @indexer(IMyContentType)
> def fieldIndexer(obj):
>       return obj.field
> grok.global_adapter(fieldIndexer, "field")
>
> @indexer(IMyContentType)
> def anotherfieldIndexer(obj):
>      return obj.anotherfield
> grok.global_adapter(anotherfieldIndexer, "anotherfield")
>
> I've registered the catalog indexes using genericsetup catalog.xml:
>
>   <index name="field" meta_type="KeywordIndex">
>     <index_attr value="field" />
>   </index>
>   <column value="field" />
>
>   <index name="anotherfield" meta_type="KeywordIndex">
>     <index_attr value="anotherfield" />
>   </index>
>   <column value="anotherfield" />

You're sure you need both indexes and metadata columns?

> Everything works like a charm this far, but I've also added a behavior to
> the content type which I also want to register fields for. I followed
> optiludes plone.behavior tutorial
> and came up with something very similar to his localrole behavior. This time
> I've tried using a multiadapter to index the fields:
>
> class MyIndexer(grok.MultiAdapter):
>          grok.implements(IIndexer)
>          grok.adapts(IMyMarkerInterface, IZCatalog)
>          grok.name("thethirdfield")
>
>          def __init__(self, context, catalog):
>                self.context = context
>                self.catalog = catalog
>                self.data = IMyBehaviorInterface(context)
>
>         def __call__(self):
>               return self.data.thethirdfield or ()
>
> The catalog.xml settings for the third field is exactly the same as field
> and anotherfield, but this time data is not registered in the indexes,
> allthough it's registered correctly in the
> metadata fields. What should I do to correctly index thethirdfield?

This is what pdb is for. ;-)

Put one in __init__ and one in __call__ and see if they're called at
all, and what happens.

One thought is that if the self.data = IMyBehaviorInterface(context)
fails, it'll raise a TypeError, which will become a "could not adapt"
in plone.indexer, which will then ignore that indexer.

Martin
_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers

Reply via email to