Gravatar for slangevin@coveo.com

Question by Simon, Jan 30, 2015 4:24 PM

Filtering languages using the .Net Web Service

Trying to set the preferred language to "ar-SA", and "Arabic", as well as the current Sitecore context language, but nothing seems to be working.

Here is a snippet

QueryParameters queryParams = new QueryParameters(); queryParams.CollectionNames = searchCollections; queryParams.BasicQuery = query; queryParams.PreferredLanguage = "ar-SA"; // Sitecore.Context.Language.Name;

StringBuilder advancedQuery = new StringBuilder();
..

QueryResults coveoResults = service.PerformQuery(queryParams);

I believe the core here is the queryParams.PreferredLanguage but I might be using the wrong field.

Any idea?

2 Replies
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Jan 30, 2015 5:51 PM

I don't think that the PreferredLanguage is the way to go to filter results based on a language. Do you have a field containing the language of your Sitecore items? If not, I suggest you add one through the mapping file. Then, just add an advanced query expression with @yourField=="ar-SA".

Gravatar for slangevin@coveo.com

Comment by Simon, Feb 4, 2015 9:26 AM

Little details, the assignement operator takes the friendly language name (ex: "English") as a parameter. So using the language code "ar-SA" might also be an issue.

Gravatar for jouimet@hansondodge.com

Answer by jouimet, Feb 3, 2015 12:04 PM

There has to be an out of the box way of doing this. When I use the .Net Front-End/Default Search Interface page, I am able to set the language to Arabic and only the Arabic pages are returned. How is it filtering out the non Arabic pages?

Gravatar for slangevin@coveo.com

Comment by Simon, Feb 3, 2015 5:15 PM

Using the .Net Interface Editor, the behavior is the same. If you use the Culture section, it uses PreferredLanguages underneath the cover, which only affect the ranking weight of the language, but does not filter anything.

The real way to filter out is using fields on the item. Sitecore uses the __Language field so you can refer to it in a mapping file to filter out the content.

Using the new Coveo for Sitecore, this field is pushed automatically to the index so it makes your life even easier.

Gravatar for slangevin@coveo.com

Comment by Simon, Feb 4, 2015 9:26 AM

I also commented on JF's answer above:

The assignment operator takes the friendly language name (ex: "English") as a parameter. So using the language code "ar-SA" might also be an issue.

Ask a question