|
| 1 | +using System.Text.Json; |
1 | 2 | using Microsoft.Extensions.DependencyInjection;
|
2 | 3 | using Microsoft.Extensions.Options;
|
3 | 4 | using Umbraco.Cms.Core.Configuration.Models;
|
4 | 5 | using Umbraco.Cms.Core.Models;
|
5 | 6 | using Umbraco.Cms.Core.Serialization;
|
6 | 7 | using Umbraco.Cms.Web.Common.DependencyInjection;
|
| 8 | +using Umbraco.Extensions; |
7 | 9 |
|
8 | 10 | namespace Umbraco.Cms.Core.PropertyEditors;
|
9 | 11 |
|
10 | 12 | public class TagPropertyIndexValueFactory : JsonPropertyIndexValueFactoryBase<string[]>, ITagPropertyIndexValueFactory
|
11 | 13 | {
|
| 14 | + private IndexingSettings _indexingSettings; |
| 15 | + |
12 | 16 | public TagPropertyIndexValueFactory(
|
13 | 17 | IJsonSerializer jsonSerializer,
|
14 | 18 | IOptionsMonitor<IndexingSettings> indexingSettings)
|
15 | 19 | : base(jsonSerializer, indexingSettings)
|
16 | 20 | {
|
17 | 21 | ForceExplicitlyIndexEachNestedProperty = true;
|
| 22 | + _indexingSettings = indexingSettings.CurrentValue; |
| 23 | + indexingSettings.OnChange(newValue => _indexingSettings = newValue); |
18 | 24 | }
|
19 | 25 |
|
20 | 26 | [Obsolete("Use non-obsolete constructor. This will be removed in Umbraco 14.")]
|
@@ -45,4 +51,40 @@ public TagPropertyIndexValueFactory(IJsonSerializer jsonSerializer)
|
45 | 51 | {
|
46 | 52 | yield return new KeyValuePair<string, IEnumerable<object?>>(property.Alias, deserializedPropertyValue);
|
47 | 53 | }
|
| 54 | + |
| 55 | + public override IEnumerable<KeyValuePair<string, IEnumerable<object?>>> GetIndexValues( |
| 56 | + IProperty property, |
| 57 | + string? culture, |
| 58 | + string? segment, |
| 59 | + bool published, |
| 60 | + IEnumerable<string> availableCultures, |
| 61 | + IDictionary<Guid, IContentType> contentTypeDictionary) |
| 62 | + { |
| 63 | + IEnumerable<KeyValuePair<string, IEnumerable<object?>>> jsonValues = base.GetIndexValues(property, culture, segment, published, availableCultures, contentTypeDictionary); |
| 64 | + if (jsonValues?.Any() is true) |
| 65 | + { |
| 66 | + return jsonValues; |
| 67 | + } |
| 68 | + |
| 69 | + var result = new List<KeyValuePair<string, IEnumerable<object?>>>(); |
| 70 | + |
| 71 | + var propertyValue = property.GetValue(culture, segment, published); |
| 72 | + |
| 73 | + // If there is a value, it's a string and it's not empty/white space |
| 74 | + if (propertyValue is string rawValue && !string.IsNullOrWhiteSpace(rawValue)) |
| 75 | + { |
| 76 | + var values = rawValue.Split(',', StringSplitOptions.RemoveEmptyEntries); |
| 77 | + |
| 78 | + result.AddRange(Handle(values, property, culture, segment, published, availableCultures, contentTypeDictionary)); |
| 79 | + } |
| 80 | + |
| 81 | + IEnumerable<KeyValuePair<string, IEnumerable<object?>>> summary = HandleResume(result, property, culture, segment, published); |
| 82 | + if (_indexingSettings.ExplicitlyIndexEachNestedProperty || ForceExplicitlyIndexEachNestedProperty) |
| 83 | + { |
| 84 | + result.AddRange(summary); |
| 85 | + return result; |
| 86 | + } |
| 87 | + |
| 88 | + return summary; |
| 89 | + } |
48 | 90 | }
|
0 commit comments