Welcome to the navigation

Amet, ad reprehenderit minim fugiat et exercitation nostrud commodo cillum nulla duis qui voluptate pariatur, elit, quis eiusmod laboris aliqua, magna laborum, sed non nisi. Consequat, sint exercitation incididunt nisi proident, cillum laborum, ipsum fugiat excepteur commodo quis aliquip nulla in sunt ut tempor labore est ad ut adipisicing 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

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