more tweaks to get config based indexes working, updates to IIndexPopulator to have strongly typed association

This commit is contained in:
Shannon
2018-12-13 23:17:58 +11:00
parent c129375dd0
commit 162f8480d1
14 changed files with 38 additions and 35 deletions

View File

@@ -14,7 +14,7 @@
<summary>Contains the core assemblies needed to run Umbraco Cms</summary>
<language>en-US</language>
<tags>umbraco</tags>
<dependencies>
<dependencies>
<!--
note: dependencies are specified as [x.y.z,x.999999) eg [2.1.0,2.999999) and NOT [2.1.0,3.0.0) because
the latter would pick anything below 3.0.0 and that includes prereleases such as 3.0.0-alpha, and we do

View File

@@ -15,7 +15,7 @@ namespace Umbraco.Examine
/// <summary>
/// Performs the data lookups required to rebuild a content index
/// </summary>
public class ContentIndexPopulator : IndexPopulator
public class ContentIndexPopulator : IndexPopulator<UmbracoContentIndex>
{
private readonly IContentService _contentService;
private readonly IValueSetBuilder<IContent> _contentValueSetBuilder;
@@ -56,9 +56,6 @@ namespace Umbraco.Examine
_publishedQuery = sqlContext.Query<IContent>().Where(x => x.Published);
_publishedValuesOnly = publishedValuesOnly;
_parentId = parentId;
RegisterIndex(Constants.UmbracoIndexes.InternalIndexName);
RegisterIndex(Constants.UmbracoIndexes.ExternalIndexName);
}
protected override void PopulateIndexes(IEnumerable<IIndex> indexes)

View File

