Exclude properies from the default indexs?
# help-with-umbraco
m
Is there a way to mark certain properties as excluded from the default internal and external indexes? Some properties are for house keeping only and don't/won't/should not be searched on so I would like to exclude them from indexing to help speed up indexd building and reduce db/search overhead
j
This file is where the standard config is set: https://github.com/umbraco/Umbraco-CMS/blob/release-13.4.1/src/Umbraco.Infrastructure/Examine/UmbracoIndexConfig.cs You can see that the contentValueSetValidator has a list of excludeFields in its ctor which is null in the default implementation: https://github.com/umbraco/Umbraco-CMS/blob/release-13.4.1/src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs#L45 So long storry short, you can add a composer where you register the index config yourself:
Copy code
csharp
public class ExamineComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        builder.Services.AddSingleton<IUmbracoIndexConfig, ContentIndexConfig>();
    }
}
And then you can add your own where you fx exclude a few fields from the internal index:
Copy code
csharp
public class ContentIndexConfig : IUmbracoIndexConfig
{
    private readonly IPublicAccessService _publicAccessService;
    private readonly IScopeProvider _scopeProvider;

    public ContentIndexConfig(
        IPublicAccessService publicAccessService,
        IScopeProvider scopeProvider
    )
    {
        _publicAccessService = publicAccessService;
        _scopeProvider = scopeProvider;
    }

    // The internal index
    public IContentValueSetValidator GetContentValueSetValidator()
    {
        IEnumerable<string> excludeFields = ["field1", "field2"];

        return new ContentValueSetValidator(
            false,
            true,
            _publicAccessService,
            _scopeProvider,
            null,
            null,
            null,
            null,
            excludeFields
        );
    }

    public IContentValueSetValidator GetPublishedContentValueSetValidator() =>
        new ContentValueSetValidator(true, true, _publicAccessService, _scopeProvider);

    public IValueSetValidator GetMemberValueSetValidator() => new MemberValueSetValidator();
}
m
Thanks, can this be adapted to work with the external index as well? I don't see how it is specifying the internal in the code so not sure what to copy/update to inlcude external.
j
The
GetContentValueSetValidator
is used by the internal index and the
GetPublishedContentValueSetValidator
is used by the external index 🙂
m
Cool. Thanks for all the info.
2 Views