Copied to clipboard

Flag this post as spam?

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


  • Sorin Sandru 3 posts 73 karma points
    Sep 30, 2021 @ 14:27
    Sorin Sandru
    0

    Does examine search by culture?

    I'm trying to search my content tree for a set of tags that are specific to each culture. The problem i'm encountering is that my current query does not automatically search for alias fields with the current culture. If i do explicitly search for an alias with an appended culture it finds the content.

    var relatedArticleTags = Model.RelatedArticleTags?.ToArray() ?? new string[0];
        if (ExamineManager.Instance.TryGetIndex(Constants.UmbracoIndexes.ExternalIndexName, out var index))
        {
    
            var results = index.GetSearcher().CreateQuery()
                .NodeTypeAlias(Article.ModelTypeAlias)
                .And().GroupedOr(new string[] { Model.GetProperty("tags").Alias }, relatedArticleTags)
                .Not().Id(Model.Id).OrderBy(new SortableField("createDate", SortType.String))
                .Execute();
            foreach (var result in results)
            {
                var article = Umbraco.Content(result.Id);
                relatedArticleItems.Add(article);
            }
        }
    

    Is there a way for examine to automatically do searches on content by the current active culture?

  • Erik Eelman 69 posts 272 karma points
    Oct 01, 2021 @ 11:32
    Erik Eelman
    0

    Hi Sorin,

    You could pass the current culture to your search method. I believe you can get the current culture this way:

    content.GetCultureFromDomains() (where content is a IPublishedContnet)
    
  • Sorin Sandru 3 posts 73 karma points
    Oct 01, 2021 @ 12:14
    Sorin Sandru
    0

    I'm currently passing in a string to each filter where i manually combine the fieldname and culture.

    GroupedOr(new string[] { $"tags_{Model.GetCultureFromDomains().ToLower()}" }, relatedArticleTags)
    

    Or is there another way to actually pass the culture to Examine?

  • Erik Eelman 69 posts 272 karma points
    Oct 01, 2021 @ 12:20
    Erik Eelman
    0

    I'm not sure if there is another way of doing this, but if you need to search on multiple fields you can do something like this:

    string currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture.Name.ToLower();
    string searchFields = "nodeName,pageTitle_{0},metaDescription_{0}"
    terms = query.GroupedOr(String.Format(SearchFields, currentCulture).Split(','), searchTerm);
    

    The example is found on: https://skrift.io/issues/examine-in-umbraco-8/

Please Sign in or register to post replies

Write your reply to:

Draft