@@ -3,12 +3,14 @@ using Examine;
namespace Umbraco.Examine
{
public interface IIndexPopulator
{
bool IsRegistered(string indexName);
void RegisterIndex(string indexName);
/// <summary>
/// If this index is registered with this populatr
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
bool IsRegistered(IIndex index);
/// <summary>
/// Populate indexers

View File

@@ -5,13 +5,26 @@ using Umbraco.Core.Collections;
namespace Umbraco.Examine
{
/// <summary>
/// An <see cref="IIndexPopulator"/> that is automatically associated to any index of type <see cref="TIndex"/>
/// </summary>
/// <typeparam name="TIndex"></typeparam>
public abstract class IndexPopulator<TIndex> : IndexPopulator where TIndex : IIndex
{
public override bool IsRegistered(IIndex index)
{
if (base.IsRegistered(index)) return true;
return index is TIndex;
}
}
public abstract class IndexPopulator : IIndexPopulator
{
private readonly ConcurrentHashSet<string> _registeredIndexes = new ConcurrentHashSet<string>();
public bool IsRegistered(string indexName)
public virtual bool IsRegistered(IIndex index)
{
return _registeredIndexes.Contains(indexName);
return _registeredIndexes.Contains(index.Name);
}
/// <summary>
@@ -25,7 +38,7 @@ namespace Umbraco.Examine
public void Populate(params IIndex[] indexes)
{
PopulateIndexes(indexes.Where(x => IsRegistered(x.Name)));
PopulateIndexes(indexes.Where(IsRegistered));
}
protected abstract void PopulateIndexes(IEnumerable<IIndex> indexes);

View File

@@ -20,9 +20,9 @@ namespace Umbraco.Examine
ExamineManager = examineManager;
}
public bool CanRebuild(string indexName)
public bool CanRebuild(IIndex index)
{
return _populators.Any(x => x.IsRegistered(indexName));
return _populators.Any(x => x.IsRegistered(index));
}
public void RebuildIndex(string indexName)

View File

@@ -10,7 +10,7 @@ namespace Umbraco.Examine
/// <summary>
/// Performs the data lookups required to rebuild a media index
/// </summary>
public class MediaIndexPopulator : IndexPopulator
public class MediaIndexPopulator : IndexPopulator<UmbracoContentIndex>
{
private readonly int? _parentId;
private readonly IMediaService _mediaService;
@@ -37,9 +37,6 @@ namespace Umbraco.Examine
_parentId = parentId;
_mediaService = mediaService;
_mediaValueSetBuilder = mediaValueSetBuilder;
RegisterIndex(Constants.UmbracoIndexes.InternalIndexName);
RegisterIndex(Constants.UmbracoIndexes.ExternalIndexName);
}
protected override void PopulateIndexes(IEnumerable<IIndex> indexes)

View File

@@ -7,7 +7,7 @@ using Umbraco.Core.Services;
namespace Umbraco.Examine
{
public class MemberIndexPopulator : IndexPopulator
public class MemberIndexPopulator : IndexPopulator<UmbracoMemberIndex>
{
private readonly IMemberService _memberService;
private readonly IValueSetBuilder<IMember> _valueSetBuilder;
@@ -16,8 +16,6 @@ namespace Umbraco.Examine
{
_memberService = memberService;
_valueSetBuilder = valueSetBuilder;
RegisterIndex(Core.Constants.UmbracoIndexes.MembersIndexName);
}
protected override void PopulateIndexes(IEnumerable<IIndex> indexes)
{

View File

@@ -48,7 +48,7 @@
</ItemGroup>
<ItemGroup>
<!-- note: NuGet deals with transitive references now -->
<PackageReference Include="Examine" Version="1.0.0-beta059" />
<PackageReference Include="Examine" Version="1.0.0-beta060" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="NPoco" Version="3.9.4" />
</ItemGroup>

View File

@@ -77,7 +77,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="7.0.1" />
<PackageReference Include="Castle.Core" Version="4.2.1" />
<PackageReference Include="Examine" Version="1.0.0-beta059" />
<PackageReference Include="Examine" Version="1.0.0-beta060" />
<PackageReference Include="HtmlAgilityPack">
<Version>1.8.9</Version>
</PackageReference>

View File

@@ -130,8 +130,6 @@ namespace Umbraco.Tests.UmbracoExamine
validator: new ContentValueSetValidator(false)))
using (indexer.ProcessNonAsync())
{
contentRebuilder.RegisterIndex(indexer.Name);
mediaRebuilder.RegisterIndex(indexer.Name);
var searcher = indexer.GetSearcher();
@@ -283,7 +281,6 @@ namespace Umbraco.Tests.UmbracoExamine
validator: new ContentValueSetValidator(false)))
using (indexer.ProcessNonAsync())
{
rebuilder.RegisterIndex(indexer.Name);
var searcher = indexer.GetSearcher();

View File

@@ -62,7 +62,6 @@ namespace Umbraco.Tests.UmbracoExamine
using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir))
using (indexer.ProcessNonAsync())
{
rebuilder.RegisterIndex(indexer.Name);
indexer.CreateIndex();
rebuilder.Populate(indexer);

View File

@@ -88,7 +88,7 @@
<PackageReference Include="CSharpTest.Net.Collections" Version="14.906.1403.1082" />
<PackageReference Include="ClientDependency" Version="1.9.7" />
<PackageReference Include="ClientDependency-Mvc5" Version="1.8.0.0" />
<PackageReference Include="Examine" Version="1.0.0-beta059" />
<PackageReference Include="Examine" Version="1.0.0-beta060" />
<PackageReference Include="ImageProcessor.Web" Version="4.9.3.25" />
<PackageReference Include="ImageProcessor.Web.Config" Version="2.4.1.19" />
<PackageReference Include="Microsoft.AspNet.Identity.Owin" Version="2.2.2" />

View File

@@ -109,7 +109,7 @@ namespace Umbraco.Web.Editors
if (!validate.IsSuccessStatusCode)
throw new HttpResponseException(validate);
validate = ValidatePopulator(indexName);
validate = ValidatePopulator(index);
if (!validate.IsSuccessStatusCode)
throw new HttpResponseException(validate);
@@ -134,7 +134,7 @@ namespace Umbraco.Web.Editors
if (!validate.IsSuccessStatusCode)
return validate;
validate = ValidatePopulator(indexName);
validate = ValidatePopulator(index);
if (!validate.IsSuccessStatusCode)
return validate;
@@ -201,7 +201,7 @@ namespace Umbraco.Web.Editors
Name = indexName,
HealthStatus = isHealth.Success ? (isHealth.Result ?? "Healthy") : (isHealth.Result ?? "Unhealthy"),
ProviderProperties = properties,
CanRebuild = _indexRebuilder.CanRebuild(indexName)
CanRebuild = _indexRebuilder.CanRebuild(index)
};
@@ -228,13 +228,13 @@ namespace Umbraco.Web.Editors
return response1;
}
private HttpResponseMessage ValidatePopulator(string indexName)
private HttpResponseMessage ValidatePopulator(IIndex index)
{
if (_indexRebuilder.CanRebuild(indexName))
if (_indexRebuilder.CanRebuild(index))
return Request.CreateResponse(HttpStatusCode.OK);
var response = Request.CreateResponse(HttpStatusCode.BadRequest);
response.Content = new StringContent($"The index {indexName} cannot be rebuilt because it does not have an associated {typeof(IIndexPopulator)}");
response.Content = new StringContent($"The index {index.Name} cannot be rebuilt because it does not have an associated {typeof(IIndexPopulator)}");
response.ReasonPhrase = "Index cannot be rebuilt";
return response;
}

View File

@@ -62,7 +62,7 @@
<PackageReference Include="AutoMapper" Version="7.0.1" />
<PackageReference Include="ClientDependency" Version="1.9.7" />
<PackageReference Include="CSharpTest.Net.Collections" Version="14.906.1403.1082" />
<PackageReference Include="Examine" Version="1.0.0-beta059" />
<PackageReference Include="Examine" Version="1.0.0-beta060" />
<PackageReference Include="HtmlAgilityPack" Version="1.8.9" />
<PackageReference Include="ImageProcessor">
<Version>2.6.2.25</Version>