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
This commit is contained in:
committed by
GitHub
parent
be81586b46
commit
dfe41d7f76
@@ -17,6 +17,9 @@ public class DeliveryApiContentIndex : UmbracoExamineIndex
|
||||
private readonly IDeliveryApiCompositeIdHandler _deliveryApiCompositeIdHandler;
|
||||
private readonly ILogger<DeliveryApiContentIndex> _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.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +38,14 @@ public abstract class UmbracoExamineIndex : LuceneIndex, IUmbracoIndex, IIndexDi
|
||||
}
|
||||
|
||||
public Attempt<string?> IsHealthy() => _diagnostics.IsHealthy();
|
||||
|
||||
public virtual IReadOnlyDictionary<string, object?> Metadata => _diagnostics.Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// Performs special __Path and __Icon value transformations to all deriving indexes when set to true.
|
||||
/// </summary>
|
||||
protected virtual bool ApplySpecialValueTransformations => true;
|
||||
|
||||
/// <summary>
|
||||
/// When set to true Umbraco will keep the index in sync with Umbraco data automatically
|
||||
/// </summary>
|
||||
@@ -115,16 +121,27 @@ public abstract class UmbracoExamineIndex : LuceneIndex, IUmbracoIndex, IIndexDi
|
||||
{
|
||||
base.OnTransformingIndexValues(e);
|
||||
|
||||
if (ApplySpecialValueTransformations)
|
||||
{
|
||||
ApplySpecialIndexValueTransformations(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the index ValueSet with a special __Path and __Icon fields.
|
||||
/// </summary>
|
||||
private void ApplySpecialIndexValueTransformations(IndexingItemEventArgs e)
|
||||
{
|
||||
var updatedValues = e.ValueSet.Values.ToDictionary(x => x.Key, x => (IEnumerable<object>)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<object>? icon) &&
|
||||
e.ValueSet.Values.ContainsKey(UmbracoExamineFieldNames.IconFieldName) == false)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user