Custom Renderer – Index Keyword Key in SmartTarget

keywords in SmartTargetI found out how to use a new CM-side extension point today; Renderers. I had been struggling for a while with the fact that SmartTarget does not index the Keyword key – which was precisely what I wanted to set up some promotion content selection filters on. It turns out to be quite easy, and indeed gives a generic method for messing with the content that SmartTarget indexes without having to fiddle about on the Delivery side with Java or Kettle.

SmartTarget uses its own custom Renderer; you will see it configured in your Tridion.ContentManager.config file on your publisher server(s):

     <add type="Tridion.SmartTarget.Publishing.Rendering.SmartTargetRenderer" assembly="Tridion.SmartTarget.Publishing, Version=, Culture=neutral, PublicKeyToken=ddfc895746e5ee6b" />

This generates some metadata on items being published (Pages and Component Presentations) in the form of XML elements which can be accessed via the RenderedItem.Metadata property. For Component Presentations, this metadata contains the XML source of the component, and each field is individually indexed by SmartTarget and thus available to use for filtering. For Keywords the component XML source just contains the keyword Title (exactly as you see it in the source XML view in the Tridion CM GUI). There is an additional Keyword element added to the metadata, so SmartTarget does something more when indexing keywords, however this does not contain the keyword Key.

To make this clearer, here is an example of the resulting component_presentations.xml from the transport package (you can easily find these by setting the Cleanup attribute of the Queue/Location element in cd_deployer_conf.xml to false). Notice the Keyword element and corresponding segment field value.

The solution was simple; have an additional custom Renderer execute after the SmartTarget one. This will look for the Keyword elements added by SmartTarget in the metadata and then cross reference this with the Component XML source, adding in additional ‘fake’ field values containing the keyword key. So if your components have a segment keyword field, we add in a segment_key field value containing the key. We can then see and activate this field in the Fredhopper Business Manager, and use it as part of our content selection filters. Heres the updated component_presentation.xml:

Here’s the code, hopefully it speaks for itself. You will need to sign your compiled assembly to give it a strong name, add it to the GAC on your Publisher CM servers, and configure it in the renderers section of Tridion.ContentManager.config:

Its not a 100% foolproof solution (as mentioned in the code comments) – it would be nicer to ‘find’ the keyword fields based on schema definition – but I think that would be a lot of code – let me know if you have ideas for that.

Thanks to Peter Kjaer, Jan Horsman and Albert Romkes for getting me to the solution.

This isn’t quite the end of the story – there’s more to come on the topic of working with SmartTarget and Keywords shortly…

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>