Skip to content

Instantly share code, notes, and snippets.

@dcouto
Last active November 1, 2018 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcouto/00d78af1ea5befc361b8cfc614f2d585 to your computer and use it in GitHub Desktop.
Save dcouto/00d78af1ea5befc361b8cfc614f2d585 to your computer and use it in GitHub Desktop.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<coveoInboundFilterPipeline>
<processor type="MySolution.Coveo.Custom.InboundFilters.IsPublishableInboundFilter, MySolution.Coveo.Custom" />
</coveoInboundFilterPipeline>
</pipelines>
</sitecore>
</configuration>
using Coveo.Framework.Items;
using Coveo.SearchProvider.InboundFilters;
using Coveo.SearchProvider.Pipelines;
namespace MySolution.Coveo.Custom.InboundFilters
{
public class IsPublishableInboundFilter : AbstractCoveoInboundFilterProcessor
{
public override void Process(CoveoInboundFilterPipelineArgs args)
{
if (args.IndexableToIndex != null && !args.IsExcluded && ShouldExecute(args))
{
var item = args.IndexableToIndex.Item;
if (item.Publishing.NeverPublish)
{
args.IsExcluded = true;
return;
}
args.IsExcluded = !AllAncestorsArePublishable(item);
}
}
private bool AllAncestorsArePublishable(IItem item)
{
if (item.Parent != null && item.Parent.Publishing.NeverPublish)
{
return false;
}
else if (item.Parent != null)
{
return AllAncestorsArePublishable(item.Parent);
}
return true;
}
}
}
@dcouto
Copy link
Author

dcouto commented Nov 1, 2018

Updated based on feedback from @jflheureux from Coveo. Thank you, Jeff!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment