Sitecore Box

Sitecore web developer at Americaneagle.com

Triggering an Index Update for the Linked Items in SITECORE






Overview

In some scenarios you may need to include child items into the search document of the parent item. In such cases, if any of the child items is changed (edited\removed) we will have to maintain "relationship" to the linked item (parent item) in the index manually, and this require some coding.

Example

Let’s say we have a computed field attached to the home page, this computed field should contain the value for the “Title” field on “Child Item” and we need that the computed field to be updated once we edit\remove the child item by refreshing the index.





Solutions

Here we have two methods to refresh the index:

1.    indexing.getDependencies Pipeline


This pipeline is designed to address issues when a search document is built from the data coming from more than one item. Each custom processor must implement Sitecore.ContentSearch.Pipelines.GetDependencies BaseProcessor
Below is a sample code how we can implement this:



We need to add the below patch:



2.    Marking the linked item as changed

To mark a linked item as changed, we need just to save it via API (e.g. via custom “item:deleted” handler, that will fire on each delete of the child item). This action will force changing value in the system Revision field, which means that all publishing types will treat this "item change" as the "one that needs to be published". When the parent item is published, it will be handled by the default indexing mechanism, so no further coding is required.

Below is a sample code how we can implement this:


We need to add the below patch:


The same mechanism can be applied on the “item:saved” handler to handle updating the item fields.

References:


0 comments:

Post a Comment