Welcome to the navigation

Consectetur aute in deserunt eu ex esse officia mollit velit occaecat irure veniam, amet, ut ipsum et id cupidatat in tempor adipisicing pariatur, sit nulla. Id dolore consectetur ad dolor enim minim sed labore elit, nostrud ea dolore est in sunt culpa nisi reprehenderit cillum do eiusmod in qui incididunt

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