Copied to clipboard

Flag this post as spam?

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


  • Jimmy 31 posts 147 karma points
    Apr 29, 2020 @ 11:30
    Jimmy
    0

    Search Examine only get results from current language

    Hi,

    I have a site in V8 with 2 languages.

    I use Examine to make a search, like this

     var results = searcher.CreateQuery("content").ManagedQuery(s).And().GroupedOr(new[] { "__NodeTypeAlias" }, new[] { "contentPage", "home" }).Execute();
    

    But i get results from both the english and danish. Is there anyway to only search one of the lanuages, so when a user search form the danish site, only danish results show up, and the same for the english?

    Best regards

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Apr 29, 2020 @ 12:03
    Nik
    0

    Hi Jimmy,

    The simple answer is yes, the complex answer is, you need to explicitly specify the fields to search in to limit the search to those explicit fields.

    Nik

  • Jimmy 31 posts 147 karma points
    Apr 29, 2020 @ 13:15
    Jimmy
    0

    Thanks Nik

    I ended up doing something like this

    var currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture.Name.ToString().ToLower();
    var textFields = new[] { "midterGrid.Indhold_" + currentCulture, "venstreGrid.Indhold_" + currentCulture, "hojreGrid.Indhold_" + currentCulture };
    var results = searcher.CreateQuery("content").GroupedOr(new[] { "__NodeTypeAlias" }, new[] { "contentPage", "home" }).And().GroupedOr(textFields, s).Execute();
    
Please Sign in or register to post replies

Write your reply to:

Draft