Welcome to the navigation

Commodo nulla dolore nostrud excepteur non ut laboris anim ex et dolor magna id in amet, est tempor aute ut pariatur, dolore consequat, irure adipisicing. Consequat, exercitation est ipsum adipisicing commodo elit, veniam, sint officia irure do nostrud enim aliqua, magna eiusmod nulla ut dolore ex in duis minim id

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

Please note that this portal is a BETA site , I will continuously improve all functionality and performance during the coming weeks / the author