Tips & Tricks - Customizing the Display of Search Results

This post shows how individual VM files can be integrated to display search results. In addition to the modified display and order of the data, the term found is also highlighted.

You can download the sample application here and import it into your portal as usual. When importing, select the "Import with application data" setting.

Create a VM file

Copy the "application.vmi" file to the portal directory "internal/system/vm/common/search/result". In the same directory, create a new folder named "custom" and save the copied file there with the name "my-application.vmi." In the sample file, the following data fields are used in the search results:

  • Title

  • Description

  • Date of Change

  • Publication Date

  • Origin

The source should be displayed as "My search" rather than the application name.

Customize the VM file

Open the "my-application.vmi" file in a text editor. The value of the corresponding data field in the application should be displayed for the modification date.

Lines 199 through 202 can be commented out, since the modification date will be defined later in a separate block.

Lines 204 through 211 are replaced with the following code.

            ## Individual modification
<dt class="source">$I18N.get("SEARCH2_COLUMN_SOURCE"): My search</dt>	##Guid of current data group
	#set ($dgguid = $recordInfo.getDGGuid())
	##ID of current data record
	#set ($myrecid = $recordInfo.getRecId())
			
	##IF GUID of current data group == GUID of data group of search configuration
	#if($dgguid == "054713578DA3050A194EC5B23E7981CAC7C63483") 
	##SELCET query for the desired data fields
	#set($statement = $PreparedQuery.prepare($DbConnection, "SELECT STR_TITEL_6A585D30, TXT_BESCHREIBUNG, DT_VEROEFFENTLICHUNGSDATUM, DT_AENDERUNGSDATUM FROM XDATAGROUP00D1A21861 WHERE LID = ?"))
	$statement.setInt(1, $myrecid)
	#set($rs = $statement.executeQuery())
	#foreach($element in $rs)
		##TITLE
		#set($title = $!element.getStringValue(1))
		##DESCRIPTION
		#set($text = $!element.getStringValue(2))
		##PUBLICATION DATE
		#set($dtpublish = $!element.getTimestampValue(3))
		##EDIT DATE
		#set($dtchanged = $!element.getTimestampValue(4))
		#set($pubDay = $DtUtil.wrap($dtpublish))
		#set($chgDay = $DtUtil.wrap($dtchanged))
		##Current timezone
		#set($timeZone = $User.getTimeZone())
		<dt>Published on $normalRenderer.renderDateTime($pubDay)    Last edited on $normalRenderer.renderDateTime($chgDay) </dt>		#end
		$rs.close()
		$statement.close()
		#end
## End individual modification

        

Save the changes and close the file.

The modified VM file is already included in the search configuration's Properties dialog in the sample application.

The figure above shows the sequence of dialog boxes that allow you to import your own VM files using the Properties dialog box associated with the Search button. On the "Actions" tab, you can edit the search configuration by clicking "Edit" next to " ." In the following dialog box, select the desired search configuration and then click " " "Edit Search Configuration." In the search configuration properties, on the "Display" tab, you can control how file matches are displayed using a custom VM.

For more information on configuration, click here.

Customize Search Results in the "Design" Module

In the "Design" module, you can now change the format of the search term. Open the current portal layout.

In the "Search" section, search for ".multisource-search .multisource-records > .record strong". Double-clicking on the search result loads the item settings. You can now set the yellow background in CSS.

            .multisource-search .multisource-records > .record strong  
{  
	font-weight: bolder;  
	background-color: yellow;  
}  

        

Save the layout and open the application in your browser.

Result in the browser

Search for "Title" here. The search results will be displayed based on the changes made.