diff --git a/src/Umbraco.Core/PropertyEditors/JsonPropertyIndexValueFactoryBase.cs b/src/Umbraco.Core/PropertyEditors/JsonPropertyIndexValueFactoryBase.cs index 973ee3d40c..ee1f637909 100644 --- a/src/Umbraco.Core/PropertyEditors/JsonPropertyIndexValueFactoryBase.cs +++ b/src/Umbraco.Core/PropertyEditors/JsonPropertyIndexValueFactoryBase.cs @@ -40,7 +40,7 @@ public abstract class JsonPropertyIndexValueFactoryBase : IProperty } - public IEnumerable>> GetIndexValues( + public virtual IEnumerable>> GetIndexValues( IProperty property, string? culture, string? segment, diff --git a/src/Umbraco.Core/PropertyEditors/TagPropertyIndexValueFactory.cs b/src/Umbraco.Core/PropertyEditors/TagPropertyIndexValueFactory.cs index f858b6801a..2b09659091 100644 --- a/src/Umbraco.Core/PropertyEditors/TagPropertyIndexValueFactory.cs +++ b/src/Umbraco.Core/PropertyEditors/TagPropertyIndexValueFactory.cs @@ -1,20 +1,26 @@ +using System.Text.Json; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Web.Common.DependencyInjection; +using Umbraco.Extensions; namespace Umbraco.Cms.Core.PropertyEditors; public class TagPropertyIndexValueFactory : JsonPropertyIndexValueFactoryBase, ITagPropertyIndexValueFactory { + private IndexingSettings _indexingSettings; + public TagPropertyIndexValueFactory( IJsonSerializer jsonSerializer, IOptionsMonitor indexingSettings) : base(jsonSerializer, indexingSettings) { ForceExplicitlyIndexEachNestedProperty = true; + _indexingSettings = indexingSettings.CurrentValue; + indexingSettings.OnChange(newValue => _indexingSettings = newValue); } [Obsolete("Use non-obsolete constructor. This will be removed in Umbraco 14.")] @@ -45,4 +51,40 @@ public class TagPropertyIndexValueFactory : JsonPropertyIndexValueFactoryBase>(property.Alias, deserializedPropertyValue); } + + public override IEnumerable>> GetIndexValues( + IProperty property, + string? culture, + string? segment, + bool published, + IEnumerable availableCultures, + IDictionary contentTypeDictionary) + { + IEnumerable>> jsonValues = base.GetIndexValues(property, culture, segment, published, availableCultures, contentTypeDictionary); + if (jsonValues?.Any() is true) + { + return jsonValues; + } + + var result = new List>>(); + + var propertyValue = property.GetValue(culture, segment, published); + + // If there is a value, it's a string and it's not empty/white space + if (propertyValue is string rawValue && !string.IsNullOrWhiteSpace(rawValue)) + { + var values = rawValue.Split(',', StringSplitOptions.RemoveEmptyEntries); + + result.AddRange(Handle(values, property, culture, segment, published, availableCultures, contentTypeDictionary)); + } + + IEnumerable>> summary = HandleResume(result, property, culture, segment, published); + if (_indexingSettings.ExplicitlyIndexEachNestedProperty || ForceExplicitlyIndexEachNestedProperty) + { + result.AddRange(summary); + return result; + } + + return summary; + } }