diff --git a/src/Umbraco.Examine.Lucene/DeliveryApiContentIndex.cs b/src/Umbraco.Examine.Lucene/DeliveryApiContentIndex.cs index c572fc85f7..3195a6df7c 100644 --- a/src/Umbraco.Examine.Lucene/DeliveryApiContentIndex.cs +++ b/src/Umbraco.Examine.Lucene/DeliveryApiContentIndex.cs @@ -17,6 +17,9 @@ public class DeliveryApiContentIndex : UmbracoExamineIndex private readonly IDeliveryApiCompositeIdHandler _deliveryApiCompositeIdHandler; private readonly ILogger _logger; + // The special path and icon value transformations are not needed in this case + protected override bool ApplySpecialValueTransformations => false; + [Obsolete("Use the constructor that takes an IDeliveryApiCompositeIdHandler instead, scheduled for removal in v15")] public DeliveryApiContentIndex( ILoggerFactory loggerFactory, @@ -134,10 +137,4 @@ public class DeliveryApiContentIndex : UmbracoExamineIndex return (compositeIdModel.Id?.ToString(CultureInfo.InvariantCulture), compositeIdModel.Culture); } - - protected override void OnTransformingIndexValues(IndexingItemEventArgs e) - { - // UmbracoExamineIndex (base class down the hierarchy) performs some magic transformations here for paths and icons; - // we don't want that for the Delivery API, so we'll have to override this method and simply do nothing. - } } diff --git a/src/Umbraco.Examine.Lucene/UmbracoExamineIndex.cs b/src/Umbraco.Examine.Lucene/UmbracoExamineIndex.cs index 5faccf581f..bfec67f5d1 100644 --- a/src/Umbraco.Examine.Lucene/UmbracoExamineIndex.cs +++ b/src/Umbraco.Examine.Lucene/UmbracoExamineIndex.cs @@ -38,8 +38,14 @@ public abstract class UmbracoExamineIndex : LuceneIndex, IUmbracoIndex, IIndexDi } public Attempt IsHealthy() => _diagnostics.IsHealthy(); + public virtual IReadOnlyDictionary Metadata => _diagnostics.Metadata; + /// + /// Performs special __Path and __Icon value transformations to all deriving indexes when set to true. + /// + protected virtual bool ApplySpecialValueTransformations => true; + /// /// When set to true Umbraco will keep the index in sync with Umbraco data automatically /// @@ -115,16 +121,27 @@ public abstract class UmbracoExamineIndex : LuceneIndex, IUmbracoIndex, IIndexDi { base.OnTransformingIndexValues(e); + if (ApplySpecialValueTransformations) + { + ApplySpecialIndexValueTransformations(e); + } + } + + /// + /// Updates the index ValueSet with a special __Path and __Icon fields. + /// + private void ApplySpecialIndexValueTransformations(IndexingItemEventArgs e) + { var updatedValues = e.ValueSet.Values.ToDictionary(x => x.Key, x => (IEnumerable)x.Value); - //ensure special __Path field + // Ensure special __Path field var path = e.ValueSet.GetValue("path"); if (path != null) { updatedValues[UmbracoExamineFieldNames.IndexPathFieldName] = path.Yield(); } - //icon + // Ensure special __Icon field if (e.ValueSet.Values.TryGetValue("icon", out IReadOnlyList? icon) && e.ValueSet.Values.ContainsKey(UmbracoExamineFieldNames.IconFieldName) == false) {