Monday, December 22, 2008

Customizing Search Series - Finally Customizing the Search Results

Perform a search within the Client scopes to bring up the Client Results page. Click on Site Actions and Edit Page. Edit the Search Core Results web part by clicking the Modify Shared Web Part from the Edit (dropdown) menu:

On the left hand side pane, under the Results Query Options, click inside the Selected Columns to make the blue ellipsis button appear. Click on the blue ellipsis button:

At the bottom of the text, before the tag, add a column entry for each managed property that was created for the BDC content source:

Click OK.
Next click on the XSL Editor under the Data View Properties:

The XSL entry will appear in the text dialog. It may be easier to copy and paste the code out into a different code editor and then paste back into the dialog for the remaining XSLT steps.

XSLT: Overriding the results URL
The tasks outlined in this section are for the scenario where we want to show a custom URL in the results versus the one returned from the normal search results. While this may not apply to everyone, the steps show how to add a new variable based on a custom search column and use it within the overall XSLT.
Locate the “This template is called for each result” section of the code.
Add a new variable name entry for the ClientURL under the two predefined variable entries (all variables should be in lowercase regardless of how the managed property was defined):
Next, find and change all “$url” entries to “$clienturl”.
Find the “xsl:value-of select=”url”" entry within the hithighlightedproperties condition code (when statement). Change the “url” to “title”.
Locate the span class for srch-URL (span class=”srch-URL”). Within this section, locate the when condition for the hit highlighted properties as shown:

Replace the “hithighlightedproperties/HHUrl” with “clienturl”
Several lines down, replace the “url” in “xsl:value-of select=”url”" with clienturl (xsl:value-of select=”clienturl”)
Click Save, Click OK on the web part tool pane and publish the page. The client search results should now show the custom client URL that is being returned from the BDC.
XSLT: Creating the Additional Reference Links within the Results
If you perform a Google search and you hit a website’s core address (such as Microsoft.com), there are additional reference links that appear within the search results:

You can add these to the MOSS Search results as well. The reference links can be displayed using standard HTML. This HTML should be placed after the “p class=”srch-Metadata” section (therefore after the p end-tag) :

The “ENTER THE HTML HERE” message will not appear - this was entered for demonstration purposes.
The following is sample code within a
block for rendering the additional link references. The appropriate URLs should be retrieved from the BDC and entered appropriately (the columns used here are generalurl, contacturl, documenturl, and referenceurl):
Blank rows or cells are placed for spacing purposes. Additional URL properties will require additional variable entries as entered above (e.g. xsl:variable name=”generalurl” select=”generalurl”)
Here is a sample output:


Print this post

No comments: