Copied to clipboard

Flag this post as spam?

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


  • HBSequence 6 posts 77 karma points
    Dec 16, 2019 @ 13:10
    HBSequence
    0

    Examine - Unpublished content - language variants

    Hello. I'd like to convert published and unpublished content in Umbraco to a strongly-typed model, using a singular approach.

    I'm exploring using the "Internal" Examine index to do this, which contains both published and unpublished data.

    Currently I read the property/value pairs returned from Examine, convert to JSON and the convert to a strongly-typed model.

    This is working, even for Nested Content properties.

    However, it does not work when I enabled Variants, as the property names returned by Examine then have a Culture suffix e.g. "department" becomes "department_fr-fr".

    Q. Is there a way to tell Examine to search using a specific Culture and return property names without the suffix?

    Is there a better way to achieve the requirements?

    Many thanks

    My current code is below:

            ISearcher searcher;
    
            if (_examineManager.TryGetIndex(Constants.UmbracoIndexes.InternalIndexName, out var index))
            {
                searcher = index.GetSearcher();
            }
            else
            {
                throw new ApplicationException("Could not create index.");
            }
    
            var criteria = searcher.CreateQuery("content").NodeTypeAlias("person").And().Field($"department_fr-fr", "FrenchCatering");
    
            var searchResults = criteria.Execute();
    
            if (searchResults.Any())
            {
                var searchResult = searchResults.FirstOrDefault();
    
                if (searchResult != null)
                {
                    var sourceDictionary = searchResult.Values;
                    var json = JsonConvert.SerializeObject(sourceDictionary);
                    result = JsonConvert.DeserializeObject<T>(json);
                }
            }
    
            return result;
        }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies