Update examine to version 3 (#12307)

* Updating to Examine 3 beta. Currently not building due to missing support for updating values in the OnTransformingIndexValues event

* Updated to beta 6  - It builds, but we need to fix tests

* Fixed issue with values being passed into nested lists.

* Fixed issue in test

* Updated to examine beta.9

* Fixed breaking changes
This commit is contained in:
Bjarke Berg
2022-05-02 14:11:46 +02:00
committed by GitHub
parent 4bc5d31dfe
commit 11f9bcbea2
10 changed files with 97 additions and 83 deletions

View File

@@ -21,7 +21,7 @@
<None Remove="obj\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Examine" Version="2.0.1" />
<PackageReference Include="Examine" Version="3.0.0-beta.9" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@@ -64,34 +64,34 @@ namespace Umbraco.Cms.Infrastructure.Examine
// Then we'll index the Value group all together.
var invalidOrValid = values.GroupBy(v =>
{
if (!v.Values.TryGetValue("path", out List<object>? paths) || paths.Count <= 0 || paths[0] == null)
if (!v.Values.TryGetValue("path", out IReadOnlyList<object>? paths) || paths.Count <= 0 || paths[0] == null)
{
return ValueSetValidationResult.Failed;
return ValueSetValidationStatus.Failed;
}
ValueSetValidationResult validationResult = ValueSetValidator.Validate(v);
return validationResult;
return validationResult.Status;
}).ToList();
var hasDeletes = false;
var hasUpdates = false;
// ordering by descending so that Filtered/Failed processes first
foreach (IGrouping<ValueSetValidationResult, ValueSet> group in invalidOrValid.OrderByDescending(x => x.Key))
foreach (IGrouping<ValueSetValidationStatus, ValueSet> group in invalidOrValid.OrderByDescending(x => x.Key))
{
switch (group.Key)
{
case ValueSetValidationResult.Valid:
case ValueSetValidationStatus.Valid:
hasUpdates = true;
//these are the valid ones, so just index them all at once
base.PerformIndexItems(group.ToList(), onComplete);
break;
case ValueSetValidationResult.Failed:
case ValueSetValidationStatus.Failed:
// don't index anything that is invalid
break;
case ValueSetValidationResult.Filtered:
case ValueSetValidationStatus.Filtered:
hasDeletes = true;
// these are the invalid/filtered items so we'll delete them

View File

@@ -13,6 +13,7 @@ using Microsoft.Extensions.Options;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.Services;
using Umbraco.Extensions;
namespace Umbraco.Cms.Infrastructure.Examine
{
@@ -112,18 +113,22 @@ namespace Umbraco.Cms.Infrastructure.Examine
{
base.OnTransformingIndexValues(e);
var updatedValues = e.ValueSet.Values.ToDictionary(x => x.Key, x => (IEnumerable<object>) x.Value);
//ensure special __Path field
var path = e.ValueSet.GetValue("path");
if (path != null)
{
e.ValueSet.Set(UmbracoExamineFieldNames.IndexPathFieldName, path);
updatedValues[UmbracoExamineFieldNames.IndexPathFieldName] = path.Yield();
}
//icon
if (e.ValueSet.Values.TryGetValue("icon", out var icon) && e.ValueSet.Values.ContainsKey(UmbracoExamineFieldNames.IconFieldName) == false)
{
e.ValueSet.Values[UmbracoExamineFieldNames.IconFieldName] = icon;
updatedValues[UmbracoExamineFieldNames.IconFieldName] = icon;
}
e.SetValues(updatedValues);
}
public Attempt<string?> IsHealthy() => _diagnostics.IsHealthy();

View File

@@ -98,22 +98,24 @@ namespace Umbraco.Cms.Infrastructure.Examine
public override ValueSetValidationResult Validate(ValueSet valueSet)
{
var baseValidate = base.Validate(valueSet);
if (baseValidate == ValueSetValidationResult.Failed)
return ValueSetValidationResult.Failed;
valueSet = baseValidate.ValueSet;
if (baseValidate.Status == ValueSetValidationStatus.Failed)
return new ValueSetValidationResult(ValueSetValidationStatus.Failed, valueSet);
var isFiltered = baseValidate == ValueSetValidationResult.Filtered;
var isFiltered = baseValidate.Status == ValueSetValidationStatus.Filtered;
var filteredValues = valueSet.Values.ToDictionary(x => x.Key, x => x.Value.ToList());
//check for published content
if (valueSet.Category == IndexTypes.Content && PublishedValuesOnly)
{
if (!valueSet.Values.TryGetValue(UmbracoExamineFieldNames.PublishedFieldName, out var published))
{
return ValueSetValidationResult.Failed;
return new ValueSetValidationResult(ValueSetValidationStatus.Failed, valueSet);
}
if (!published[0].Equals("y"))
{
return ValueSetValidationResult.Failed;
return new ValueSetValidationResult(ValueSetValidationStatus.Failed, valueSet);
}
//deal with variants, if there are unpublished variants than we need to remove them from the value set
@@ -129,7 +131,7 @@ namespace Umbraco.Cms.Infrastructure.Examine
var cultureSuffix = publishField.Key.Substring(publishField.Key.LastIndexOf('_'));
foreach (var cultureField in valueSet.Values.Where(x => x.Key.InvariantEndsWith(cultureSuffix)).ToList())
{
valueSet.Values.Remove(cultureField.Key);
filteredValues.Remove(cultureField.Key);
isFiltered = true;
}
}
@@ -138,21 +140,22 @@ namespace Umbraco.Cms.Infrastructure.Examine
}
//must have a 'path'
if (!valueSet.Values.TryGetValue(PathKey, out var pathValues)) return ValueSetValidationResult.Failed;
if (pathValues.Count == 0) return ValueSetValidationResult.Failed;
if (pathValues[0] == null) return ValueSetValidationResult.Failed;
if (pathValues[0].ToString().IsNullOrWhiteSpace()) return ValueSetValidationResult.Failed;
if (!valueSet.Values.TryGetValue(PathKey, out var pathValues)) return new ValueSetValidationResult(ValueSetValidationStatus.Failed, valueSet);
if (pathValues.Count == 0) return new ValueSetValidationResult(ValueSetValidationStatus.Failed, valueSet);
if (pathValues[0] == null) return new ValueSetValidationResult(ValueSetValidationStatus.Failed, valueSet);
if (pathValues[0].ToString().IsNullOrWhiteSpace()) return new ValueSetValidationResult(ValueSetValidationStatus.Failed, valueSet);
var path = pathValues[0].ToString();
var filteredValueSet = new ValueSet(valueSet.Id, valueSet.Category, valueSet.ItemType, filteredValues.ToDictionary(x=>x.Key, x=> (IEnumerable<object>)x.Value));
// We need to validate the path of the content based on ParentId, protected content and recycle bin rules.
// We cannot return FAILED here because we need the value set to get into the indexer and then deal with it from there
// because we need to remove anything that doesn't pass by protected content in the cases that umbraco data is moved to an illegal parent.
if (!ValidatePath(path!, valueSet.Category)
|| !ValidateRecycleBin(path!, valueSet.Category)
|| !ValidateProtectedContent(path!, valueSet.Category))
return ValueSetValidationResult.Filtered;
return new ValueSetValidationResult(ValueSetValidationStatus.Filtered, filteredValueSet);
return isFiltered ? ValueSetValidationResult.Filtered : ValueSetValidationResult.Valid;
return new ValueSetValidationResult(isFiltered ? ValueSetValidationStatus.Filtered : ValueSetValidationStatus.Valid, filteredValueSet);
}
}
}

View File

@@ -60,18 +60,19 @@ namespace Umbraco.Cms.Infrastructure.Examine
public virtual ValueSetValidationResult Validate(ValueSet valueSet)
{
if (ValidIndexCategories != null && !ValidIndexCategories.InvariantContains(valueSet.Category))
return ValueSetValidationResult.Failed;
return new ValueSetValidationResult(ValueSetValidationStatus.Failed, valueSet);
//check if this document is of a correct type of node type alias
if (IncludeItemTypes != null && !IncludeItemTypes.InvariantContains(valueSet.ItemType))
return ValueSetValidationResult.Failed;
return new ValueSetValidationResult(ValueSetValidationStatus.Failed, valueSet);
//if this node type is part of our exclusion list
if (ExcludeItemTypes != null && ExcludeItemTypes.InvariantContains(valueSet.ItemType))
return ValueSetValidationResult.Failed;
return new ValueSetValidationResult(ValueSetValidationStatus.Failed, valueSet);
var isFiltered = false;
var filteredValues = valueSet.Values.ToDictionary(x => x.Key, x => x.Value.ToList());
//filter based on the fields provided (if any)
if (IncludeFields != null || ExcludeFields != null)
{
@@ -79,20 +80,21 @@ namespace Umbraco.Cms.Infrastructure.Examine
{
if (IncludeFields != null && !IncludeFields.InvariantContains(key))
{
valueSet.Values.Remove(key); //remove any value with a key that doesn't match the inclusion list
filteredValues.Remove(key); //remove any value with a key that doesn't match the inclusion list
isFiltered = true;
}
if (ExcludeFields != null && ExcludeFields.InvariantContains(key))
{
valueSet.Values.Remove(key); //remove any value with a key that matches the exclusion list
filteredValues.Remove(key); //remove any value with a key that matches the exclusion list
isFiltered = true;
}
}
}
return isFiltered ? ValueSetValidationResult.Filtered : ValueSetValidationResult.Valid;
var filteredValueSet = new ValueSet(valueSet.Id, valueSet.Category, valueSet.ItemType, filteredValues.ToDictionary(x => x.Key, x => (IEnumerable<object>)x.Value));
return new ValueSetValidationResult(isFiltered ? ValueSetValidationStatus.Filtered : ValueSetValidationStatus.Valid, filteredValueSet);
}
}
}

View File

@@ -52,7 +52,7 @@
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="5.0.0" />
<PackageReference Include="System.Text.Encodings.Web" Version="6.0.0" /> <!-- Explicit updated this nested dependency due to this https://github.com/dotnet/announcements/issues/178-->
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="6.0.0" />
<PackageReference Include="Examine.Core" Version="2.0.1" />
<PackageReference Include="Examine.Core" Version="3.0.0-beta.9" />
<PackageReference Include="Umbraco.Code" Version="2.0.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>