Gravatar for

Question by Steve Anderson, Oct 23, 2015 3:40 PM

Conditionally replace the URI used in Coveo SearchView results

Is it possible to conditionally change the value of the href that is output in the search results based on a condition of another field in the sitecore item?

For example, we need to provide an override link in the sitecore item (this is a normal General link field). If a value is there, I want all of the hrefs to use its value in the resulting output (class='CoveoResultLink' href='myvalue'). This new URI should be used for any occurrence of the 'CoveoResultLink'.

I know that Coveo will try to build a fully qualified URI that points to the actual sitecore item. Additionally, this override link value can sometimes point to a resource within sitecore, and sometimes not.

Thank You

2 Replies
Gravatar for

Answer by georgechang, Oct 23, 2015 3:54 PM

I would create a computed field for CoveoResultLink to determine what the resulting URL is depending on if it's a Sitecore item or an external link and index it. Then, in your result template you can add a conditional based on the value of CoveoResultLink to determine whether to use clickUri or the new computed field.

Gravatar for

Comment by Steve Anderson, Oct 26, 2015 11:53 AM

Thanks for the suggestion. I ended up creating a new computed field and conditionally selecting it, as you suggested.

Thanks Again!

Gravatar for

Answer by Simon, Oct 26, 2015 9:05 AM

The solution proposed by georgechang is the correct way at indexing time, which is the solution I would propose.

If you ever wish to override it at query time, we wrote a KB on it:

The article is about scaling but the code would work in any situations.


Gravatar for

Comment by Steve Anderson, Oct 26, 2015 11:54 AM

This is also a great KB. Thanks, Simon!

Ask a question