Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Luke Geddes 1 post 31 karma points
    Dec 01, 2021 @ 12:50
    Luke Geddes
    0

    V9 Examine Search Indexes - How do you update the field definition type?

    I want to update the field definition type of a field in the external index, how should this be done in V9?

    Previously in V8, we could use the FieldDefinitionColleciton where fields could be added/updated as per the Umbraco documentation:

        // add a custom field type
        index.FieldDefinitionCollection.TryAdd(new FieldDefinition("price", FieldDefinitionTypes.Double));
    
        // modify an existing field type (not recommended)
        index.FieldDefinitionCollection.AddOrUpdate(new FieldDefinition("parentID", FieldDefinitionTypes.FullText));
    

    The index field definitions are now a read only collection so can no longer be updated this way.

  • Andrey Karandashov 23 posts 215 karma points c-trib
    Dec 09, 2021 @ 14:57
    Andrey Karandashov
    0

    Not sure if this will be helpful for you, but I made a setup for the search in this project:

    https://github.com/Adolfi/UmbracoNineDemoSite/blob/master/UmbracoNineDemoSite.Core/Features/Search/Examine/Index/UmbracoContentComposer.cs

  • Gordon Saxby 1461 posts 1883 karma points
    May 23, 2022 @ 09:50
    Gordon Saxby
    0

    Sorry to jump in on an old post - but I am trying to figure out how I can expand the MembersIndex to include custom fields that I have added to the existing Member type.

    I got here from https://our.umbraco.com/forum/using-umbraco-and-getting-started/109029-custom-fields-not-in-member-examine-index which is my post asking about how to do this!

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Dec 10, 2021 @ 10:18
    Bjarne Fyrstenborg
    105

    Hi Luke

    The configuration of Examine indexes in Umbraco 9 / Examine 2 works different and is done with .NET’s Options pattern

    The documentation on Our https://our.umbraco.com/documentation/reference/searching/examine/indexing/ hasn't been updated for V9 yet, but Shannon has added some docs about it here: https://shazwazza.github.io/Examine/configuration (V1/V2)

    I also had a look in Umbraco core and found ConfigureIndexOptions https://github.com/umbraco/Umbraco-CMS/search?q=ConfigureIndexOptions

    I just tried this in a project to make nodeName field sortable, so I can sort employees alphabetically.

    /// <summary>
    /// Configures the index options to construct the Examine indexes
    /// </summary>
    public sealed class ConfigureIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
    {
        private readonly IUmbracoIndexConfig _umbracoIndexConfig;
        private readonly IOptions<IndexCreatorSettings> _settings;
    
        public ConfigureIndexOptions(
            IUmbracoIndexConfig umbracoIndexConfig,
            IOptions<IndexCreatorSettings> settings)
        {
            _umbracoIndexConfig = umbracoIndexConfig;
            _settings = settings;
        }
    
        public void Configure(string name, LuceneDirectoryIndexOptions options)
        {
            switch (name)
            {
                case Constants.UmbracoIndexes.ExternalIndexName:
                    options.FieldDefinitions.TryAdd(new FieldDefinition("nodeName", FieldDefinitionTypes.FullTextSortable));
                    break;
            }
        }
    
        public void Configure(LuceneDirectoryIndexOptions options)
            => Configure(string.Empty, options);
    }
    

    and then register the configuration in a composer:

    public class SearchComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
        {
            // Custom Examine configuration
            builder.Services.ConfigureOptions<ConfigureIndexOptions>();
    
            // Register services, etc.
        }
    }
    
  • David Armitage 508 posts 2078 karma points
    Mar 25, 2022 @ 05:26
    David Armitage
    0

    Thanks Bjarne - Saved me some time figuring that out there.

Please Sign in or register to post replies

Write your reply to:

Draft