Gravatar for dipsindol@gmail.com

Question by DEEPTHI KATTA, Oct 12, 2016 2:20 PM

__path with current item

Goal - To get only current context item descendants in search results. Using Pro edition, I understand the way to do this is to use __path variable, but, obviously I do not want to hardcode the GUID if the way to do this is to add a constant expression. My Coveo search renderings are on the page whose descendants I am ineterested in.

Also, assuming this would give all descendants and not just direct results

Can you throw some light on how we can get the current item GUID for comparision below? and if this is possible, if not other workarounds?

Coveo.$(function() {
    Coveo.$('#search')
    .on("buildingQuery", function(e, args) {
        args.queryBuilder.constantExpression.add('@(Model.ToCoveoFieldName("__path")) == "0de95ae441ab4d019eb067441b7c2450"');
    }).coveoForSitecore('init', CoveoForSitecore.componentsOptions);
});
Gravatar for dipsindol@gmail.com

Comment by DEEPTHI KATTA, Oct 17, 2016 8:26 PM

I got this to work using the below piece of code. Would like to know if there are implications on this or suggest any best practices -

   Coveo.$(function() {          
        Coveo.$('#search')
        .on("buildingQuery", function(e, args) {         

        args.queryBuilder.constantExpression.add('@@fz95xpath3686 ==  "@Sitecore.Context.Item.ID.ToShortID()"');
       }).coveoForSitecore('init', CoveoForSitecore.componentsOptions);
    });

Quick FYI to those this post would help. when I tried using @(Model.ToCoveoFieldName("__path")) instead of hardcoding the name I got from index, it resolved to a coveo field name that does not exist something like 'fz95xz95xpath3686'

As mentioned on other post use only one underscore to get correct path field that we need in this case like

args.queryBuilder.constantExpression.add('@(Model.ToCoveoFieldName("_path")) == "@Sitecore.Context.Item.ID.ToShortID()"');
Gravatar for ssartell@rightpoint.com

Comment by ssartell, Oct 17, 2016 10:54 PM

If you're looking to get children instead of all descendants, use "parent" instead of "path".

Gravatar for dipsindol@gmail.com

Comment by DEEPTHI KATTA, Oct 18, 2016 12:53 PM

Yeah, I understand that. For my requirements _path works fine. But, I was curious to see if there are any best practices coveo would recommend while accessing context item on their renderings? Any special methods inbuilt that I could use that have more handling?

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Oct 20, 2016 3:00 PM

Your code is what I would recommend. Getting the context item from Sitecore directly. However, you should try to fix your issue with ToCoveoFieldName as your @fz95xpath3686 field name will only work for the master or web index.

0 Reply
Ask a question