From 00c913d6217ecd9dfe16454d0f883cf034e328f4 Mon Sep 17 00:00:00 2001 From: abi Date: Thu, 2 Jan 2020 12:02:48 +0000 Subject: [PATCH 1/8] add InternalSearchConstants --- src/Umbraco.Web/InternalSearchConstants.cs | 32 +++++++++++++++++++ src/Umbraco.Web/Runtime/WebInitialComposer.cs | 2 +- .../Search/IInternalSearchConstants.cs | 13 ++++++++ src/Umbraco.Web/Search/UmbracoTreeSearcher.cs | 12 ++++--- src/Umbraco.Web/Umbraco.Web.csproj | 2 ++ 5 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 src/Umbraco.Web/InternalSearchConstants.cs create mode 100644 src/Umbraco.Web/Search/IInternalSearchConstants.cs diff --git a/src/Umbraco.Web/InternalSearchConstants.cs b/src/Umbraco.Web/InternalSearchConstants.cs new file mode 100644 index 0000000000..012cd98f1d --- /dev/null +++ b/src/Umbraco.Web/InternalSearchConstants.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using Umbraco.Examine; +using Umbraco.Web.Search; + +namespace Umbraco.Web +{ + public class InternalSearchConstants : IInternalSearchConstants + { + private List _backOfficeFields = new List {"id", "__NodeId", "__Key"}; + public List GetBackOfficeFields() + { + return _backOfficeFields; + } + + + private List _backOfficeMembersFields = new List {"email", "loginName"}; + public List GetBackOfficeMembersFields() + { + return _backOfficeMembersFields; + } + private List _backOfficeMediaFields = new List {UmbracoExamineIndex.UmbracoFileFieldName }; + public List GetBackOfficeMediaFields() + { + return _backOfficeMediaFields; + } + private List _backOfficeDocumentFields = new List (); + public List GetBackOfficeDocumentFields() + { + return _backOfficeDocumentFields; + } + } +} diff --git a/src/Umbraco.Web/Runtime/WebInitialComposer.cs b/src/Umbraco.Web/Runtime/WebInitialComposer.cs index 87c0f46fba..b8be2319d8 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComposer.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComposer.cs @@ -95,7 +95,7 @@ namespace Umbraco.Web.Runtime // a way to inject the UmbracoContext - DO NOT register this as Lifetime.Request since LI will dispose the context // in it's own way but we don't want that to happen, we manage its lifetime ourselves. composition.Register(factory => factory.GetInstance().UmbracoContext); - + composition.RegisterUnique(); composition.Register(factory => { var umbCtx = factory.GetInstance(); diff --git a/src/Umbraco.Web/Search/IInternalSearchConstants.cs b/src/Umbraco.Web/Search/IInternalSearchConstants.cs new file mode 100644 index 0000000000..72a37deaa1 --- /dev/null +++ b/src/Umbraco.Web/Search/IInternalSearchConstants.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace Umbraco.Web.Search +{ + public interface IInternalSearchConstants + { + List GetBackOfficeFields(); + List GetBackOfficeMembersFields(); + + List GetBackOfficeMediaFields(); + List GetBackOfficeDocumentFields(); + } +} diff --git a/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs b/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs index 463f4b09df..1345ffd4cc 100644 --- a/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs +++ b/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs @@ -28,13 +28,15 @@ namespace Umbraco.Web.Search private readonly IEntityService _entityService; private readonly UmbracoMapper _mapper; private readonly ISqlContext _sqlContext; + private readonly IInternalSearchConstants _internalSearchConstants; + public UmbracoTreeSearcher(IExamineManager examineManager, UmbracoContext umbracoContext, ILocalizationService languageService, IEntityService entityService, UmbracoMapper mapper, - ISqlContext sqlContext) + ISqlContext sqlContext,IInternalSearchConstants internalSearchConstants) { _examineManager = examineManager ?? throw new ArgumentNullException(nameof(examineManager)); _umbracoContext = umbracoContext; @@ -42,6 +44,7 @@ namespace Umbraco.Web.Search _entityService = entityService; _mapper = mapper; _sqlContext = sqlContext; + _internalSearchConstants = internalSearchConstants; } /// @@ -67,7 +70,7 @@ namespace Umbraco.Web.Search string type; var indexName = Constants.UmbracoIndexes.InternalIndexName; - var fields = new List { "id", "__NodeId", "__Key" }; + var fields = _internalSearchConstants.GetBackOfficeFields(); // TODO: WE should try to allow passing in a lucene raw query, however we will still need to do some manual string // manipulation for things like start paths, member types, etc... @@ -87,7 +90,7 @@ namespace Umbraco.Web.Search case UmbracoEntityTypes.Member: indexName = Constants.UmbracoIndexes.MembersIndexName; type = "member"; - fields.AddRange(new[]{ "email", "loginName"}); + fields.AddRange(_internalSearchConstants.GetBackOfficeMembersFields()); if (searchFrom != null && searchFrom != Constants.Conventions.MemberTypes.AllMembersListId && searchFrom.Trim() != "-1") { sb.Append("+__NodeTypeAlias:"); @@ -97,12 +100,13 @@ namespace Umbraco.Web.Search break; case UmbracoEntityTypes.Media: type = "media"; - fields.AddRange(new[] { UmbracoExamineIndex.UmbracoFileFieldName }); + fields.AddRange(_internalSearchConstants.GetBackOfficeMediaFields()); var allMediaStartNodes = _umbracoContext.Security.CurrentUser.CalculateMediaStartNodeIds(_entityService); AppendPath(sb, UmbracoObjectTypes.Media, allMediaStartNodes, searchFrom, ignoreUserStartNodes, _entityService); break; case UmbracoEntityTypes.Document: type = "content"; + fields.AddRange(_internalSearchConstants.GetBackOfficeDocumentFields()); var allContentStartNodes = _umbracoContext.Security.CurrentUser.CalculateContentStartNodeIds(_entityService); AppendPath(sb, UmbracoObjectTypes.Document, allContentStartNodes, searchFrom, ignoreUserStartNodes, _entityService); break; diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 5d29e53d4a..159abd435b 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -155,6 +155,7 @@ + @@ -249,6 +250,7 @@ + From 9614dcf0b08bcca001e423733e2dc7f2826a2de8 Mon Sep 17 00:00:00 2001 From: abi Date: Thu, 2 Jan 2020 13:20:32 +0000 Subject: [PATCH 2/8] move InternalSearchConstants to correct place in source code --- src/Umbraco.Web/{ => Search}/InternalSearchConstants.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/Umbraco.Web/{ => Search}/InternalSearchConstants.cs (100%) diff --git a/src/Umbraco.Web/InternalSearchConstants.cs b/src/Umbraco.Web/Search/InternalSearchConstants.cs similarity index 100% rename from src/Umbraco.Web/InternalSearchConstants.cs rename to src/Umbraco.Web/Search/InternalSearchConstants.cs From 575ec6fec4e5c0f2aa94a2d4efb216fddef54c18 Mon Sep 17 00:00:00 2001 From: abi Date: Thu, 2 Jan 2020 13:39:23 +0000 Subject: [PATCH 3/8] Correct project references --- src/Umbraco.Web/Umbraco.Web.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 159abd435b..0980b1b3d6 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -155,7 +155,6 @@ - @@ -251,6 +250,7 @@ + From 12f51dec4e6ee3c4b64719799066749feae04cd5 Mon Sep 17 00:00:00 2001 From: abi Date: Thu, 2 Jan 2020 23:00:53 +0000 Subject: [PATCH 4/8] Use immutable types --- .../Search/IInternalSearchConstants.cs | 10 +++++----- .../Search/InternalSearchConstants.cs | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Web/Search/IInternalSearchConstants.cs b/src/Umbraco.Web/Search/IInternalSearchConstants.cs index 72a37deaa1..06222e2ec7 100644 --- a/src/Umbraco.Web/Search/IInternalSearchConstants.cs +++ b/src/Umbraco.Web/Search/IInternalSearchConstants.cs @@ -4,10 +4,10 @@ namespace Umbraco.Web.Search { public interface IInternalSearchConstants { - List GetBackOfficeFields(); - List GetBackOfficeMembersFields(); - - List GetBackOfficeMediaFields(); - List GetBackOfficeDocumentFields(); + IEnumerable GetBackOfficeFields(); + IEnumerable GetBackOfficeMembersFields(); + + IEnumerable GetBackOfficeMediaFields(); + IEnumerable GetBackOfficeDocumentFields(); } } diff --git a/src/Umbraco.Web/Search/InternalSearchConstants.cs b/src/Umbraco.Web/Search/InternalSearchConstants.cs index 012cd98f1d..51e5df4c4e 100644 --- a/src/Umbraco.Web/Search/InternalSearchConstants.cs +++ b/src/Umbraco.Web/Search/InternalSearchConstants.cs @@ -6,25 +6,25 @@ namespace Umbraco.Web { public class InternalSearchConstants : IInternalSearchConstants { - private List _backOfficeFields = new List {"id", "__NodeId", "__Key"}; - public List GetBackOfficeFields() + private IReadOnlyList _backOfficeFields = new List {"id", "__NodeId", "__Key"}; + public IEnumerable GetBackOfficeFields() { return _backOfficeFields; } - private List _backOfficeMembersFields = new List {"email", "loginName"}; - public List GetBackOfficeMembersFields() + private IReadOnlyList _backOfficeMembersFields = new List {"email", "loginName"}; + public IEnumerable GetBackOfficeMembersFields() { return _backOfficeMembersFields; } - private List _backOfficeMediaFields = new List {UmbracoExamineIndex.UmbracoFileFieldName }; - public List GetBackOfficeMediaFields() + private IReadOnlyList _backOfficeMediaFields = new List {UmbracoExamineIndex.UmbracoFileFieldName }; + public IEnumerable GetBackOfficeMediaFields() { return _backOfficeMediaFields; } - private List _backOfficeDocumentFields = new List (); - public List GetBackOfficeDocumentFields() + private IReadOnlyList _backOfficeDocumentFields = new List (); + public IEnumerable GetBackOfficeDocumentFields() { return _backOfficeDocumentFields; } From 3b8e6d3cc05621c0c402b807902cf0e549e2d6e9 Mon Sep 17 00:00:00 2001 From: abi Date: Thu, 2 Jan 2020 23:05:08 +0000 Subject: [PATCH 5/8] rename to UmbracoTreeSearcherFields --- src/Umbraco.Web/Runtime/WebInitialComposer.cs | 6 +++--- ...hConstants.cs => IUmbracoTreeSearcherFields.cs} | 2 +- src/Umbraco.Web/Search/UmbracoTreeSearcher.cs | 14 +++++++------- ...chConstants.cs => UmbracoTreeSearcherFields.cs} | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) rename src/Umbraco.Web/Search/{IInternalSearchConstants.cs => IUmbracoTreeSearcherFields.cs} (86%) rename src/Umbraco.Web/Search/{InternalSearchConstants.cs => UmbracoTreeSearcherFields.cs} (93%) diff --git a/src/Umbraco.Web/Runtime/WebInitialComposer.cs b/src/Umbraco.Web/Runtime/WebInitialComposer.cs index b8be2319d8..cc6cdc1f60 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComposer.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComposer.cs @@ -73,7 +73,7 @@ namespace Umbraco.Web.Runtime // register accessors for cultures composition.RegisterUnique(); composition.RegisterUnique(); - + // register the http context and umbraco context accessors // we *should* use the HttpContextUmbracoContextAccessor, however there are cases when // we have no http context, eg when booting Umbraco or in background threads, so instead @@ -95,7 +95,7 @@ namespace Umbraco.Web.Runtime // a way to inject the UmbracoContext - DO NOT register this as Lifetime.Request since LI will dispose the context // in it's own way but we don't want that to happen, we manage its lifetime ourselves. composition.Register(factory => factory.GetInstance().UmbracoContext); - composition.RegisterUnique(); + composition.RegisterUnique(); composition.Register(factory => { var umbCtx = factory.GetInstance(); @@ -268,7 +268,7 @@ namespace Umbraco.Web.Runtime .Append() .Append() .Append(); - + // replace with web implementation composition.RegisterUnique(); diff --git a/src/Umbraco.Web/Search/IInternalSearchConstants.cs b/src/Umbraco.Web/Search/IUmbracoTreeSearcherFields.cs similarity index 86% rename from src/Umbraco.Web/Search/IInternalSearchConstants.cs rename to src/Umbraco.Web/Search/IUmbracoTreeSearcherFields.cs index 06222e2ec7..eaa5d743a1 100644 --- a/src/Umbraco.Web/Search/IInternalSearchConstants.cs +++ b/src/Umbraco.Web/Search/IUmbracoTreeSearcherFields.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; namespace Umbraco.Web.Search { - public interface IInternalSearchConstants + public interface IUmbracoTreeSearcherFields { IEnumerable GetBackOfficeFields(); IEnumerable GetBackOfficeMembersFields(); diff --git a/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs b/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs index 1345ffd4cc..56c7c6fbf3 100644 --- a/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs +++ b/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs @@ -28,7 +28,7 @@ namespace Umbraco.Web.Search private readonly IEntityService _entityService; private readonly UmbracoMapper _mapper; private readonly ISqlContext _sqlContext; - private readonly IInternalSearchConstants _internalSearchConstants; + private readonly IUmbracoTreeSearcherFields _umbracoTreeSearcherFields; public UmbracoTreeSearcher(IExamineManager examineManager, @@ -36,7 +36,7 @@ namespace Umbraco.Web.Search ILocalizationService languageService, IEntityService entityService, UmbracoMapper mapper, - ISqlContext sqlContext,IInternalSearchConstants internalSearchConstants) + ISqlContext sqlContext,IUmbracoTreeSearcherFields umbracoTreeSearcherFields) { _examineManager = examineManager ?? throw new ArgumentNullException(nameof(examineManager)); _umbracoContext = umbracoContext; @@ -44,7 +44,7 @@ namespace Umbraco.Web.Search _entityService = entityService; _mapper = mapper; _sqlContext = sqlContext; - _internalSearchConstants = internalSearchConstants; + _umbracoTreeSearcherFields = umbracoTreeSearcherFields; } /// @@ -70,7 +70,7 @@ namespace Umbraco.Web.Search string type; var indexName = Constants.UmbracoIndexes.InternalIndexName; - var fields = _internalSearchConstants.GetBackOfficeFields(); + var fields = _umbracoTreeSearcherFields.GetBackOfficeFields(); // TODO: WE should try to allow passing in a lucene raw query, however we will still need to do some manual string // manipulation for things like start paths, member types, etc... @@ -90,7 +90,7 @@ namespace Umbraco.Web.Search case UmbracoEntityTypes.Member: indexName = Constants.UmbracoIndexes.MembersIndexName; type = "member"; - fields.AddRange(_internalSearchConstants.GetBackOfficeMembersFields()); + fields.AddRange(_umbracoTreeSearcherFields.GetBackOfficeMembersFields()); if (searchFrom != null && searchFrom != Constants.Conventions.MemberTypes.AllMembersListId && searchFrom.Trim() != "-1") { sb.Append("+__NodeTypeAlias:"); @@ -100,13 +100,13 @@ namespace Umbraco.Web.Search break; case UmbracoEntityTypes.Media: type = "media"; - fields.AddRange(_internalSearchConstants.GetBackOfficeMediaFields()); + fields.AddRange(_umbracoTreeSearcherFields.GetBackOfficeMediaFields()); var allMediaStartNodes = _umbracoContext.Security.CurrentUser.CalculateMediaStartNodeIds(_entityService); AppendPath(sb, UmbracoObjectTypes.Media, allMediaStartNodes, searchFrom, ignoreUserStartNodes, _entityService); break; case UmbracoEntityTypes.Document: type = "content"; - fields.AddRange(_internalSearchConstants.GetBackOfficeDocumentFields()); + fields.AddRange(_umbracoTreeSearcherFields.GetBackOfficeDocumentFields()); var allContentStartNodes = _umbracoContext.Security.CurrentUser.CalculateContentStartNodeIds(_entityService); AppendPath(sb, UmbracoObjectTypes.Document, allContentStartNodes, searchFrom, ignoreUserStartNodes, _entityService); break; diff --git a/src/Umbraco.Web/Search/InternalSearchConstants.cs b/src/Umbraco.Web/Search/UmbracoTreeSearcherFields.cs similarity index 93% rename from src/Umbraco.Web/Search/InternalSearchConstants.cs rename to src/Umbraco.Web/Search/UmbracoTreeSearcherFields.cs index 51e5df4c4e..d1c663024b 100644 --- a/src/Umbraco.Web/Search/InternalSearchConstants.cs +++ b/src/Umbraco.Web/Search/UmbracoTreeSearcherFields.cs @@ -4,7 +4,7 @@ using Umbraco.Web.Search; namespace Umbraco.Web { - public class InternalSearchConstants : IInternalSearchConstants + public class UmbracoTreeSearcherFields : IUmbracoTreeSearcherFields { private IReadOnlyList _backOfficeFields = new List {"id", "__NodeId", "__Key"}; public IEnumerable GetBackOfficeFields() From 358b4c9133ac2f4a2cc45cff21cfbe325c3a57fd Mon Sep 17 00:00:00 2001 From: abi Date: Thu, 2 Jan 2020 23:08:53 +0000 Subject: [PATCH 6/8] Make fields list to allow to add fields --- src/Umbraco.Web/Search/UmbracoTreeSearcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs b/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs index 56c7c6fbf3..146177f86f 100644 --- a/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs +++ b/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs @@ -70,7 +70,7 @@ namespace Umbraco.Web.Search string type; var indexName = Constants.UmbracoIndexes.InternalIndexName; - var fields = _umbracoTreeSearcherFields.GetBackOfficeFields(); + var fields = _umbracoTreeSearcherFields.GetBackOfficeFields().ToList(); // TODO: WE should try to allow passing in a lucene raw query, however we will still need to do some manual string // manipulation for things like start paths, member types, etc... From d33928f4259b01e4045a46adf92c2356d7297406 Mon Sep 17 00:00:00 2001 From: abi Date: Fri, 3 Jan 2020 01:43:37 +0100 Subject: [PATCH 7/8] Correct project references --- src/Umbraco.Web/Umbraco.Web.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 0980b1b3d6..99eadef2bd 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -249,8 +249,8 @@ - - + + From 0d12852cd8520dd21c4e33136a93d4747506d816 Mon Sep 17 00:00:00 2001 From: abi Date: Tue, 21 Jan 2020 09:07:10 +0000 Subject: [PATCH 8/8] Address Shannon comments Add code documentation, return empty enumerable instead of allocate empty list --- .../Search/IUmbracoTreeSearcherFields.cs | 16 +++++++++++++++- .../Search/UmbracoTreeSearcherFields.cs | 7 +++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Web/Search/IUmbracoTreeSearcherFields.cs b/src/Umbraco.Web/Search/IUmbracoTreeSearcherFields.cs index eaa5d743a1..c5a6c53d19 100644 --- a/src/Umbraco.Web/Search/IUmbracoTreeSearcherFields.cs +++ b/src/Umbraco.Web/Search/IUmbracoTreeSearcherFields.cs @@ -2,12 +2,26 @@ using System.Collections.Generic; namespace Umbraco.Web.Search { + /// + /// Used to propagate hardcoded internal Field lists + /// public interface IUmbracoTreeSearcherFields { + /// + /// Propagate list of searchable fields for all node types + /// IEnumerable GetBackOfficeFields(); + /// + /// Propagate list of searchable fields for Members + /// IEnumerable GetBackOfficeMembersFields(); - + /// + /// Propagate list of searchable fields for Media + /// IEnumerable GetBackOfficeMediaFields(); + /// + /// Propagate list of searchable fields for Documents + /// IEnumerable GetBackOfficeDocumentFields(); } } diff --git a/src/Umbraco.Web/Search/UmbracoTreeSearcherFields.cs b/src/Umbraco.Web/Search/UmbracoTreeSearcherFields.cs index d1c663024b..f90d7bc6b6 100644 --- a/src/Umbraco.Web/Search/UmbracoTreeSearcherFields.cs +++ b/src/Umbraco.Web/Search/UmbracoTreeSearcherFields.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; +using System.Linq; using Umbraco.Examine; -using Umbraco.Web.Search; -namespace Umbraco.Web +namespace Umbraco.Web.Search { public class UmbracoTreeSearcherFields : IUmbracoTreeSearcherFields { @@ -23,10 +23,9 @@ namespace Umbraco.Web { return _backOfficeMediaFields; } - private IReadOnlyList _backOfficeDocumentFields = new List (); public IEnumerable GetBackOfficeDocumentFields() { - return _backOfficeDocumentFields; + return Enumerable.Empty(); } } }