Gravatar for hussaindotnet@gmail.com

Question by Hussain Shaik, Feb 21, 2017 6:49 AM

Include always english results in the final result even for user selected language is non english

we are having some content in different languages.if any query matches , then final result should include current user language and English results as well.

i am using JS framework only . Any references ?

1 Reply
Gravatar for sbelzile@coveo.com

Answer by Sébastien Belzile, Feb 21, 2017 8:02 AM

JS with Sitecore if I remember properly.

Using JS UI only: Your advanced query should include an expression with the field "syslanguage" (if you use CES 7) or the field "language" (Coveo Cloud V2). Ex; @language=="en". To detect the language of your user, you could use your browser functionalities (navigator.language) and simply inject it in your advanced expression.

C4SC: There is a property on the Coveo Search component to display only results in the user's language. You will need to uncheck that and code your own filter using the same method as above. The Sitecore context can provide the user language and help you fallback on another when you don't have any content in that language.

Different language code formats: en, en-US, fr-CA, fr-fr etc. is something that you need to care about, so the "==" operator might not be optimal. Refer to the query syntax to find something optimal that suits your needs. I would use something like: @language=(en,fr).

Gravatar for hussaindotnet@gmail.com

Comment by Hussain Shaik, Feb 21, 2017 8:27 AM

i am using coveo cloud V2 here with JS framework without any coveo component

Gravatar for sbelzile@coveo.com

Comment by Sébastien Belzile, Feb 21, 2017 8:36 AM

Yes, I know, but your search page is inside a Sitecore site, right? If so, you could take advantage of the Sitecore context even if you do not use the C4SC components.

Anyway, use only the JS part of my answer then. If it suits your needs, of course.

Gravatar for hussaindotnet@gmail.com

Comment by Hussain Shaik, Feb 21, 2017 10:32 AM

Thanks !!! That helps..

Gravatar for hussaindotnet@gmail.com

Comment by Hussain Shaik, Feb 22, 2017 3:40 AM

I am using the below query for getting results for en or fr. But no luck. Any issue in the below query?

args.queryBuilder.advancedExpression.addFieldExpression('@syssource', '=', [("en","fr")]);

Gravatar for hussaindotnet@gmail.com

Comment by Hussain Shaik, Feb 22, 2017 3:57 AM

I am using the below query to get the results in both FR or en. But i am getting only FR results not en. Any issue in the below query

args.queryBuilder.advancedExpression.addFieldExpression('@@syslanguage', '=', [("en","fr")]);
Gravatar for sbelzile@coveo.com

Comment by Sébastien Belzile, Feb 22, 2017 8:02 AM

If you look in the dev tools of your browser, what is the query being launched?

Gravatar for hussaindotnet@gmail.com

Comment by Hussain Shaik, Feb 22, 2017 9:05 AM

My Query

q:ariba
aq:(@syssource=="Coveo_web_index_local - AMRVWP000001409-BTodDevSite") (@language=fr)
language:en
firstResult:0
numberOfResults:10
excerptLength:200
enableDidYouMean:false
sortCriteria:relevancy
queryFunctions:[]
rankingFunctions:[]
groupBy:[]
retrieveFirstSentences:true
timezone:Asia/Kolkata
disableQuerySyntax:false
enableDuplicateFiltering:false
enableCollaborativeRating:false
debug:false
Gravatar for sbelzile@coveo.com

Comment by Sébastien Belzile, Feb 22, 2017 9:52 AM

(@language=fr) language:en

Does that make sense to you?

If you read this page: https://developers.coveo.com/display/public/JsSearchV1/Step+4+-+Modifying+the+Query, you should see the following syntax:

builder.advancedExpression.addFieldExpression('@fieldName', '==', ['firstFieldValue', 'secondFieldValue']);

(look at the brackets). You can also directly add the final expression that you want.

Gravatar for hussaindotnet@gmail.com

Comment by Hussain Shaik, Feb 22, 2017 10:15 AM

Yes, this query works correctly. Thanks a lot !!!

Ask a question