Welcome to the navigation

Dolore sit non dolor deserunt excepteur qui anim aute incididunt magna elit, ut eu mollit ut labore id aliquip ex proident, in culpa ea ullamco. Sed dolore qui incididunt consectetur dolore ut irure dolor id anim exercitation in voluptate non ad sit quis amet, nostrud labore velit ut deserunt minim

Yeah, this will be replaced... But please enjoy the search!

Index only linked documents using Episerver Find

I needed a simple way to ensure not documents that weren't in use was indexed by Episerver Find. The basics of the routine is if a document has one or more content references it should be indexed, otherwise not.

There is a method in the IContentRepository called GetReferencesToContent that "Gets the reference information of the references to the specified content and optionally its descendants.". There may be alternative ways to achieve this, i.e. using the ContentSoftLinkRepository, that have however really worked for me. Henrik Lindström wrote an article about that approach a while ago.

In this example I use MediaData but it could actually be used for any IContent

ContentIndexer.Instance.Conventions.ForInstancesOf<MediaData>().ShouldIndex(x =>
{
    try
    {
        if (x.ContentLink == null)
        {
            return false;
        }

        var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();

// this will accept links to both blocks and pages var references = contentRepository.GetReferencesToContent(x.ContentLink, false); if (references.Any()) { return true; } } catch (Exception ex) { //ILogger.Error(ex.Message, ex); } return false; });

 

x