using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Examine; namespace Umbraco.Cms.Infrastructure.Search; public class UmbracoTreeSearcherFields : IUmbracoTreeSearcherFields { private readonly ISet _backOfficeDocumentFieldsToLoad = new HashSet { UmbracoExamineFieldNames.VariesByCultureFieldName }; private readonly ISet _backOfficeFieldsToLoad = new HashSet { "id", UmbracoExamineFieldNames.ItemIdFieldName, UmbracoExamineFieldNames.NodeKeyFieldName, "nodeName", UmbracoExamineFieldNames.IconFieldName, UmbracoExamineFieldNames.CategoryFieldName, "parentID", UmbracoExamineFieldNames.ItemTypeFieldName, }; private readonly ISet _backOfficeMediaFieldsToLoad = new HashSet { UmbracoExamineFieldNames.UmbracoFileFieldName }; private readonly ISet _backOfficeMembersFieldsToLoad = new HashSet { "email", "loginName" }; private readonly ILocalizationService _localizationService; private readonly IReadOnlyList _backOfficeFields = new List { "id", UmbracoExamineFieldNames.ItemIdFieldName, UmbracoExamineFieldNames.NodeKeyFieldName, }; private readonly IReadOnlyList _backOfficeMediaFields = new List { UmbracoExamineFieldNames.UmbracoFileFieldName }; private readonly IReadOnlyList _backOfficeMembersFields = new List { "email", "loginName" }; public UmbracoTreeSearcherFields(ILocalizationService localizationService) => _localizationService = localizationService; /// public virtual IEnumerable GetBackOfficeFields() => _backOfficeFields; /// public virtual IEnumerable GetBackOfficeMembersFields() => _backOfficeMembersFields; /// public virtual IEnumerable GetBackOfficeMediaFields() => _backOfficeMediaFields; /// public virtual IEnumerable GetBackOfficeDocumentFields() => Enumerable.Empty(); /// public virtual ISet GetBackOfficeFieldsToLoad() => _backOfficeFieldsToLoad; /// public virtual ISet GetBackOfficeMembersFieldsToLoad() => _backOfficeMembersFieldsToLoad; /// public virtual ISet GetBackOfficeMediaFieldsToLoad() => _backOfficeMediaFieldsToLoad; /// public virtual ISet GetBackOfficeDocumentFieldsToLoad() { ISet fields = _backOfficeDocumentFieldsToLoad; // We need to load all nodeName_* fields but we won't know those up front so need to get // all langs (this is cached) foreach (var field in _localizationService.GetAllLanguages() .Select(x => "nodeName_" + x.IsoCode.ToLowerInvariant())) { fields.Add(field); } fields.Add(UmbracoExamineFieldNames.PublishedFieldName); return fields; } }