Try our conversational search powered by Generative AI!

Language fallback for indexed non-Episerver content not working

Vote:
 

Hello,

I'm indexing non-Episerver objects, and I would like these objects to be indexed in two language versions. Most fields are the same, but the SearchSection, used for a facet in the search results, is different for the two languages. The requirement is that when searching from the Dutch search page only the Dutch items are returned, and when searching from the English search page only English items are returned. I'm using UnifiedSearch, with a fallback to Dutch, which works well for the Episerver content, i.e. if content does not exist in English the Dutch content is returned in the search results, when searching from the English search page. 

The problem is that the non-Episerver objects are always returned in both languages, on both the Dutch and the English search page, i.e. for these items the fallback doesn't not seem to be working.

The non-Episerver objects are pushed to the index separately, in an English and a Dutch version, with the same ID. I have noticed that when I set the MasterLanguage property to different languages (English and Dutch) both versions get separate entries in the index, even though they get the same ID. In my site Dutch is the MasterLanguage. If I push both versions with the same ID and the same MasterLanguage, the version which was pushed first is overwritten by the version which was pushed last.

How can I get the behaviour I want, i.e. separate items in the index for Dutch and English versions, in such a way that only the English items are returned when searching from the English search page? I.e. which properties with which values do I need to add to the class representing the non-Episerver content?

#204836
Jun 19, 2019 15:45
Vote:
 

Hi John, 

I've done similar in the past, where I have made my non episerver content types implement ILocalizable. 

This will then allow you to use FilterOnLanguages when you filter your content by either Dutch or English. 

public static ITypeSearch<T> FilterOnLanguages<T>(this ITypeSearch<T> search, IEnumerable<string> languages)
    {
      if (languages == null)
        return search;
      FilterBuilder<IContentSecurable> filterBuilder = new FilterBuilder<IContentSecurable>(search.Client);
      foreach (string language1 in languages)
      {
        string language = language1;
        filterBuilder = filterBuilder.Or((Expression<Func<IContentSecurable, Filter>>) (x => ((ILocalizable) x).Language.Name.Match(language)));
      }
      return search.Filter<T>((Filter) filterBuilder);
    }

Hope this helps.

Paul 

#204935
Jun 21, 2019 12:25
Vote:
 

Hi Paul,

Thanks for your reply. The problem is that the client wants a fallback on Dutch for content which is not translated in English, so if I use FilterOnLanguages I lose the fallback.

#204936
Jun 21, 2019 12:44
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.