From 945e3be5533d5ffb5074a2f92068e866d907afce Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 9 Aug 2023 11:47:45 +0200 Subject: [PATCH] Add config so it is configurable whether to explicitly index each nested property (#14648) * Added new configuration "Umbraco:CMS:Examine:ExplicitlyIndexEachNestedProperty" that can be used to avoid nested properties like block grid to index each property individually. * Moved the setting "Umbraco:CMS:Examine:ExplicitlyIndexEachNestedProperty" to "Umbraco:CMS:Indexing:ExplicitlyIndexEachNestedProperty" to make it more future proof * Added missing registration * Fixed registration * Small readability improvement --------- Co-authored-by: Sven Geusens --- .../Configuration/Models/IndexingSettings.cs | 18 +++++++++++ src/Umbraco.Core/Constants-Configuration.cs | 1 + .../UmbracoBuilder.Configuration.cs | 3 +- .../JsonPropertyIndexValueFactoryBase.cs | 32 ++++++++++++++++--- .../TagPropertyIndexValueFactory.cs | 17 +++++++++- .../BlockValuePropertyIndexValueFactory.cs | 16 +++++++++- .../NestedContentPropertyIndexValueFactory.cs | 19 +++++++++-- .../NestedPropertyIndexValueFactoryBase.cs | 19 +++++++++-- 8 files changed, 114 insertions(+), 11 deletions(-) create mode 100644 src/Umbraco.Core/Configuration/Models/IndexingSettings.cs diff --git a/src/Umbraco.Core/Configuration/Models/IndexingSettings.cs b/src/Umbraco.Core/Configuration/Models/IndexingSettings.cs new file mode 100644 index 0000000000..2a94a406d1 --- /dev/null +++ b/src/Umbraco.Core/Configuration/Models/IndexingSettings.cs @@ -0,0 +1,18 @@ +using System.ComponentModel; + +namespace Umbraco.Cms.Core.Configuration.Models; + +/// +/// Typed configuration options for index creator settings. +/// +[UmbracoOptions(Constants.Configuration.ConfigIndexing)] +public class IndexingSettings +{ + private const bool StaticExplicitlyIndexEachNestedProperty = true; + + /// + /// Gets or sets a value for whether each nested property should have it's own indexed value. Requires a rebuild of indexes when changed. + /// + [DefaultValue(StaticExplicitlyIndexEachNestedProperty)] + public bool ExplicitlyIndexEachNestedProperty { get; set; } = StaticExplicitlyIndexEachNestedProperty; +} diff --git a/src/Umbraco.Core/Constants-Configuration.cs b/src/Umbraco.Core/Constants-Configuration.cs index bd84ab828f..4f9d045cb6 100644 --- a/src/Umbraco.Core/Constants-Configuration.cs +++ b/src/Umbraco.Core/Constants-Configuration.cs @@ -39,6 +39,7 @@ public static partial class Constants public const string ConfigHosting = ConfigPrefix + "Hosting"; public const string ConfigImaging = ConfigPrefix + "Imaging"; public const string ConfigExamine = ConfigPrefix + "Examine"; + public const string ConfigIndexing = ConfigPrefix + "Indexing"; public const string ConfigKeepAlive = ConfigPrefix + "KeepAlive"; public const string ConfigLogging = ConfigPrefix + "Logging"; public const string ConfigMemberPassword = ConfigPrefix + "Security:MemberPassword"; diff --git a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs index c4ff4bdab6..411c39b178 100644 --- a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs +++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs @@ -50,6 +50,7 @@ public static partial class UmbracoBuilderExtensions builder .AddUmbracoOptions() .AddUmbracoOptions() + .AddUmbracoOptions() .AddUmbracoOptions() .AddUmbracoOptions() .AddUmbracoOptions() @@ -65,7 +66,7 @@ public static partial class UmbracoBuilderExtensions .AddUmbracoOptions() .AddUmbracoOptions() .AddUmbracoOptions() - .AddUmbracoOptions() + .AddUmbracoOptions() .AddUmbracoOptions() .AddUmbracoOptions() .AddUmbracoOptions() diff --git a/src/Umbraco.Core/PropertyEditors/JsonPropertyIndexValueFactoryBase.cs b/src/Umbraco.Core/PropertyEditors/JsonPropertyIndexValueFactoryBase.cs index a56bf0ed88..bf549e2d2e 100644 --- a/src/Umbraco.Core/PropertyEditors/JsonPropertyIndexValueFactoryBase.cs +++ b/src/Umbraco.Core/PropertyEditors/JsonPropertyIndexValueFactoryBase.cs @@ -1,5 +1,9 @@ +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; @@ -11,13 +15,28 @@ namespace Umbraco.Cms.Core.PropertyEditors; public abstract class JsonPropertyIndexValueFactoryBase : IPropertyIndexValueFactory { private readonly IJsonSerializer _jsonSerializer; + private IndexingSettings _indexingSettings; + + protected bool ForceExplicitlyIndexEachNestedProperty { get; set; } /// /// Constructor for the JsonPropertyIndexValueFactoryBase. /// - protected JsonPropertyIndexValueFactoryBase(IJsonSerializer jsonSerializer) + protected JsonPropertyIndexValueFactoryBase(IJsonSerializer jsonSerializer, IOptionsMonitor indexingSettings) { _jsonSerializer = jsonSerializer; + _indexingSettings = indexingSettings.CurrentValue; + indexingSettings.OnChange(newValue => _indexingSettings = newValue); + } + + + /// + /// Constructor for the JsonPropertyIndexValueFactoryBase. + /// + [Obsolete("Use non-obsolete constructor. This will be removed in Umbraco 14.")] + protected JsonPropertyIndexValueFactoryBase(IJsonSerializer jsonSerializer): this(jsonSerializer, StaticServiceProvider.Instance.GetRequiredService>()) + { + } /// @@ -58,9 +77,14 @@ public abstract class JsonPropertyIndexValueFactoryBase : IProperty } } - result.AddRange(HandleResume(result, property, culture, segment, published)); + IEnumerable>> summary = HandleResume(result, property, culture, segment, published); + if (_indexingSettings.ExplicitlyIndexEachNestedProperty || ForceExplicitlyIndexEachNestedProperty) + { + result.AddRange(summary); + return result; + } - return result; + return summary; } [Obsolete("Use method overload that has availableCultures, scheduled for removal in v14")] @@ -68,7 +92,7 @@ public abstract class JsonPropertyIndexValueFactoryBase : IProperty => GetIndexValues(property, culture, segment, published, Enumerable.Empty()); /// - /// Method to return a list of resume of the content. By default this returns an empty list + /// Method to return a list of summary of the content. By default this returns an empty list /// protected virtual IEnumerable>> HandleResume( List>> result, diff --git a/src/Umbraco.Core/PropertyEditors/TagPropertyIndexValueFactory.cs b/src/Umbraco.Core/PropertyEditors/TagPropertyIndexValueFactory.cs index b3a8e9a2b8..f858b6801a 100644 --- a/src/Umbraco.Core/PropertyEditors/TagPropertyIndexValueFactory.cs +++ b/src/Umbraco.Core/PropertyEditors/TagPropertyIndexValueFactory.cs @@ -1,12 +1,27 @@ +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; namespace Umbraco.Cms.Core.PropertyEditors; public class TagPropertyIndexValueFactory : JsonPropertyIndexValueFactoryBase, ITagPropertyIndexValueFactory { - public TagPropertyIndexValueFactory(IJsonSerializer jsonSerializer) : base(jsonSerializer) + public TagPropertyIndexValueFactory( + IJsonSerializer jsonSerializer, + IOptionsMonitor indexingSettings) + : base(jsonSerializer, indexingSettings) { + ForceExplicitlyIndexEachNestedProperty = true; + } + + [Obsolete("Use non-obsolete constructor. This will be removed in Umbraco 14.")] + public TagPropertyIndexValueFactory(IJsonSerializer jsonSerializer) + : this(jsonSerializer, StaticServiceProvider.Instance.GetRequiredService>()) + { + } protected override IEnumerable>> Handle( diff --git a/src/Umbraco.Infrastructure/PropertyEditors/BlockValuePropertyIndexValueFactory.cs b/src/Umbraco.Infrastructure/PropertyEditors/BlockValuePropertyIndexValueFactory.cs index dfedeedc3f..adace6126e 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/BlockValuePropertyIndexValueFactory.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/BlockValuePropertyIndexValueFactory.cs @@ -1,10 +1,14 @@ // Copyright (c) Umbraco. // See LICENSE for more details. +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Blocks; using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Web.Common.DependencyInjection; namespace Umbraco.Cms.Core.PropertyEditors; @@ -14,12 +18,22 @@ internal sealed class BlockValuePropertyIndexValueFactory : { private readonly IContentTypeService _contentTypeService; + public BlockValuePropertyIndexValueFactory( + PropertyEditorCollection propertyEditorCollection, + IContentTypeService contentTypeService, + IJsonSerializer jsonSerializer, + IOptionsMonitor indexingSettings) + : base(propertyEditorCollection, jsonSerializer, indexingSettings) + { + _contentTypeService = contentTypeService; + } + [Obsolete("Use non-obsolete constructor. This will be removed in Umbraco 14.")] public BlockValuePropertyIndexValueFactory( PropertyEditorCollection propertyEditorCollection, IContentTypeService contentTypeService, IJsonSerializer jsonSerializer) - : base(propertyEditorCollection, jsonSerializer) + : this(propertyEditorCollection, contentTypeService, jsonSerializer, StaticServiceProvider.Instance.GetRequiredService>()) { _contentTypeService = contentTypeService; } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyIndexValueFactory.cs b/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyIndexValueFactory.cs index 445e1cc361..121a40bec9 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyIndexValueFactory.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyIndexValueFactory.cs @@ -1,9 +1,13 @@ // Copyright (c) Umbraco. // See LICENSE for more details. +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.Core.Services; +using Umbraco.Cms.Web.Common.DependencyInjection; namespace Umbraco.Cms.Core.PropertyEditors; @@ -15,11 +19,22 @@ internal sealed class NestedContentPropertyIndexValueFactory { private readonly IContentTypeService _contentTypeService; - public NestedContentPropertyIndexValueFactory( PropertyEditorCollection propertyEditorCollection, IContentTypeService contentTypeService, - IJsonSerializer jsonSerializer) : base(propertyEditorCollection, jsonSerializer) + IJsonSerializer jsonSerializer, + IOptionsMonitor indexingSettings) + : base(propertyEditorCollection, jsonSerializer, indexingSettings) + { + _contentTypeService = contentTypeService; + } + + [Obsolete("Use non-obsolete constructor. This will be removed in Umbraco 14.")] + public NestedContentPropertyIndexValueFactory( + PropertyEditorCollection propertyEditorCollection, + IContentTypeService contentTypeService, + IJsonSerializer jsonSerializer) + : this(propertyEditorCollection, contentTypeService, jsonSerializer, StaticServiceProvider.Instance.GetRequiredService>()) { _contentTypeService = contentTypeService; } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/NestedPropertyIndexValueFactoryBase.cs b/src/Umbraco.Infrastructure/PropertyEditors/NestedPropertyIndexValueFactoryBase.cs index b3799aaa95..94ed0a3e15 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/NestedPropertyIndexValueFactoryBase.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/NestedPropertyIndexValueFactoryBase.cs @@ -1,7 +1,11 @@ using System.Text; +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.Infrastructure.Examine; +using Umbraco.Cms.Web.Common.DependencyInjection; using Umbraco.Extensions; namespace Umbraco.Cms.Core.PropertyEditors; @@ -10,12 +14,23 @@ internal abstract class NestedPropertyIndexValueFactoryBase { private readonly PropertyEditorCollection _propertyEditorCollection; + + protected NestedPropertyIndexValueFactoryBase( + PropertyEditorCollection propertyEditorCollection, + IJsonSerializer jsonSerializer, + IOptionsMonitor indexingSettings) + : base(jsonSerializer, indexingSettings) + { + _propertyEditorCollection = propertyEditorCollection; + } + + [Obsolete("Use non-obsolete constructor. This will be removed in Umbraco 14.")] protected NestedPropertyIndexValueFactoryBase( PropertyEditorCollection propertyEditorCollection, IJsonSerializer jsonSerializer) - : base(jsonSerializer) + : this(propertyEditorCollection, jsonSerializer, StaticServiceProvider.Instance.GetRequiredService>()) { - _propertyEditorCollection = propertyEditorCollection; + } [Obsolete("Use the overload that specifies availableCultures, scheduled for removal in v14")]