https://discord.umbraco.com logo
#help-with-umbraco
Umbraco Tags with spaces on a multi language site?
# help-with-umbraco
j

JigitalCharlie

10/16/2023, 3:57 PM
I have an interesting problem. I have a tagging system and the content editor would like to add spaces in the tag I.E 'News and Views' and then another tag 'Health and Fitness' In the Index this is stored as News and Views, Health and Fitness so i cannot do a .exact on the string when searching? Also if i try to create my own on index field i need the language variation which i cannot get access to from within the IComponent. Any ideas?
I think has support for tags..
But also be aware depending on the examine/lucene analyzer.. stopwords like
and
won't be indexed..
Copy code
csharp
        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.Analyzer = new CultureInvariantStandardAnalyzer(CharArraySet.EMPTY_SET);
...
}
}
you can override the index to stop, the stop words but that might have unitended consequences.
you might have to add custom fields for each tag and set as raw so that examine/lucene leaves things alone. eg you end up with tag_0 : News and Views : type:raw tag_1 : Health and Fitness : type:raw And then you can use string.Escape() to phrase match against the raw field ??
Quick look at searchExtensions.. and think it introduces a listValueType.. (used for path) perhaps you'd have mileage with your tag property by setting in your custom indexoptions? https://github.com/callumbwhyte/umbraco-search-extensions/blob/dev/src/Our.Umbraco.Extensions.Search/ValueTypes/ListValueType.cs
Copy code
csharp
 public void Configure(string name, LuceneDirectoryIndexOptions options)
        {
            options.IndexValueTypesFactory = new Dictionary<string, IFieldValueTypeFactory>
            {
                { "json", new DelegateFieldValueTypeFactory(fieldName => new JsonValueType(fieldName, _loggerFactory)) },
                { "list", new DelegateFieldValueTypeFactory(fieldName => new ListValueType(fieldName, _loggerFactory)) },
                { "picker", new DelegateFieldValueTypeFactory(fieldName => new PickerValueType(fieldName, _loggerFactory)) },
                { "udi", new DelegateFieldValueTypeFactory(fieldName => new UdiValueType(fieldName, _loggerFactory)) },
            };

            options.FieldDefinitions.AddOrUpdate(new FieldDefinition("path", "list"));

            options.FieldDefinitions.AddOrUpdate(new FieldDefinition("createDate", "date"));

            options.FieldDefinitions.AddOrUpdate(new FieldDefinition("updateDate", "date"));
        }
https://github.com/callumbwhyte/umbraco-search-extensions/blob/dev/src/Our.Umbraco.Extensions.Search/Composing/ConfigureIndexOptions.cs
looking at something completely different.. and came across.. https://github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Core/PropertyEditors/TagPropertyIndexValueFactory.cs#L17 .. might mean in later version of umb you already get the separated out fields for tags?
j

JigitalCharlie

10/17/2023, 11:31 AM
Thanks @mistyn8 very useful 😄
Yea i thought about the Tag_0 ect but really not keen
p

paulo_webreality

11/22/2023, 10:10 AM
Hi @mistyn8 - When you change the Analyzer for your index, did it update the table in the backoffice? I'm doing that on a site but when I check the Analyzer in the Examine table, it still shows "StandardAnalyzer"
p

paulo_webreality

11/22/2023, 10:44 AM
I tried that, but it's not changing for me... Thanks. Just highlights that there's a bug somewhere in my code/Umbraco version!
m

mistyn8

11/22/2023, 11:53 AM
have you added a composer to register the
LuceneDirectoryIndexOptions
Copy code
csharp
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;

namespace Umbraco.Docs.Samples.Web.CustomIndexing;
{
    public class ExamineComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
        {
            builder.Services.ConfigureOptions<ConfigureExternalIndexOptions>();
        }
    }
}
https://docs.umbraco.com/umbraco-cms/reference/searching/examine/indexing