Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V14: Merge #16800

Merged
merged 8 commits into from
Jul 19, 2024
9 changes: 3 additions & 6 deletions src/Umbraco.Examine.Lucene/DeliveryApiContentIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -134,10 +137,4 @@ protected override void PerformDeleteFromIndex(IEnumerable<string> itemIds, Acti

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.
}
}
21 changes: 19 additions & 2 deletions src/Umbraco.Examine.Lucene/UmbracoExamineIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ protected UmbracoExamineIndex(
}

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>
Expand Down Expand Up @@ -115,16 +121,27 @@ protected override void OnTransformingIndexValues(IndexingItemEventArgs e)
{
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)
{
Expand Down
Loading