London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Filter content by language

Vote:
 

Hi Team,
I want to filter page by exiting languages . 

The below method always retrnng me null value. 

Is the any thing wrong with my query.

 public T GetPageData<T>() where T:PageData
        {
          
            return this.searchClient.Search<T>()
                .Filter(x => x.ExistingLanguages.Select(y => y.Name).MatchContained(z => z, "en"))
                .GetContentResult().Items.FirstOrDefault();
        }

I am using the latest verion of Find

 <package id="EPiServer.Find" version="13.0.5" targetFramework="net472" />
Regards
Phani

#207312
Sep 17, 2019 8:08
Vote:
 

The easiest way would be just to just use the build in filter called FilterOnLanguages

 public T GetPageData<T>() where T:PageData
        {
          
            return this.searchClient.Search<T>()
              	.FilterOnLanguages(new List<string>(){"en"})
                .GetContentResult().Items.FirstOrDefault();
        }

#207320
Sep 17, 2019 9:12
Vote:
 

Hi  Anders,

Thanks for your quick response. 

I found the issue .

The property   ExistingLanguage is not indexed in  EPiFind. However there was an extension method  ExistingLanguage()  has been indexed .

If you want to filter on languages then the below code also works :).

   public T GetPageData<T>() where T:PageData
        {
           return this.searchClient.Search<T>().Filter(x => x.ExistingLanguages().MatchCaseInsensitive("en")).GetContentResult().Items.FirstOrDefault();
        }

Now we have two solutions for filtering content on lanaguages. 

Regards

Phani 

#207324
Sep 17, 2019 9:26
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.