Return the debug info about this component.
Disable the component. Normally this means that the component will not execute handlers for the framework events (query events, for example). Components are enabled by default on creation.
Enable the component. Normally this means that the component will execute handlers for the framework events (query events, for example). Components are enabled by default on creation.
Return the bindings, or environment, for the current component.
Opens the result in the same window, no matter how the actual component is configured for the end user.
Specifies whether the method should log an analytics event.
Opens the link in the same manner the end user would.
This essentially simulates a click on the result link.
Specifies whether the method should log an analytics event.
Opens the result in a new window, no matter how the actual component is configured for the end user.
Specifies whether the method should log an analytics event.
Tries to open the result in Microsoft Outlook if the result has an outlookformacuri
or outlookuri
field.
Normally, this implies the result should be a link to an email.
If the needed fields are not present, this method does nothing.
Specifies whether the method should log an analytics event.
Get the bound component to the given HTMLElement. Throws an assert if the HTMLElement has no component bound, unless using the noThrow argument.
If there is multiple component bound to the current HTMLElement, you must specify the component class.
HTMLElement for which to get the bound component.
Optional component class. If the HTMLElement has multiple components bound, you must specify which one you are targeting.
Boolean option to tell the method to not throw on error.
Allows the component to bind events and execute them only when it is enabled.
Contains the state of options for different components. Mainly used by ResultLink.
Contains the state of different components (enabled vs disabled). Allows to get/set values. Triggers component state event when modified. Each component can listen to those events.
A disabled component will not participate in the query, or listen to ComponentEvents.
Allows component to log in the dev console.
Contains the singleton that allows to trigger queries.
Contains the state of the query. Allows to get/set values. Trigger query state event when modified. Each component can listen to those events.
A reference to the root HTMLElement (the SearchInterface).
A reference to the root of every component, the SearchInterface.
The static ID that each component needs in order to be identified.
For example, SearchButton -> static ID: SearchButton -> className: CoveoSearchButton
A reference to the Analytics.client.
Specifies whether the component should open its link in a new window instead of opening it in the current context.
If this option is true
, clicking the ResultLink
calls the
openLinkInNewWindow
method instead of the
openLink
method.
Note:
If a search page contains a
ResultPreferences
component whoseenableOpenInNewWindow
option istrue
, and the end user checks the Always open results in new window box,ResultLink
components in this page will always open their links in a new window when the end user clicks them, no matter what the value of theiralwaysOpenInNewWindow
option is.
Default value is false
.
data-always-open-in-new-window='true' data-always-open-in-new-window='false'
Specifies the field to use to output the component href
attribute value.
Tip:
Instead of specifying a value for the
field
option, you can directly add anhref
attribute to theResultLink
HTML element. Then, you can use a custom script to generate thehref
value.
Examples:
ResultLink
outputs its href
value using the @uri
field (rather than the
default field):<a class="CoveoResultLink" data-field="@uri"></a>
getMyKBUri()
function provides the href
value:<script id="KnowledgeArticle" type="text/underscore" class="result-template">
<div class='CoveoIcon>'></div>
<a class="CoveoResultLink" href="<%= getMyKBUri(raw) %>"></a>
<div class="CoveoExcerpt"></div>
</script>
See also hrefTemplate
, which can override this option.
By default, the component uses the @clickUri
field of the item to output the value of its href
attribute.
data-field='@foo'
Specifies a template literal from which to generate the ResultLink
href
attribute value (see
Template literals).
This option overrides the field
option value.
The template literal can reference any number of fields from the parent result. It can also reference global scope properties.
Examples:
href
value such as http://uri.com?id=itemTitle
:<a class='CoveoResultLink' data-href-template='${clickUri}?id=${raw.title}'></a>
href
value such as localhost/fooBar
:<a class='CoveoResultLink' data-href-template='${window.location.hostname}/{Foo.Bar}'></a>
Default value is undefined
.
data-href-template='foo'
Specify this option to log additional analytics when this result link is pressed.
Example:
const resultLink = new Coveo.ResultLink(
linkElement,
{
logAnalytics: (href) => Coveo.logCustomEvent(
Coveo.analyticsActionCauseList.openSmartSnippetSource,
{
searchQueryUid: searchInterface.queryController.lastSearchUid,
documentTitle: result.title,
author: Utils.getFieldValue(result, 'author'),
documentURL: href
},
element
)
},
searchInterface.getBindings(),
result
)
Specifies an event handler function to execute when the user clicks the ResultLink
component.
The handler function takes a JavaScript Event
object and
an IQueryResult
as its parameters.
Overriding the default behavior of the onClick
event can allow you to execute specific code instead.
Note:
You cannot set this option directly in the component markup as an HTML attribute. You must either set it in the
init
call of your search interface (see Passing Component Options in the init Call), or before theinit
call, using theoptions
top-level function (see Passing Component Options Before the init Call).
Example:
// You can set the option in the 'init' call:
Coveo.init(document.querySelector("#search"), {
ResultLink : {
onClick : function(e, result) {
e.preventDefault();
// Custom code to execute with the item URI and title.
openUriInASpecialTab(result.clickUri, result.title);
}
}
});
// Or before the 'init' call, using the 'options' top-level function:
// Coveo.options(document.querySelector('#search'), {
// ResultLink : {
// onClick : function(e, result) {
// e.preventDefault();
// // Custom code to execute with the item URI and title.
// openUriInASpecialTab(result.clickUri, result.title);
// }
// }
// });
Specifies whether the component should try to open its link in Microsoft Outlook.
Setting this option to true
is normally useful for ResultLink
instances related to Microsoft Exchange emails.
If this option is true
, clicking the ResultLink
calls the
openLinkInOutlook
method instead of the
openLink
method.
Default value is false
.
data-open-in-outlook='true' data-open-in-outlook='false'
Specifies whether the component should open its link in the Quickview
component rather than
loading through the original URL.
Default value is false
.
data-open-quickview='true' data-open-quickview='false'
Specifies a template literal from which to generate the ResultLink
display title (see
Template literals).
This option overrides the default ResultLink
display title behavior.
The template literal can reference any number of fields from the parent result. However, if the template literal
references a key whose value is undefined in the parent result fields, the ResultLink
title displays the
name of this key instead.
This option is ignored if the ResultLink
innerHTML contains any value.
Examples:
ResultLink
display title such as Case number: 123456
if both the
raw.objecttype
and raw.objectnumber
keys are defined in the parent result fields:<a class="CoveoResultLink" data-title-template="${raw.objecttype} number: ${raw.objectnumber}"></a>
${myField}
as a ResultLink
display title if the myField
key is undefined
in the parent result fields:<a class="CoveoResultLink" data-title-template="${myField}"></a>
Foobar
as a ResultLink
display title, because the ResultLink
innterHTML is
not empty:<a class="CoveoResultLink" data-title-template="${will} ${be} ${ignored}">Foobar</a>
Default value is undefined
.
data-title-template='foo'
Creates a new ResultLink
component.
The HTMLElement on which to instantiate the component.
The options for the ResultLink
component.
The bindings that the component requires to function normally. If not set, these will be automatically resolved (with a slower execution time).
The result to associate the component with.
The
ResultLink
component automatically transform a search result title into a clickable link pointing to the original item.This component is a result template component (see Result Templates).