Category Archives: Search

How to create a Three Lines Search Display Template

Before starting ensure the SharePoint Server Publishing Infrastructure site collection feature is activated:

1.  Access SharePoint Designer 2013. Open the site to add a new search display template.

2.  Click on “All Files” and “_catalogs” and “masterpage” and “Display Templates” and “Content Web Parts”:

SharePoint Designer 2013 Display Templates

3.  Select the display template to base the new display template on. In this example I have created a new display template based on the “Item_TwoLines.html” file. Right-click and select “Copy”. Right-click and select “Paste”. (Note: The JavaScript pair file is created automatically).

4.  Select the copied item and rename it e.g. “Item_ThreeLines.html”. Wait for the JavaScript to correctly copy (use the Refresh function). Ensuring the new renamed html item is selected, right-click and select “Check Out”.

5.  With the item selected right-click and select “Edit File in Advanced Mode”. The Advanced Editor displays the HTML.

The updated “Item_ThreeLines.html” appears as below. The highlighted elements indicate what has been added to the Item_TwoLines.html code:

<html xmlns:mso=”urn:schemas-microsoft-com:office:office” xmlns:msdt=”uuid:C2F41010-65B3-11d1-A29F-00AA00C14882″>
<head>
<title>Three lines</title>
<!–[if gte mso 9]><xml>
<mso:CustomDocumentProperties>
<mso:TemplateHidden msdt:dt=”string”>0</mso:TemplateHidden>
<mso:ManagedPropertyMapping msdt:dt=”string”>&#39;Link URL&#39;{Link URL}:&#39;Path&#39;,&#39;Line 1&#39;{Line 1}:&#39;Title&#39;,&#39;Line 2&#39;{Line 2}:&#39;Title&#39;,&#39;Line 3&#39;{Line 3}:&#39;&#39;,&#39;FileExtension&#39;,&#39;SecondaryFileExtension&#39;</mso:ManagedPropertyMapping>
<mso:MasterPageDescription msdt:dt=”string”>This Item Display Template will show a small thumbnail icon next to a hyperlink of the item title, with an additional line that is available for a custom managed property.</mso:MasterPageDescription>
<mso:ContentTypeId msdt:dt=”string”>0x0101002039C03B61C64EC4A04F5361F385106603</mso:ContentTypeId>
<mso:TargetControlType msdt:dt=”string”>;#Content Web Parts;#</mso:TargetControlType>
<mso:HtmlDesignAssociated msdt:dt=”string”>1</mso:HtmlDesignAssociated>
<mso:HtmlDesignStatusAndPreview msdt:dt=”string”>http://hsweb01/sites/navigate/_catalogs/masterpage/Display Templates/Content Web Parts/Item_ThreeLines.html, Conversion successful.</mso:HtmlDesignStatusAndPreview>
<mso:HtmlDesignConversionSucceeded msdt:dt=”string”>True</mso:HtmlDesignConversionSucceeded>
</mso:CustomDocumentProperties>
</xml><![endif]–>
</head>
<body>
<!–
Warning: Do not try to add HTML to this section. Only the contents of the first <div>
inside the <body> tag will be used while executing Display Template code. Any HTML that
you add to this section will NOT become part of your Display Template.
–>
<script> $includeLanguageScript(this.url, “~sitecollection/_catalogs/masterpage/Display Templates/Language Files/{Locale}/CustomStrings.js”);
</script>
<!–
Use the div below to author your Display Template. Here are some things to keep in mind:
* Surround any JavaScript logic as shown below using a “pound underscore” (#_ … _#) token
inside a comment.
* Use the values assigned to your variables using an “underscore pound equals”
(_#= … =#_) token.
–>
<div id=”ThreeLines“>
<!–#_
var encodedId = $htmlEncode(ctx.ClientControl.get_nextUniqueId() + “_3lines_”);
var linkURL = $getItemValue(ctx, “Link URL”);
linkURL.overrideValueRenderer($urlHtmlEncode);
var iconURL = Srch.ContentBySearch.getIconSourceFromItem(ctx.CurrentItem);
var line1 = $getItemValue(ctx, “Line 1”);
var line2 = $getItemValue(ctx, “Line 2”);
var line3 = $getItemValue(ctx, “Line 3”);
line1.overrideValueRenderer($contentLineText);
line2.overrideValueRenderer($contentLineText);
line3.overrideValueRenderer($contentLineText);
var containerId = encodedId + “container”;
var pictureLinkId = encodedId + “pictureLink”;
var pictureId = encodedId + “picture”;
var dataContainerId = encodedId + “dataContainer”;
var line1LinkId = encodedId + “line1Link”;
var line1Id = encodedId + “line1”;
var line2Id = encodedId + “line2”;
var line3Id = encodedId + “line3”;
_#–>
<div class=”cbs-Item” id=”_#= containerId =#_” data-displaytemplate=”Item2Lines”>
<a class=”cbs-ItemLink” title=”_#= $htmlEncode(line1.defaultValueRenderer(line1)) =#_” id=”_#= pictureLinkId =#_”>
<img class=”cbs-Thumbnail” src=”_#= $urlHtmlEncode(iconURL) =#_” alt=”_#= $htmlEncode(line1.defaultValueRenderer(line1)) =#_” id=”_#= pictureId =#_” />
</a>
<div class=”cbs-Detail” id=”_#= dataContainerId =#_”>
<a class=”cbs-Line1Link ms-noWrap ms-displayBlock” href=”_#= linkURL =#_” title=”_#= $htmlEncode(line1.defaultValueRenderer(line1)) =#_” id=”_#= line1LinkId =#_”>_#= line1 =#_</a>
<!–#_
if(!line2.isEmpty)
{
_#–>
<div class=”cbs-Line2 ms-noWrap” title=”_#= $htmlEncode(line2.defaultValueRenderer(line2)) =#_” id=”_#= line2Id =#_”>_#= line2 =#_</div>
<!–#_
}
_#–>
<!–#_
if(!line3.isEmpty)
{
_#–>
<div class=”cbs-Line2 ms-noWrap” title=”_#= $htmlEncode(line2.defaultValueRenderer(line3)) =#_” id=”_#= line3Id =#_”>_#= line3 =#_</div>
<!–#_
}
_#–>
</div>
</div>
</div>
</body>
</html>

6.  Save the edited “Item_ThreeLines.html” file. Check In the file and publish as a Major Version.

7.  If updated correctly, the new Display Template will appear in the “Content Search” Web Part properties. Select the display template name e.g. “Three lines”, as shown below:

Content Search Web Part Display Template Properties

8.  Expand the “Property Mappings” and tick the “Change the mapping of managed properties…” tick box. Note that a Link URL and Line 1, Line 2, and Line 3 appear based on the HTML changes. Click the drop-down menus to select available managed properties. On my example I have chosen to display a custom managed property called “DEVBMSID”, Title and UIVersionStringOWSTEXT (Version Number).

9.  To ensure that the Content Search Web Part only displays relevant documents click on the “Change Query” button in the “Search Criteria” section. Use the Quick Mode query builder or switch to Advanced Mode and enter search syntax – see example below:

Content Search – Build Your Query

10. You can test the results before clicking the “OK” button to save the search. Note: Refiners and Sorting can also be defined.

11. Ensure the “Number of items to show” is set to a suitable number – otherwise not all search results will be displayed.

12. Finally click on the Content Search Web Part properties “OK” button to save all settings.

 

Search Center navigation problems in SP10

SharePoint’s Enterprise Search Center and Basic Search Center are based on a minimal.master Master Page. This means that you cannot easily integrate a Search Centre into your standard global navigation deployment. To get around this problem you can either open the Search Centre in a new browser window, or implement a fix. My company Deltascheme offer a simple fix for the Basic Search Center. If you choose to install the solution you can create a revised version of the Basic Search Center that integrates with your standard v4.master global navigation.

Follow this link to download the fix: http://www.deltascheme.com/deltascheme-products/basic-search-center-with-navigation-for-sharepoint/

Displaying Metadata Properties on Search Results pages (MOSS 2007)

Background
It is possible to display custom metadata beneath each item

found on the search results page. The metadata can be presented in a number of

ways. There is plenty of information on the Internet about how this can be done

using XML and XSL – see http://blogs.catapultsystems.com/matthew/archive/2008/09/01/sharepoint-image-search-part-4.aspx for example.

See also Ref.Inside the Index and Search Engines: Microsoft

Office SharePoint Server 2007 -pages 140-141 book stored in Marlow

office.

On this example we will simply add four metadata items beneath

each item search result.

Instructions

1) Edit the Search Results page and edit the Search Core Results

Web part.

2) Expand the Results Query Options section and click

