Hello, I'm trying to search for MediaData that only exists on published pages. The pages can have many different kind of block areas with MediaData inside them. The requirement is that the MediaData itself does not have to be unpublished, only its parent page where it exists. My search query looks as follows
var FileQuery = SearchClient.Instance.Search()
.WildCardQuery(wildtext, x => x.Name)
This gives me hits from all assets folders.
Then I'm trying to see if the link have soft link, if that is the case get OwnerContentLink.
var contentResultFileHits = FileQuery.GetContentResult();
var repository = ServiceLocator.Current.GetInstance();
var linkRepository = ServiceLocator.Current.GetInstance();
var fileHits = contentResultFileHits
.Select(x => x)
.Where(x => linkRepository.Load(x.ContentLink, true)
.Where(link => link.SoftLinkType == ReferenceType.PageLinkReference && !ContentReference.IsNullOrEmpty(link.OwnerContentLink))
.Select(link => link.OwnerContentLink)
.Any(o => CheckPublished(repository, o)));
After that, check if the ContentReference is PageData, if so check start publish date, stop publish date and deleted. Otherwise call method again with parent link.
private static bool CheckPublished(IContentLoader repository, ContentReference o)
var content = repository.Get(o);
var bb = (((PageData)content).StopPublish == null || ((PageData)content).StopPublish > DateTime.Now && ((PageData)content).StartPublish < DateTime.Now) && !content.IsDeleted;
return CheckPublished(repository, content.ParentLink);
This doesn't seem to work very well on blocks as the parent link for the block container doesn't reference the page. How can I improve my search query to get required result?