November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
I don't think you'll be able to use _contentRepository.GetReferencesToContent as part of a search request filter.
Filters that are going to be executed by S&N need to be able to be converted in to search queries for elastic and there's no indexed data for usages of a block in S&N.
The easiest thing to do is to return all your blocks fist then using the _contentRepository.GetReferencesToContent() on the result block values so that it's executed agains the content repo but be aware that's a direct database call and can be expensive so it depends where you're using this.
Have a look at this blog post: https://www.codeart.dk/blog/2020/1/powerslice-identify-unused-blocks/
I am attempting to Get a list of blocks that not being used.
[ServiceConfiguration(typeof(IContentQuery)), ServiceConfiguration(typeof(IContentSlice))]
public class MyNewSlice : ContentSliceBase<SitePageData>
{
private readonly IContentRepository _contentRepository;
public MyNewSlice(IClient searchClient, IContentTypeRepository contentTypeRepository, IContentLoader contentLoader, IContentRepository contentRepository) : base(searchClient, contentTypeRepository, contentLoader)
{
_contentRepository = contentRepository;
}
public override string Name => "My New Slice";
protected override ITypeSearch<SitePageData> Filter(ITypeSearch<SitePageData> searchRequest, ContentQueryParameters parameters)
{
return searchRequest.Filter(x => x.MatchTypeHierarchy(typeof(BlockData)) & _contentRepository.GetReferencesToContent(x.ContentLink, false).Any().Match(false));
}
public override int SortOrder => 505;
}