Skip to content

Commit dfe41d7

Browse files
authoredJul 15, 2024··
V13: Ensure TransformingIndexValues event is also raised from the DeliveryApiContentIndex (#16756)
* Removing override of OnTransformingIndexValues from DeliveryApiContentIndex * Making sure that TransformingIndexValues event is raised for DeliveryApiContentIndex without performing the special index value transformations * Review suggestion
1 parent be81586 commit dfe41d7

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed
 

‎src/Umbraco.Examine.Lucene/DeliveryApiContentIndex.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public class DeliveryApiContentIndex : UmbracoExamineIndex
1717
private readonly IDeliveryApiCompositeIdHandler _deliveryApiCompositeIdHandler;
1818
private readonly ILogger<DeliveryApiContentIndex> _logger;
1919

20+
// The special path and icon value transformations are not needed in this case
21+
protected override bool ApplySpecialValueTransformations => false;
22+
2023
[Obsolete("Use the constructor that takes an IDeliveryApiCompositeIdHandler instead, scheduled for removal in v15")]
2124
public DeliveryApiContentIndex(
2225
ILoggerFactory loggerFactory,
@@ -134,10 +137,4 @@ protected override void PerformDeleteFromIndex(IEnumerable<string> itemIds, Acti
134137

135138
return (compositeIdModel.Id?.ToString(CultureInfo.InvariantCulture), compositeIdModel.Culture);
136139
}
137-
138-
protected override void OnTransformingIndexValues(IndexingItemEventArgs e)
139-
{
140-
// UmbracoExamineIndex (base class down the hierarchy) performs some magic transformations here for paths and icons;
141-
// we don't want that for the Delivery API, so we'll have to override this method and simply do nothing.
142-
}
143140
}

‎src/Umbraco.Examine.Lucene/UmbracoExamineIndex.cs

+19-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ protected UmbracoExamineIndex(
3838
}
3939

4040
public Attempt<string?> IsHealthy() => _diagnostics.IsHealthy();
41+
4142
public virtual IReadOnlyDictionary<string, object?> Metadata => _diagnostics.Metadata;
4243

44+
/// <summary>
45+
/// Performs special __Path and __Icon value transformations to all deriving indexes when set to true.
46+
/// </summary>
47+
protected virtual bool ApplySpecialValueTransformations => true;
48+
4349
/// <summary>
4450
/// When set to true Umbraco will keep the index in sync with Umbraco data automatically
4551
/// </summary>
@@ -115,16 +121,27 @@ protected override void OnTransformingIndexValues(IndexingItemEventArgs e)
115121
{
116122
base.OnTransformingIndexValues(e);
117123

124+
if (ApplySpecialValueTransformations)
125+
{
126+
ApplySpecialIndexValueTransformations(e);
127+
}
128+
}
129+
130+
/// <summary>
131+
/// Updates the index ValueSet with a special __Path and __Icon fields.
132+
/// </summary>
133+
private void ApplySpecialIndexValueTransformations(IndexingItemEventArgs e)
134+
{
118135
var updatedValues = e.ValueSet.Values.ToDictionary(x => x.Key, x => (IEnumerable<object>)x.Value);
119136

120-
//ensure special __Path field
137+
// Ensure special __Path field
121138
var path = e.ValueSet.GetValue("path");
122139
if (path != null)
123140
{
124141
updatedValues[UmbracoExamineFieldNames.IndexPathFieldName] = path.Yield();
125142
}
126143

127-
//icon
144+
// Ensure special __Icon field
128145
if (e.ValueSet.Values.TryGetValue("icon", out IReadOnlyList<object>? icon) &&
129146
e.ValueSet.Values.ContainsKey(UmbracoExamineFieldNames.IconFieldName) == false)
130147
{

0 commit comments

Comments
 (0)
Please sign in to comment.