From c0fa66799f8e81a3d32ccd56da5ee18189140938 Mon Sep 17 00:00:00 2001 From: arkadiuszbiel Date: Fri, 4 Oct 2019 16:41:29 +0200 Subject: [PATCH 1/4] Split config and index creator to allow to override only config not whole index creator --- src/Umbraco.Examine/IUmbracoIndexConfig.cs | 12 +++++++ src/Umbraco.Examine/Umbraco.Examine.csproj | 2 ++ .../UmbracoUmbracoIndexConfig.cs | 34 +++++++++++++++++++ src/Umbraco.Web/Search/ExamineComposer.cs | 1 + .../Search/UmbracoIndexesCreator.cs | 27 ++++----------- 5 files changed, 55 insertions(+), 21 deletions(-) create mode 100644 src/Umbraco.Examine/IUmbracoIndexConfig.cs create mode 100644 src/Umbraco.Examine/UmbracoUmbracoIndexConfig.cs diff --git a/src/Umbraco.Examine/IUmbracoIndexConfig.cs b/src/Umbraco.Examine/IUmbracoIndexConfig.cs new file mode 100644 index 0000000000..798c173f5c --- /dev/null +++ b/src/Umbraco.Examine/IUmbracoIndexConfig.cs @@ -0,0 +1,12 @@ +using Examine; + +namespace Umbraco.Examine +{ + public abstract class IUmbracoIndexConfig + { + public abstract IContentValueSetValidator GetContentValueSetValidator(); + public abstract IContentValueSetValidator GetPublishedContentValueSetValidator(); + public abstract IValueSetValidator GetMemberValueSetValidator(); + + } +} diff --git a/src/Umbraco.Examine/Umbraco.Examine.csproj b/src/Umbraco.Examine/Umbraco.Examine.csproj index e28a8e674e..2bfa810b45 100644 --- a/src/Umbraco.Examine/Umbraco.Examine.csproj +++ b/src/Umbraco.Examine/Umbraco.Examine.csproj @@ -64,9 +64,11 @@ + + diff --git a/src/Umbraco.Examine/UmbracoUmbracoIndexConfig.cs b/src/Umbraco.Examine/UmbracoUmbracoIndexConfig.cs new file mode 100644 index 0000000000..0a9b8607e8 --- /dev/null +++ b/src/Umbraco.Examine/UmbracoUmbracoIndexConfig.cs @@ -0,0 +1,34 @@ +using Examine; +using Umbraco.Core.Services; +using Umbraco.Core.Services.Implement; + +namespace Umbraco.Examine +{ + public class UmbracoUmbracoIndexConfig : IUmbracoIndexConfig + { + public UmbracoUmbracoIndexConfig(IPublicAccessService publicAccessService) + { + PublicAccessService = publicAccessService; + } + + protected IPublicAccessService PublicAccessService { get; } + public override IContentValueSetValidator GetContentValueSetValidator() + { + return new ContentValueSetValidator(false, true, PublicAccessService); + } + + public override IContentValueSetValidator GetPublishedContentValueSetValidator() + { + return new ContentValueSetValidator(true, false, PublicAccessService); + } + + /// + /// Returns the for the member indexer + /// + /// + public override IValueSetValidator GetMemberValueSetValidator() + { + return new MemberValueSetValidator(); + } + } +} diff --git a/src/Umbraco.Web/Search/ExamineComposer.cs b/src/Umbraco.Web/Search/ExamineComposer.cs index 0ade432d70..ee07e3dd1e 100644 --- a/src/Umbraco.Web/Search/ExamineComposer.cs +++ b/src/Umbraco.Web/Search/ExamineComposer.cs @@ -29,6 +29,7 @@ namespace Umbraco.Web.Search composition.Register(Lifetime.Singleton); composition.Register(Lifetime.Singleton); + composition.RegisterUnique(); composition.RegisterUnique(); composition.RegisterUnique(factory => new ContentValueSetBuilder( diff --git a/src/Umbraco.Web/Search/UmbracoIndexesCreator.cs b/src/Umbraco.Web/Search/UmbracoIndexesCreator.cs index 5ac5529be5..beecb85ae6 100644 --- a/src/Umbraco.Web/Search/UmbracoIndexesCreator.cs +++ b/src/Umbraco.Web/Search/UmbracoIndexesCreator.cs @@ -19,18 +19,20 @@ namespace Umbraco.Web.Search public UmbracoIndexesCreator(IProfilingLogger profilingLogger, ILocalizationService languageService, IPublicAccessService publicAccessService, - IMemberService memberService) + IMemberService memberService, IUmbracoIndexConfig umbracoIndexConfig) { ProfilingLogger = profilingLogger ?? throw new System.ArgumentNullException(nameof(profilingLogger)); LanguageService = languageService ?? throw new System.ArgumentNullException(nameof(languageService)); PublicAccessService = publicAccessService ?? throw new System.ArgumentNullException(nameof(publicAccessService)); MemberService = memberService ?? throw new System.ArgumentNullException(nameof(memberService)); + UmbracoIndexConfig = umbracoIndexConfig; } protected IProfilingLogger ProfilingLogger { get; } protected ILocalizationService LanguageService { get; } protected IPublicAccessService PublicAccessService { get; } protected IMemberService MemberService { get; } + protected IUmbracoIndexConfig UmbracoIndexConfig { get; } /// /// Creates the Umbraco indexes @@ -55,7 +57,7 @@ namespace Umbraco.Web.Search new CultureInvariantWhitespaceAnalyzer(), ProfilingLogger, LanguageService, - GetContentValueSetValidator()); + UmbracoIndexConfig.GetContentValueSetValidator()); return index; } @@ -68,7 +70,7 @@ namespace Umbraco.Web.Search new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), ProfilingLogger, LanguageService, - GetPublishedContentValueSetValidator()); + UmbracoIndexConfig.GetPublishedContentValueSetValidator()); return index; } @@ -80,28 +82,11 @@ namespace Umbraco.Web.Search CreateFileSystemLuceneDirectory(Constants.UmbracoIndexes.MembersIndexPath), new CultureInvariantWhitespaceAnalyzer(), ProfilingLogger, - GetMemberValueSetValidator()); + UmbracoIndexConfig.GetMemberValueSetValidator()); return index; } - - public virtual IContentValueSetValidator GetContentValueSetValidator() - { - return new ContentValueSetValidator(false, true, PublicAccessService); - } - public virtual IContentValueSetValidator GetPublishedContentValueSetValidator() - { - return new ContentValueSetValidator(true, false, PublicAccessService); - } - /// - /// Returns the for the member indexer - /// - /// - public virtual IValueSetValidator GetMemberValueSetValidator() - { - return new MemberValueSetValidator(); - } } } From 1ca35b2fbb91f9b48f32f014f5dab64900d800dd Mon Sep 17 00:00:00 2001 From: arkadiuszbiel Date: Sat, 5 Oct 2019 14:36:47 +0200 Subject: [PATCH 2/4] Obsolete instead of remove functions --- .../Search/UmbracoIndexesCreator.cs | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web/Search/UmbracoIndexesCreator.cs b/src/Umbraco.Web/Search/UmbracoIndexesCreator.cs index beecb85ae6..73b7343b16 100644 --- a/src/Umbraco.Web/Search/UmbracoIndexesCreator.cs +++ b/src/Umbraco.Web/Search/UmbracoIndexesCreator.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Core.Logging; using Umbraco.Core.Services; using Umbraco.Examine; @@ -57,7 +58,8 @@ namespace Umbraco.Web.Search new CultureInvariantWhitespaceAnalyzer(), ProfilingLogger, LanguageService, - UmbracoIndexConfig.GetContentValueSetValidator()); + GetContentValueSetValidator() + ); return index; } @@ -70,7 +72,7 @@ namespace Umbraco.Web.Search new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), ProfilingLogger, LanguageService, - UmbracoIndexConfig.GetPublishedContentValueSetValidator()); + GetPublishedContentValueSetValidator()); return index; } @@ -82,10 +84,30 @@ namespace Umbraco.Web.Search CreateFileSystemLuceneDirectory(Constants.UmbracoIndexes.MembersIndexPath), new CultureInvariantWhitespaceAnalyzer(), ProfilingLogger, - UmbracoIndexConfig.GetMemberValueSetValidator()); + GetMemberValueSetValidator() + ); return index; } + [Obsolete] + public virtual IContentValueSetValidator GetContentValueSetValidator() + { + return UmbracoIndexConfig.GetContentValueSetValidator(); + } + [Obsolete] + public virtual IContentValueSetValidator GetPublishedContentValueSetValidator() + { + return UmbracoIndexConfig.GetPublishedContentValueSetValidator(); + } + /// + /// Returns the for the member indexer + /// + /// + [Obsolete] + public virtual IValueSetValidator GetMemberValueSetValidator() + { + return UmbracoIndexConfig.GetMemberValueSetValidator(); + } } From 511751d1473a85fc19e01e958e66abbb2ea42e3c Mon Sep 17 00:00:00 2001 From: arkadiuszbiel Date: Thu, 10 Oct 2019 15:50:00 +0200 Subject: [PATCH 3/4] refactor based on shannon comments --- src/Umbraco.Examine/IUmbracoIndexConfig.cs | 8 ++++---- src/Umbraco.Examine/Umbraco.Examine.csproj | 2 +- ...racoUmbracoIndexConfig.cs => UmbracoIndexConfig.cs} | 10 +++++----- src/Umbraco.Web/Search/UmbracoIndexesCreator.cs | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) rename src/Umbraco.Examine/{UmbracoUmbracoIndexConfig.cs => UmbracoIndexConfig.cs} (65%) diff --git a/src/Umbraco.Examine/IUmbracoIndexConfig.cs b/src/Umbraco.Examine/IUmbracoIndexConfig.cs index 798c173f5c..02c6c51d0c 100644 --- a/src/Umbraco.Examine/IUmbracoIndexConfig.cs +++ b/src/Umbraco.Examine/IUmbracoIndexConfig.cs @@ -2,11 +2,11 @@ using Examine; namespace Umbraco.Examine { - public abstract class IUmbracoIndexConfig + public interface IUmbracoIndexConfig { - public abstract IContentValueSetValidator GetContentValueSetValidator(); - public abstract IContentValueSetValidator GetPublishedContentValueSetValidator(); - public abstract IValueSetValidator GetMemberValueSetValidator(); + IContentValueSetValidator GetContentValueSetValidator(); + IContentValueSetValidator GetPublishedContentValueSetValidator(); + IValueSetValidator GetMemberValueSetValidator(); } } diff --git a/src/Umbraco.Examine/Umbraco.Examine.csproj b/src/Umbraco.Examine/Umbraco.Examine.csproj index 2bfa810b45..e30d355dfe 100644 --- a/src/Umbraco.Examine/Umbraco.Examine.csproj +++ b/src/Umbraco.Examine/Umbraco.Examine.csproj @@ -68,7 +68,7 @@ - + diff --git a/src/Umbraco.Examine/UmbracoUmbracoIndexConfig.cs b/src/Umbraco.Examine/UmbracoIndexConfig.cs similarity index 65% rename from src/Umbraco.Examine/UmbracoUmbracoIndexConfig.cs rename to src/Umbraco.Examine/UmbracoIndexConfig.cs index 0a9b8607e8..7ad9c638d3 100644 --- a/src/Umbraco.Examine/UmbracoUmbracoIndexConfig.cs +++ b/src/Umbraco.Examine/UmbracoIndexConfig.cs @@ -4,20 +4,20 @@ using Umbraco.Core.Services.Implement; namespace Umbraco.Examine { - public class UmbracoUmbracoIndexConfig : IUmbracoIndexConfig + public class UmbracoIndexConfig : IUmbracoIndexConfig { - public UmbracoUmbracoIndexConfig(IPublicAccessService publicAccessService) + public UmbracoIndexConfig(IPublicAccessService publicAccessService) { PublicAccessService = publicAccessService; } protected IPublicAccessService PublicAccessService { get; } - public override IContentValueSetValidator GetContentValueSetValidator() + public IContentValueSetValidator GetContentValueSetValidator() { return new ContentValueSetValidator(false, true, PublicAccessService); } - public override IContentValueSetValidator GetPublishedContentValueSetValidator() + public IContentValueSetValidator GetPublishedContentValueSetValidator() { return new ContentValueSetValidator(true, false, PublicAccessService); } @@ -26,7 +26,7 @@ namespace Umbraco.Examine /// Returns the for the member indexer /// /// - public override IValueSetValidator GetMemberValueSetValidator() + public IValueSetValidator GetMemberValueSetValidator() { return new MemberValueSetValidator(); } diff --git a/src/Umbraco.Web/Search/UmbracoIndexesCreator.cs b/src/Umbraco.Web/Search/UmbracoIndexesCreator.cs index 73b7343b16..ec536b9d75 100644 --- a/src/Umbraco.Web/Search/UmbracoIndexesCreator.cs +++ b/src/Umbraco.Web/Search/UmbracoIndexesCreator.cs @@ -88,12 +88,12 @@ namespace Umbraco.Web.Search ); return index; } - [Obsolete] + [Obsolete("This method should not be used and will be removed in future versions. GetContentValueSetValidator was moved to IUmbracoIndexConfig")] public virtual IContentValueSetValidator GetContentValueSetValidator() { return UmbracoIndexConfig.GetContentValueSetValidator(); } - [Obsolete] + [Obsolete("This method should not be used and will be removed in future versions. GetPublishedContentValueSetValidator was moved to IUmbracoIndexConfig")] public virtual IContentValueSetValidator GetPublishedContentValueSetValidator() { return UmbracoIndexConfig.GetPublishedContentValueSetValidator(); @@ -103,7 +103,7 @@ namespace Umbraco.Web.Search /// Returns the for the member indexer /// /// - [Obsolete] + [Obsolete("This method should not be used and will be removed in future versions. GetMemberValueSetValidator was moved to IUmbracoIndexConfig")] public virtual IValueSetValidator GetMemberValueSetValidator() { return UmbracoIndexConfig.GetMemberValueSetValidator(); From a7412dfe79cc48888566d987c473daf8253a5cfe Mon Sep 17 00:00:00 2001 From: arkadiuszbiel Date: Thu, 10 Oct 2019 18:37:30 +0200 Subject: [PATCH 4/4] Correct name in DI --- src/Umbraco.Web/Search/ExamineComposer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web/Search/ExamineComposer.cs b/src/Umbraco.Web/Search/ExamineComposer.cs index ee07e3dd1e..b30f0cbe03 100644 --- a/src/Umbraco.Web/Search/ExamineComposer.cs +++ b/src/Umbraco.Web/Search/ExamineComposer.cs @@ -29,7 +29,7 @@ namespace Umbraco.Web.Search composition.Register(Lifetime.Singleton); composition.Register(Lifetime.Singleton); - composition.RegisterUnique(); + composition.RegisterUnique(); composition.RegisterUnique(); composition.RegisterUnique(factory => new ContentValueSetBuilder(