Question

I have a simple list with a column of type 'Hyperlink or Picture' named 'TestHyperlink'. I've created a Managed Property at the Search Service Application screen for this column so it can be used later inside a Search Template. I do an index reset and fully crawl to make sure the system is aware of my newly created property.

Inside the Search Template I add the property to the ManagedPropertyMapping tag and create the following line:

console.log(ctx.CurrentItem.TestHyperlink)

The log shows me the url but not the description. I've read on the Internet it should return a csv value like this: 'url, description' but not in SP2016.

So my question in short; how can i get the description out of a 'Hyperlink or Picture' column in SP2016?

Was it helpful?

Solution 2

While waiting for a concrete answer I've used the following work around. I've split column 'TestHyperlink' into two other columns named 'TestHyperlink_Url' and 'TestHyperlink_Desc' formatted as type 'Text'. Afterwards I've created a Managed Property for mapping the new columns. As they are simple text columns it's now possible to use them in my Search Display Template.

OTHER TIPS

Try:

console.log(ctx.CurrentItem["TestHyperlink.desc"]);

or also, maybe:

console.log(ctx.CurrentItem.TestHyperlink.desc);

Doing my own testing the Managed Property associated with the URL field only stores the URL and throws away the Description. In fact, if I search for the description I don't find it, but if I search for the URL I find that. So that means that during content processing it appears that the URL is the only part that is kept.

You should map your Managed Property to Crawled property ows_q_URLH_TestHyperlink.

Then your managed property will contain URL and description in format: "Url, Desc".

Then, in display template you can add some js to extract this url\description:

var UrlFull = ctx.CurrentItem.YourManagedProperty;
var UrlPath = (UrlFull .split(','))[0];
var UrlDesc = (UrlFull .split(','))[1];

to build hyperlink for example:

<div>Link: <a href="_#= $htmlEncode(UrlPath) =#_"> _#= UrlDesc =#_ </a></div>
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top