Show language: C# VB.NET Both

ResultPreview Customization

The ResultPreview feature of SearchResult can be customized through the use of a plug-in, or with Javascript on the client side.

Plug-in (Server Side)

ResultPreview Settings

For maximum efficiency plug-in DLLs are not loaded unless SearchResult.ResultPreviewerLoadPlugin is set "true". Set this property in the ASPX or codebehind for the page which uses SearchResult, in order to be able to modify the preview text.

Creating The Plug-in

A Plug-in project can quickly be generated from the 'Plug-ins' tab in the Index Management Tool, in the project you will find code which handles the ResultPreviewTextLoaded event. For more information on plug-ins, see the overview of the Central Event System in general.

A plug-in class will subscribe to the Action event and process ActionName.ResultPreviewTextLoaded. The associated ActionData.Data is of type StringBuilder, and contains the document text, which may be modified. The document Uri is accessible through 'sender' (see below)

C#
private void CentralEventDispatcher_Action(object sender, Keyoti.SearchEngine.Events.ActionEventArgs e)
{
    if(e.ActionData.Name== ActionName.ResultPreviewTextLoaded)
    {
		StringBuilder documentPreviewText = e.ActionData.Data as StringBuilder;
		string uri = (sender as Keyoti.SearchEngine.Web.SearchResultPreviewHelper).Uri;
		//Change the document text, to put the Uri at the start of the text.
		//Remember that if you reassign documentPreviewText to a new object,
		//it will not be used by the previewer.
		documentPreviewText.Insert(0, "Document URL::" + uri + "\r\n\r\n");
    } 
}
VB.NET
Private Sub CentralEventDispatcher_Action(ByVal sender As Object,_
					ByVal e As Keyoti.SearchEngine.Events.ActionEventArgs)        
	If (e.ActionData.Name = ActionName.ResultPreviewTextLoaded) Then
		Dim documentPreviewText As StringBuilder = CType(e.ActionData.Data,StringBuilder)
		Dim uri As String = CType(sender,Keyoti.SearchEngine.Web.SearchResultPreviewHelper).Uri
		'Change the document text, to put the Uri at the start of the text.
		'Remember that if you reassign documentPreviewText to a new object,
		'it will not be used by the previewer.
		documentPreviewText.Insert(0, ("Document URL::"  + (uri + ""& vbCrLf& vbCrLf)))
	End If
End Sub

In this example the document text is modified to include the Uri at the start. The documentPreviewText is a StringBuilder and can be modified with any of its methods.

Javascript (Client Side)

On the page with the SearchResult control, add a function called sew_OnResultPreviewTextLoaded, this will be automatically called by the result preview engine when the text is about to be shown, allowing for modification of the text.

Javascript
function sew_OnResultPreviewTextLoaded(url, text, button, closedImgURL, openedImgURL) {
	//url - document URL
	//text - document text to be shown to user
	//button - instance of the HTML element that the user clicked (could be an img)
	//closedImgURL, openedImgURL - the URLs specified for the button states

	//Let's put the doc URL at the end of the text
	return text + "\r\n\r\n" + url;
}

Note that the modified text is returned, rather than set in the 'text' variable.