Gravatar for ahmedokour86@gmail.com

Question by aokour, Oct 27, 2014 9:46 AM

Setting start location for search using javascript framework

Hi, I'm using the free version of (Coveo for Sitecore), and I'm trying to add a start location for the search results, by using the following code:

 Coveo.$(function() {
            Coveo.$('#search').coveoForSitecore('init', CoveoForSitecore.componentsOptions);
            Coveo.$('#search').on('buildingQuery', function (e,args){
                args.queryBuilder.advancedExpression.addFieldExpression("<%= ToCoveoFieldName("_fullpath") %>","==", ["/sitecore/content/home*"]);
            });
        });

It does not work, and the results are 0

Any idea where i went wrong?

UPDATE: I tried also the following, with no luck:

args.queryBuilder.constantExpression.add(" <%= ToCoveoFieldName("_path") %> *= \"/D6507DFE-6178-43B7-B549-C4363800935C\"");
2 Replies
Gravatar for slangevin@coveo.com

Answer by Simon, Jul 14, 2015 7:14 AM

The answer is on this related post: https://answers.coveo.com/questions/1197/sitecore-advanced-queries-for-filtering

Gravatar for glaporte@coveo.com

Answer by Gregory Laporte, Oct 27, 2014 11:17 AM

Hi,

Seems like you have an issue with quoting:

args.queryBuilder.advancedExpression.addFieldExpression('"<%= ToCoveoFieldName("_fullpath") %>","==", ["/sitecore/content/home*"]');

You should remove the single quote at the beginning and at the end. The addFieldExpression method takes 3 string parameters. (Field, operator, values). Also, since you want to do a wildcard operation, you should use "*=" as an operator.

Another thing here, the buildingQuery listener should be done before initialization. That way, you will make sure that it's listening to the first query.

Thanks!

Gravatar for ahmedokour86@gmail.com

Comment by aokour, Oct 27, 2014 12:21 PM

Ok, i did everything you said, but still no luck, i tried the following also: args.queryBuilder.advancedExpression.addFieldExpression("<%= ToCoveoFieldName("longid") %>","=", ["D6507DFE-6178-43B7-B549-C4363800935C*"]);

But no results came back, Do you have a working example of this?

Thanks

Gravatar for vseguin@coveo.com

Comment by Vincent Séguin, Oct 27, 2014 1:24 PM

Hi,

Can you try with this : args.queryBuilder.advancedExpression.add("<%= ToCoveoFieldName("longid") %>= "D6507DFE-6178-43B7-B549-C4363800935C");

Gravatar for glaporte@coveo.com

Comment by Gregory Laporte, Oct 27, 2014 1:48 PM

Can you try *= instead of =. It's a wildcard operator.

Gravatar for ahmedokour86@gmail.com

Comment by aokour, Oct 28, 2014 6:11 AM

Tried that and didn't work

Gravatar for vseguin@coveo.com

Comment by Vincent Séguin, Oct 28, 2014 7:40 AM

In that case, i recommand you open a support ticket, it will be way easier to troubleshoot it live.

Gravatar for ahmedokour86@gmail.com

Comment by aokour, Oct 28, 2014 7:44 AM

Thanks for the help, I will open a ticket

Gravatar for vseguin@coveo.com

Comment by Vincent Séguin, Oct 28, 2014 8:12 AM

Just to make sure, you don't have any '*' in your query, especially at the end of the GUID right?

Gravatar for ahmedokour86@gmail.com

Comment by aokour, Oct 28, 2014 9:50 AM

Yes i did, tried the following also;

args.queryBuilder.advancedExpression.add("<%= ToCoveoFieldName("longid") %> *= \"/{11111111-1111-1111-1111-111111111111}\"");

Nothing returned

Ask a question