Try our conversational search powered by Generative AI!

Unified Search - Filter file used on child pages


I'm trying to add a filter for files of type GenericMedia to my unified search that matches the following criterias:

- The file is added to a page in a LinkItemCollection (or a contentarea if that is easier)

- The page the file is added to is child of another specified page (I'm passing the pagedata object of the parent as an argument to the search method)


I'm drawing a blank as how to implement this. Anybody else have an idea?

Jan 02, 2014 15:11

You could do something like this:

First, create an extension method to fetch the desired information:

        public static IEnumerable<int> ReferencedOnChildOfPages<T>(this T content)
            var file = content as IContent;
            if (file != null)
                var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
                var references = contentRepository.GetReferencesToContent(file.ContentLink, false);
                foreach (var referenceInformation in references)
                    PageData page = null;
                    contentRepository.TryGet(referenceInformation.OwnerID, out page);
                    if (page != null)
                        yield return page.ParentLink.ID;



Then, include the data in the index in an initializable module:

            SearchClient.Instance.Conventions.ForInstancesOf<GenericMedia>().IncludeField(x => x.ReferencedOnChildOfPages());


Reindex, and you should then be able to filter your query like this:

.Filter(x => x.ReferencedOnChildOfPages().Match(somePage.ContentLink.ID))


Jan 03, 2014 10:07

Thanks man. That worked like a charm.

But if ReferenceChildOfPages is stored on the file in the index, do I need to reindex everytime I reference a file on a page for it to be searchable? I know the index of the page it self is updated when I hit Publish, but that won't update the index of the file will it?

Jan 03, 2014 17:15

Yeah, you will need to reindex. You could listen to the PublishedContent event, and then check the page for file references. If it does, reindex those references files.

Jan 06, 2014 8:13


In addition I had to get references to files from previous versions of the page and reindex those to handle when a file is removed from the linkitemcollection.

Jan 06, 2014 12:07

Great :-)

Jan 06, 2014 14:18
Dec 03, 2014 8:52
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.