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:


SITECORE Multi-Sites with Shared Pages



Overview

SITECORE support having multiple website in a single instance, every site has it is own pages, content, etc...  And you can add shared content items between all sites as you can see in the below screenshot:



That’s awesome! But the challenge comes when you need to have shared pages between more than one sites. Don’t worry it is doable, but we need to do some coding here.



What to do?

I am supposing that you know how to configure multiple website in the normal scenario, if you don’t, please check out this document by Sitecore.

After configuring our sites we need to go through the below steps to have the shared pages working fine:

1)   We need to override “GetItemUrl” method to update the URLs for the items under shared content to be formed the same as the links under the site itself.

We need to be able to browse the pages under the shared folder without include “/Global/” in the URL, for example if we are on “site1” (suppose that the URL is http://site1) and we want to browse this page “/sitecore/content/Global/Products/Product1” then the URL should be this http://site1/Products/Product1 instead of http://site1/Global/Products/Product1 and if we are on “Site2” the URL should be this http://site2/Products/Product1





2)   After updating the URL, now we need to process the request and update Context.Item” value since we don’t have “Products” item under the sites, and this can be done by adding a new processor to resolve such kind of request.

To do that we need to add a new processor in the <httpRequestBegin> to be inherited from HttpRequestProcessor class. In this processor we need to update this property “Context.Item” with the matched item based on the current request.


So in our above example the request will be:

Request: http://site1/Products/Product1

Context item : Sitecore.Context.Database.GetItem( “/sitecore/content/Global/Products/Product1”)



       Don’t forget to add the link provider and the processer to the config using the below              patch:


3)   The last step is make sure that your sitemap.xml is working as expected any update any code login accordingly.