Merge pull request #7400 from bielu/allow-override-internalsearch-constants
Add possibility to override internal hardcoded configs for backoffice search
This commit is contained in:
@@ -73,7 +73,7 @@ namespace Umbraco.Web.Runtime
|
||||
// register accessors for cultures
|
||||
composition.RegisterUnique<IDefaultCultureAccessor, DefaultCultureAccessor>();
|
||||
composition.RegisterUnique<IVariationContextAccessor, HybridVariationContextAccessor>();
|
||||
|
||||
|
||||
// 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<IUmbracoContextAccessor>().UmbracoContext);
|
||||
|
||||
composition.RegisterUnique<IUmbracoTreeSearcherFields, UmbracoTreeSearcherFields>();
|
||||
composition.Register<IPublishedContentQuery>(factory =>
|
||||
{
|
||||
var umbCtx = factory.GetInstance<IUmbracoContextAccessor>();
|
||||
@@ -268,7 +268,7 @@ namespace Umbraco.Web.Runtime
|
||||
.Append<Issuu>()
|
||||
.Append<Hulu>()
|
||||
.Append<Giphy>();
|
||||
|
||||
|
||||
|
||||
// replace with web implementation
|
||||
composition.RegisterUnique<IPublishedSnapshotRebuilder, Migrations.PostMigrations.PublishedSnapshotRebuilder>();
|
||||
|
||||
27
src/Umbraco.Web/Search/IUmbracoTreeSearcherFields.cs
Normal file
27
src/Umbraco.Web/Search/IUmbracoTreeSearcherFields.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Umbraco.Web.Search
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to propagate hardcoded internal Field lists
|
||||
/// </summary>
|
||||
public interface IUmbracoTreeSearcherFields
|
||||
{
|
||||
/// <summary>
|
||||
/// Propagate list of searchable fields for all node types
|
||||
/// </summary>
|
||||
IEnumerable<string> GetBackOfficeFields();
|
||||
/// <summary>
|
||||
/// Propagate list of searchable fields for Members
|
||||
/// </summary>
|
||||
IEnumerable<string> GetBackOfficeMembersFields();
|
||||
/// <summary>
|
||||
/// Propagate list of searchable fields for Media
|
||||
/// </summary>
|
||||
IEnumerable<string> GetBackOfficeMediaFields();
|
||||
/// <summary>
|
||||
/// Propagate list of searchable fields for Documents
|
||||
/// </summary>
|
||||
IEnumerable<string> GetBackOfficeDocumentFields();
|
||||
}
|
||||
}
|
||||
@@ -28,13 +28,15 @@ namespace Umbraco.Web.Search
|
||||
private readonly IEntityService _entityService;
|
||||
private readonly UmbracoMapper _mapper;
|
||||
private readonly ISqlContext _sqlContext;
|
||||
private readonly IUmbracoTreeSearcherFields _umbracoTreeSearcherFields;
|
||||
|
||||
|
||||
public UmbracoTreeSearcher(IExamineManager examineManager,
|
||||
UmbracoContext umbracoContext,
|
||||
ILocalizationService languageService,
|
||||
IEntityService entityService,
|
||||
UmbracoMapper mapper,
|
||||
ISqlContext sqlContext)
|
||||
ISqlContext sqlContext,IUmbracoTreeSearcherFields umbracoTreeSearcherFields)
|
||||
{
|
||||
_examineManager = examineManager ?? throw new ArgumentNullException(nameof(examineManager));
|
||||
_umbracoContext = umbracoContext;
|
||||
@@ -42,6 +44,7 @@ namespace Umbraco.Web.Search
|
||||
_entityService = entityService;
|
||||
_mapper = mapper;
|
||||
_sqlContext = sqlContext;
|
||||
_umbracoTreeSearcherFields = umbracoTreeSearcherFields;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,7 +70,7 @@ namespace Umbraco.Web.Search
|
||||
|
||||
string type;
|
||||
var indexName = Constants.UmbracoIndexes.InternalIndexName;
|
||||
var fields = new List<string> { "id", "__NodeId", "__Key" };
|
||||
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...
|
||||
@@ -87,7 +90,7 @@ namespace Umbraco.Web.Search
|
||||
case UmbracoEntityTypes.Member:
|
||||
indexName = Constants.UmbracoIndexes.MembersIndexName;
|
||||
type = "member";
|
||||
fields.AddRange(new[]{ "email", "loginName"});
|
||||
fields.AddRange(_umbracoTreeSearcherFields.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(_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(_umbracoTreeSearcherFields.GetBackOfficeDocumentFields());
|
||||
var allContentStartNodes = _umbracoContext.Security.CurrentUser.CalculateContentStartNodeIds(_entityService);
|
||||
AppendPath(sb, UmbracoObjectTypes.Document, allContentStartNodes, searchFrom, ignoreUserStartNodes, _entityService);
|
||||
break;
|
||||
|
||||
31
src/Umbraco.Web/Search/UmbracoTreeSearcherFields.cs
Normal file
31
src/Umbraco.Web/Search/UmbracoTreeSearcherFields.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Examine;
|
||||
|
||||
namespace Umbraco.Web.Search
|
||||
{
|
||||
public class UmbracoTreeSearcherFields : IUmbracoTreeSearcherFields
|
||||
{
|
||||
private IReadOnlyList<string> _backOfficeFields = new List<string> {"id", "__NodeId", "__Key"};
|
||||
public IEnumerable<string> GetBackOfficeFields()
|
||||
{
|
||||
return _backOfficeFields;
|
||||
}
|
||||
|
||||
|
||||
private IReadOnlyList<string> _backOfficeMembersFields = new List<string> {"email", "loginName"};
|
||||
public IEnumerable<string> GetBackOfficeMembersFields()
|
||||
{
|
||||
return _backOfficeMembersFields;
|
||||
}
|
||||
private IReadOnlyList<string> _backOfficeMediaFields = new List<string> {UmbracoExamineIndex.UmbracoFileFieldName };
|
||||
public IEnumerable<string> GetBackOfficeMediaFields()
|
||||
{
|
||||
return _backOfficeMediaFields;
|
||||
}
|
||||
public IEnumerable<string> GetBackOfficeDocumentFields()
|
||||
{
|
||||
return Enumerable.Empty<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -249,6 +249,8 @@
|
||||
<Compile Include="Search\ExamineFinalComponent.cs" />
|
||||
<Compile Include="Search\ExamineFinalComposer.cs" />
|
||||
<Compile Include="Search\ExamineUserComponent.cs" />
|
||||
<Compile Include="Search\IUmbracoTreeSearcherFields.cs" />
|
||||
<Compile Include="Search\UmbracoTreeSearcherFields.cs" />
|
||||
<Compile Include="Services\DashboardService.cs" />
|
||||
<Compile Include="Services\IDashboardService.cs" />
|
||||
<Compile Include="Models\Link.cs" />
|
||||
|
||||
Reference in New Issue
Block a user