Poornima Nayar
11/01/2023, 11:10 AMJemayn
11/01/2023, 11:40 AMMike Chambers
11/01/2023, 12:02 PMContentValueSetValidator
, has include/exclude field support now?
The IValueSetValidator is also responsible for filtering the data in the ValueSet. For example, by default the validator for the MemberIndex will validate on all the default member properties, so an extra property "PhoneNumber", would not pass validation, and therefore not be included.
https://github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs
csharp
public ContentValueSetValidator(
bool publishedValuesOnly,
bool supportProtectedContent,
IPublicAccessService? publicAccessService,
IScopeProvider? scopeProvider,
int? parentId = null,
IEnumerable<string>? includeItemTypes = null,
IEnumerable<string>? excludeItemTypes = null,
IEnumerable<string>? includeFields = null,
IEnumerable<string>? excludeFields = null)
: base(includeItemTypes, excludeItemTypes, includeFields, excludeFields)
{
So should be able to use the
csharp
IConfigureNamedOptions<LuceneDirectoryIndexOptions>
{
public void Configure(string? name, LuceneDirectoryIndexOptions options)
{
switch (name)
{
//NB you need to rebuild the examine index for these changes to take effect
case Constants.UmbracoIndexes.ExternalIndexName:
options.Validator = new ContentValueSetValidator(true, true, _publicAccessService, _scopeProvider, {included fields}, {excluded fields});
break;
}
}
}
????Jemayn
11/01/2023, 12:04 PMMike Chambers
11/01/2023, 12:07 PMFieldDefintions.TryRemove()
though though prob a reason why you can add/alter to the readonly collection.. but not remove. 😉Mike Chambers
11/01/2023, 12:08 PMPoornima Nayar
11/01/2023, 12:11 PMPoornima Nayar
11/01/2023, 12:12 PMPoornima Nayar
11/01/2023, 12:12 PMMike Chambers
11/01/2023, 12:14 PMMike Chambers
11/01/2023, 12:15 PMjson
"Umbraco": {
"CMS": {
"Indexing": {
"ExplicitlyIndexEachNestedProperty": true
}
}
}
Poornima Nayar
11/01/2023, 12:15 PMMike Chambers
11/01/2023, 12:17 PMJemayn
11/01/2023, 12:20 PMcsharp
var rawValuesDictionary = e.ValueSet.Values?.ToDictionary(
x => x.Key,
x => x.Value.ToList());
var valuesDictionary = rawValuesDictionary?.Where(
x => !x.Key.Contains("items[")).ToDictionary(
x => x.Key, x => x.Value);
e.SetValues(valuesDictionary?.ToDictionary(
x => x.Key,
x => (IEnumerable<object>)x.Value));
So I just use linq to go through fields containing a string and remove themPoornima Nayar
11/01/2023, 12:21 PMPoornima Nayar
11/01/2023, 12:21 PMPoornima Nayar
11/01/2023, 12:23 PMMike Chambers
11/01/2023, 12:26 PMPoornima Nayar
11/01/2023, 12:27 PMMike Chambers
11/01/2023, 12:29 PMPoornima Nayar
11/01/2023, 12:30 PMPoornima Nayar
11/01/2023, 12:31 PMPoornima Nayar
11/01/2023, 12:32 PMMike Chambers
11/01/2023, 12:34 PMcsharp
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.PropertyEditors;
namespace Umbraco.Cms.Web.UI.Custom;
public class MyBlockValuePropertyIndexValueFactory : DefaultPropertyIndexValueFactory, IBlockValuePropertyIndexValueFactory
{
}
public class MyBlockValuePropertyIndexValueFactoryComposer : IComposer
{
public void Compose(IUmbracoBuilder builder) => builder.Services.AddSingleton<IBlockValuePropertyIndexValueFactory, MyBlockValuePropertyIndexValueFactory>();
}
I think this would allow you to alter how a block value would write into the index? though maybe not remove the actual property?Poornima Nayar
11/01/2023, 12:48 PMPoornima Nayar
11/01/2023, 12:49 PMPoornima Nayar
11/01/2023, 12:56 PMPoornima Nayar
11/01/2023, 1:20 PMPoornima Nayar
11/01/2023, 1:20 PMPoornima Nayar
11/06/2023, 2:56 PM