Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Search using inherited fields View modes: 
User avatar
Member
Member
robert-tailor.co - 8/21/2012 5:29:58 PM
   
Search using inherited fields
I have a document type that inherits fields from another document.

I only want content editors to have to enter text in the child document if it differs from the parent document. i.e. Child documents will use the parent documents values unless they have been overridden with values in the child document.

Is it possible to edit the search so that when it indexes a certain document type, it should look at the parent document type for values if certain columns are left blank?

Thanks for any advice you can offer.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 8/22/2012 2:18:07 AM
   
RE:Search using inherited fields
Hi,

I am afraid but this is not possible - the document type is inheriting just the form definition, not the values. This would require pretty complex customization of the search.

Best regards,
Juraj Ondrus

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 8/24/2012 12:27:52 PM
   
RE:Search using inherited fields
This is not impossible. Sorry Juraj.

You can modify the content that is stored in the smart search index by subscribing to the GetContent document event in a ClassLoaderModule.

Here is an example:


//This code can be put in the file /App_Code/Samples/Modules/SampleClassLoaderModule.cs


/// <summary>
/// Initializes the module
/// </summary>
public override void Init()
{
// -- This line provides the ability to register the classes via web.config cms.extensibility section from App_Code
ClassHelper.OnGetCustomClass += ClassHelper_OnGetCustomClass;
DocumentEvents.GetContent.Execute += new EventHandler<DocumentEventArgs>(GetContent_Execute);
}

void GetContent_Execute(object sender, DocumentEventArgs e)
{
if (e.Node.NodeClassName.ToLower() == "custom.yourclassname")
{
if (ValidationHelper.GetString(e.Node["YourColumnName"], null) == null)
{
var parent = e.Node.Parent;
if (parent != null && parent.NodeClassName == "custom.yourclassname")
{
e.Content += ValidationHelper.GetString(parent["YourColumnName"], String.Empty);
}
}
}
}



You can also use this method to add categories or any other content that you can't set in the document search settings.

The only drawback is that you won't see that content in the search results unless you create a macro or method to use in your transformation that outputs the parent content if its own content is empty.

Just a side note: This doesn't actually modify the content at all, it just modifies what the Lucene.NET smart search indexer stores in the index and associates with the respective content nodes.

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 8/24/2012 12:30:05 PM
   
RE:Search using inherited fields
One more note: This block of code only runs when your search index is built. So don't forget to rebuild your index after you apply this code to your application or else it will appear as though it is not working.

User avatar
Member
Member
robert-tailor.co - 8/26/2012 3:26:26 PM
   
RE:Search using inherited fields
Awesome - thanks Jiveabillion!

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 8/31/2012 2:43:36 PM
   
RE:Search using inherited fields
Hi,

Thank you for sharing the ideas here. Modifying the indexed data through the OnGetContent event is interesting stuff, although it has the mentioned limitations.

There are plans to add some support or even interface for this kind of Smart Search customizations in the future versions, so please stay tuned :)

Regards,
Zdenek