on the ellipse beside the Selected Columns field. Add extra selected columns to

be used by the Search Core Results. For example you may wish to add the

following lines:

<Column Name=”Brand”/>
<Column

Name=”Market”/>
<Column Name=”Filename”/>
<Column

Name=”TypeImage”/>
<Column Name=”TypeCommunication”/>
<Column

Name=”TypeMarket”/>

if you have previously created a managed metadata property

called ‘Brand’, ‘Market’, ‘Filename’, ‘TypeImage’, ‘TypeCommunication’, and

‘TypeMarket’ (in the SSP) for particular content type columns.

3) Click the XSL Editor … button and search

for <p

class=”srch-Metadata”>

Just

above this line insert a code snippet like the one shown

below:

</xsl:choose>

</div

>

<div class=”srch-Description”>Brand:

<xsl:value-of select=”brand”

/> <br />Market:

<xsl:value-of select=”market”

/> <br />Filename:

<xsl:value-of select=”filename”

/> <br />Type:

<xsl:value-of select=”typeimage” />

<xsl:value-of select=”typecommunication”

/>

<xsl:value-of select=”typemarket” />

<xsl:value-of select=”typeplan” />

</div>

<p

class=”srch-Metadata”>

<span

class=”srch-URL”>

<a

href=”{$url}” id=”{concat(‘CSR_U_’,$id)}” title=”{$url}”

dir=”ltr”>

<xsl:choose>

On

this example we have previously defined Managed Properties in the SSP for Brand,

Market, Filename and four different documents types (Image Type, Communication

Type, Market Type, and Plan Type).

4)

Close the XSL Editor and apply the modification to the Web Part and re-publish

the page.

The

effects of this modification will display the four crawled property values

underneath each item, e.g.

Item

details (as standard)

Brand:

SuperTea

Market:

Australia

Filename:

an-image.jpg

Type:

Press Release

Note:

Each item found will only contain one of the four possible Type

values.