From 257392dd28d55c2414d658be6add052647e6fe80 Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 12 Oct 2020 16:49:45 +1100 Subject: [PATCH] Non-published content indexed in ExternalIndex Fixes issue that the non-published content index populator is executing for the ExternalIndex --- src/Umbraco.Examine/ContentIndexPopulator.cs | 8 +++++++- src/Umbraco.Examine/IUmbracoContentIndex.cs | 14 ++++++++++++++ src/Umbraco.Examine/IndexPopulator.cs | 11 +++++++++-- src/Umbraco.Examine/UmbracoContentIndex.cs | 2 +- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Examine/ContentIndexPopulator.cs b/src/Umbraco.Examine/ContentIndexPopulator.cs index 99ff4d7f87..af30b56038 100644 --- a/src/Umbraco.Examine/ContentIndexPopulator.cs +++ b/src/Umbraco.Examine/ContentIndexPopulator.cs @@ -15,7 +15,7 @@ namespace Umbraco.Examine /// /// Performs the data lookups required to rebuild a content index /// - public class ContentIndexPopulator : IndexPopulator + public class ContentIndexPopulator : IndexPopulator { private readonly IContentService _contentService; private readonly IValueSetBuilder _contentValueSetBuilder; @@ -58,6 +58,12 @@ namespace Umbraco.Examine _parentId = parentId; } + public override bool IsRegistered(IUmbracoContentIndex2 index) + { + // check if it should populate based on published values + return _publishedValuesOnly == index.PublishedValuesOnly; + } + protected override void PopulateIndexes(IReadOnlyList indexes) { if (indexes.Count == 0) return; diff --git a/src/Umbraco.Examine/IUmbracoContentIndex.cs b/src/Umbraco.Examine/IUmbracoContentIndex.cs index 3181ff663e..b718ec6bce 100644 --- a/src/Umbraco.Examine/IUmbracoContentIndex.cs +++ b/src/Umbraco.Examine/IUmbracoContentIndex.cs @@ -2,6 +2,20 @@ using Examine; namespace Umbraco.Examine { + /// + /// Marker interface for indexes of Umbraco content + /// + /// + /// This is a backwards compat change, in next major version remove the need for this and just have a single interface + /// + public interface IUmbracoContentIndex2 : IUmbracoContentIndex + { + bool PublishedValuesOnly { get; } + } + + /// + /// Marker interface for indexes of Umbraco content + /// public interface IUmbracoContentIndex : IIndex { diff --git a/src/Umbraco.Examine/IndexPopulator.cs b/src/Umbraco.Examine/IndexPopulator.cs index f9d4d85dc8..bfd757f9be 100644 --- a/src/Umbraco.Examine/IndexPopulator.cs +++ b/src/Umbraco.Examine/IndexPopulator.cs @@ -13,9 +13,16 @@ namespace Umbraco.Examine { public override bool IsRegistered(IIndex index) { - if (base.IsRegistered(index)) return true; - return index is TIndex; + if (base.IsRegistered(index)) + return true; + + if (!(index is TIndex casted)) + return false; + + return IsRegistered(casted); } + + public virtual bool IsRegistered(TIndex index) => true; } public abstract class IndexPopulator : IIndexPopulator diff --git a/src/Umbraco.Examine/UmbracoContentIndex.cs b/src/Umbraco.Examine/UmbracoContentIndex.cs index 67e430b4e9..88033b1407 100644 --- a/src/Umbraco.Examine/UmbracoContentIndex.cs +++ b/src/Umbraco.Examine/UmbracoContentIndex.cs @@ -17,7 +17,7 @@ namespace Umbraco.Examine /// /// An indexer for Umbraco content and media /// - public class UmbracoContentIndex : UmbracoExamineIndex, IUmbracoContentIndex + public class UmbracoContentIndex : UmbracoExamineIndex, IUmbracoContentIndex2 { public const string VariesByCultureFieldName = SpecialFieldPrefix + "VariesByCulture"; protected ILocalizationService LanguageService { get; }