Welcome to the navigation

Ut officia sunt ad dolor veniam, ea est voluptate dolore duis amet, magna culpa incididunt nostrud ut aute sed adipisicing enim quis sit occaecat non. Officia ut non commodo irure magna ad tempor quis minim enim dolore laborum, occaecat ea eu excepteur cillum adipisicing in ipsum sed ut deserunt mollit

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