Gravatar for erkan.yildiz@avanade.com

Question by erkany, Feb 2, 2015 3:53 PM

Is it possible to set a relative path for search results ClickURI

Hi,

As suggested I am using CoveoPostItemProcessing pipeline and modifying the default clickURI like this:

… p_Args.CoveoItem.ClickableUri = "/about/company-history" ; …

I see that when I put a relative path the search results link looks something like this: sitecore://database/web/ItemId/{5C93A35C-3CDD-4334-BABC-6C194DB2FBD3}/Language/en/Version/1

If I put a full URL starting with HTTP like : "http://google.com" - the search results link show what I input.

The purpose of trying to use relative path is to avoid dealing with host names and figuring secure vs non-secure (HTTP vs HTTPS) during indexing. ( Which I tried using MultisiteContext - SiteInfo etc. and could not make it work)

2 Replies
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Feb 2, 2015 3:59 PM

In CES, the documents must have absolute URIs (Uri, ClickUri, PrintableUri). Thus, it is not possible to set relative ones. When you do so, Coveo for Sitecore ensures an absolute URI.

Gravatar for mlaporte@coveo.com

Comment by Martin Laporte, Feb 3, 2015 3:28 AM

Note that you can still change this on the UI side, though. In your templates in the CoveoResultLink component you can specify the href. For example you could put the relative uri in a field and then do something like:

<a class="CoveoResultLink" href="<%=raw.someFieldContainingRelativeUri%>">...</a>

Or you could invoke a JS function in the <%= %> block that would strip the host part from the default click uri.

Gravatar for shirazi@rdacorp.com

Comment by aga, May 14, 2015 9:30 AM

Hi, can you please elaborate on the "JS function in the <%= %>" approach? This js code would need to be called after the results are fetched after a query, do we have an event for that?

Gravatar for pavan.omtri@towerswatson.com

Answer by psomtri, May 20, 2015 8:17 PM

Here is a sample

<a class='CoveoResultLink' href="{{= FollowHitUri}}">{{=title?highlight(title, titleHighlights):clickUri}}</a>

Create ProcessParsedResponse pipeline

<coveoProcessParsedRestResponse>
            <processor type="MyCompany.Custom.Coveo.Processors.ProcessParsedRestResponse.UpdateClickableUri, TowersWatson.Custom" />
          </coveoProcessParsedRestResponse>

In that pipeline get ClickUri get the relative Uri from that and put in a new field

class UpdateClickableUri : IProcessor<CoveoProcessParsedRestResponseArgs>
{
    public void Process(CoveoProcessParsedRestResponseArgs p_Args)
    {
        if (p_Args.CurrentContextItem.Name.ToLower().Contains("search"))
       {
                string clickUriValue;
                UriBuilder tempUri;
                SearchResponse response = p_Args.ResponseContent;
                foreach (SearchResult result in response.Results)
                {
                    clickUriValue = result["ClickUri"].ToString();
                    if (!string.IsNullOrEmpty(clickUriValue))
                    {
                        tempUri = new UriBuilder(clickUriValue);
                        // build your relative URL from tempUri properties 
                        result["FollowHitUri"] = tempUri.path + tempUri.Query;
                    }
                }
            }
        }
    }
Gravatar for shirazi@rdacorp.com

Comment by aga, May 20, 2015 10:26 PM

why was this down voted?

Gravatar for micallahan@logmein.com

Comment by mcallahan, May 21, 2015 1:34 PM

That worked, awesome thanks!

Ask a question