Hello,
In order to achieve this, you will need to use the
CustomDataHandler class and in particular, its
OnGetContent method. In general, the custom handler (CustomDataHandler, CustomTreeNodeHandler etc.) gives you ability to execute custom code when some CMS event occurs. The events of
CustomDataHandler are applied to all data items that are stored to the database and the
OnGetContent is a method used by smart search. It's called every time the document (or custom table, forum, user) is indexed.
The first parameter of the
OnGetContent method usually contains a TreeNode object and the second parameter contains text that gets indexed by Lucene.NET search engine used in Kentico
CMS smart search module (let's call it content). In this case, you will need get the Multiple choice field of the currently idexed document, parse it to get IDs of all fields, get appropriate records from Age Group based on IDs and add them to the content variable.
Let's assume that Age Group is a custom table and you use the following query to bind the Mupliple choice field:
SELECT ItemID, AgeGroup from customtable_AgeGroupFor this scenario, the
OnGetContent method could look like this one:
public override string OnGetContent(object obj, string content)
{
if (obj is TreeNode)
{
TreeNode node = obj as TreeNode;
if (node != null)
{
string field = ValidationHelper.GetString(node.GetValue(<Multiple choice field)>, String.Empty);
if ( !String.IsNullOrEmpty(field) )
{
CustomTableItemProvider customTableProvider = new CustomTableItemProvider(CMSContext.CurrentUser);
string customTableClassName = "customtable.agegroup";
string [] ids = field.Split('|');
foreach (string id in ids)
{
CustomTableItem item = customTableProvider.GetItem(ValidationHelper.GetInteger(id, 0), customTableClassName);
content = content + " " + CMS.GlobalHelper.ValidationHelper.GetString(item.GetValue("AgeGroup"), "");
}
}
}
}
return content;
}
Now, you should be able to search for documents using values form the AgeGroup table (toddler etc.).
If you want more information about the
CustomDataHandler class and how to add it to your project, please visit following links:
Event handling overviewData handlerIn terms of displaying correct values in transformation, you need to create a custom transformation method:
Adding custom functions to transformationsAnother example of using
OnGetContent which might help you understand what you need to do to make it work can be found in this knowledge base article:
How to search for documents using assigned categoryBest regards,
Michal Legen