SharePoint 2013: How To Create Custom Display Templates For SharePoint Search

What are Display Templates?

Display Template is a new technique introduced in SharePoint 2013 in order to modify the look and feel of the search results by making use of HTML & JavaScript instead of XSLT modifications as we did in the earlier versions.

With this new rendering technique or rather framework, SharePoint offers some of the most compelling advantages as mentioned below:

  1. Display Templates Support HTML & JavaScript instead of XSLT (which is often quite cumbersome to work with).
  2. Display Templates based configurations supports a broader scope of execution than XSLT based configurations. (As Display Templates should be defined at Site or Site Collection Scope while XSLT based Templates could only be defined at the WebPart Scope).
  3. Display Template applies Per Item Basis and not Per Result Set Basis (Provides us with the Context of the Current Item which is under execution, so that we can make use of any Managed Metadata Property associated with the Search Result Item and render it as per needs)
  4. As the Display Templates are scoped to Site or Site Collection, they can be used for all kind of results, can be used with in Content Search Web Part, Refiners and so on.

I recommend you to follow this MSDN Article on Display Templates to get an in depth understanding on the topic.

By now we got a fairly good Idea on “What are Display Templates?” and now it is time to see them in action.

Business Scenario:

  1. Additional User Profile Property should be added to User Profile Page which will hold the User’s LinkedIn Profile URL.
  2. There should be a provision to adjust the display position of this Property in Core Search Result Web Part.

Prerequisites:

  1. User Profile Service should be up and running
  2. User Profile Synchronization should be configured
  3. Search Service Application Instance should be configured appropriately
  4. Search Center Site Collection should be configured appropriately

In order to see Display Templates in Action, we need to perform following steps:

  1. Create User Profile Property
  2. Start Full Crawl of Content Source for the User Profiles
  3. Create, Map and Configure Managed Property
  4. Start Full Crawl of Content Source for the User Profiles
  5. Create Display Template
  6. Create Result Type with Custom Display Template
  7. Test Display Template

Create User Profile Property

Go To Central Admin >> Manage Service Applications

1

Click on User Profile Service Application

2

Click on Manage User Properties

3

Click on New Property

4

Enter Name, Display Name, Type & Length for the User Property as needed.

5

Make sure Default Privacy Setting must be set to Everyone

6

Make sure Indexed must be selected under Search Settings Section, else this property will be skipped by Search Crawler and it won’t be available to use later.

7

Once done with it click OK to add the User Property

8

Once added you can find the new property under Custom Properties Section

9

Go to Manage User Profiles

10

Find the required User Profiles and Edit their Profiles by selecting Edit My Profile from ECB Menu

11

On the User Profile Page, locate the LinkedIn Profile Property

Enter the URL to LinkedIn Profile of the User and Save the User Profile Properties

12

13

With this we are all done with the Creation of User Profile Property.

Start Full Crawl of Content Source for the User Profiles

Now in order to generate the Crawled Property corresponding to the User Profile Property we need to run the Full Crawl on the People Content Source

Go to Search Service Application

14

Click on Content Sources

15

Click on People Search and select Start Full Crawl from ECB

16

Wait till the Crawl Status become Idle

Create, Map and Configure Managed Property

Go to Search Schema

17

Click on Crawled Properties Link

18

We should verify if the Crawl Property corresponding to our User Profile Property has been created successfully or not

Find the Crawled Property by entering Search Term in Crawled Properties Textbox and click on the Image button with Green Arrow image.

Make sure you should be able to see the Crawled Property which is created during the Full Crawl Process as shown below

19

New we need to create a new Managed Property and Map it with the crawled property shown in earlier step

Click on Managed Properties Link

Click on New Managed Property Link

20

Enter Name, Description, Data Type for the Managed Property

21

Select Searchable, Queryable, Retrievable, Sortable, Refinable and Safe as appropriate

22

23

Click on Add Mapping Button

24

On the Crawled Property Selection Screen

  1. Enter Property Name
  2. Click Find Button
  3. Select appropriate Crawled Property
  4. Click OK

25

Save the Managed Property Definition

26

In order to verify newly Created Managed Property

  1. Enter Property Name
  2. Click Image Button

You should be able to see Managed Property with all the settings you specified earlier.

27

With this we are done with the creation of require Managed Property corresponding to the Crawled Property

Start Full Crawl of Content Source for the User Profiles

Now in order to fill the Managed property with the value stored with in Crawled Property based on the mapping, we need to run the Full Crawl again as we did before.

28

Create Display Template

Once we are done with the Creation and Configuration of required Managed Property, it is time now to create a new Display Template which will include this Managed Property

We need to launch Design Manager from the Standard Menu as shown below

29

Click on Upload Design Files

30

Click on Location URL as shown below

31

Click on Display Templates Folder

32

Click on Search Folder

33

Since we need to modify the template for People Search Results, we need to modify the template Item_Person

34

Point of Caution: As a part of recommended SharePoint Practices, we should never edit and existing template, instead we should make a copy of it, rename it and then modify it as per our needs.

35

Open the Item_Person_LinkedIn Template file and make the following modifications

  1. Change the Title
  2. Added the Managed Property we created in earlier steps

36

Now you need to decide where exactly you want to place this Managed Property within the Display Template.

In our case I am going to place this below User Name

Find the Html Tag NameValue

Below this tag add the following code as shown below

  1. Check if LinkedInProfileUrl Managed Property is not Empty
  2. Add HTML snippet to display the value stored in LinkedInProfileUrl Managed Property
  3. Close the IF block

37

Save the file and copy it back to the same location

38

SharePoint generates a JS File corresponding to this HTML file automatically, and the JS file should not be modified by the users. This JS file will be maintained and modified by SharePoint system automatically based on the changes you have made in HTML File.

39

With this we are done with the development of new Display Template.

Create Result Type with Custom Display Template

Now the next step is to create a new Result Type, which will be using our new Display Template to display the Search Results

Go to Site Settings

40

Click on Result Types

41

Click on New Result Type

42

  1. Provide Name to the Result Type
  2. Select Result Source
  3. Select Display Template (the one we have just created)
  4. Save Result Type

43

44

We can see the newly created Result Type on Manage Result Type Page as shown below

45

With this we are all done with development of new Display Template, it is time to test it now.

Test Display Template

Search for the Users and sure enough you will find the new Property appears only for those User Profiles which contains a non-empty value for LinkedIn URL Property.

46

From the above walkthrough we can conclude the fact that Display Templates are simple but really powerfull mode of customizing Search Result Page as per custom needs.

Hope this help someone in need…

Advertisements

SharePoint 2013: How To Create Custom Search Verticals

What are Search Verticals:

In SharePoint 2013 Search Vertical are displayed in the Search Navigation Web Part on Search Center. SharePoint 2013 Provides us four Search Verticals OOTB namely Everything, People, Conversation, Videos. Each of these verticals mapped to a specific page to display the results returned by the queries and when Search Users click on any of these verticals they are navigating to the respective mapped pages with the vertical they clicked on.

3

For example: Search Vertical Everything uses Results.aspx page to display the results returned by the query. In the similar fashion People vertical uses PeopleResults.aspx, Conversation vertical uses ConversationResults.aspx, Video vertical uses VideoResults.aspx.

All these pages used by the different Search Verticals can be located under Page Library on Search Center Site

1

Each of these vertical pages uses following four Web Parts to render results returned by the user queries:

  1. Refinement Web Part
  2. Search Box Web Part
  3. Search Navigation Web Part
  4. Search Results Web Part

2

I hope by now you got a fairly good idea on “What are Search Verticals?”

In this article we are going to create new Search Vertical for our Search Center that will be showing all the documents (Only Documents) Authored or Co-Authored by me.

Business Scenario:

  1. Search must be able to show all the documents Authored or Co-Authored by me
  2. All the search results must be shown under different vertical on the Search Center
  3. Only documents must be included in the search results

Prerequisites:

  1. Search Service Application Instance must be created and configured
  2. Content Sources must be created as required
  3. Full Crawl must be executed once at least on each of the Content Source
  4. Search Center Site must be created & configured as required

On the similar lines we can create our own Search Verticals.

We need to perform following steps to get a new Search Vertical Up and Running.

  1. Create Result Sources (One per vertical)
  2. Create new Search Vertical page to display results
  3. Configure Search Navigation

We will start our journey by creating the required Result Source for the new search vertical

Go to Site Settings

4

Go to Search >> Result Sources

5

Create new Result Source by clicking New Result Source link

6

Enter Name and Description.

Choose Local SharePoint as Protocol

Click in Launch Query Builder Button to launch Query Builder screen where we can specify the relevant query for the Result Source

7

8

Choose Property Filter as needed, based on the business scenario we have we will choose Property Filter as Author and Value as Name of the user who run the query then Property Filter as IsDocument and Value as 1.

Setting IsDocument Property Filter to 1 is a must if you want to display only documents as the part of the search results for this newly created vertical.

9

Click Add property filter Button to add the properties to the Query Text.

Once we are done with configuring the Query we need to test the Query by clicking Test Query Button

Search Result Preview Panel on the left will display all the results returned by the query we just configured.

10

Click OK

11

With this we are done with the creation of Result Source for the new Search Vertical

Now we will create new Search Vertical Page to display results retuned by the Result Source that we have just created.

Go to Site Contents

12

Go to Pages Library

13

Click new item or Go to Files Tab >> New Document

Choose Page Template to create a new Search Page

14

15

Once the page is added, Edit the page

16

Locate Search Results Web Part and edit its properties

17

18

In Web Part Properties click on Change Query Button to launch a query builder

19

Choose My Documents Result Source from Select a query Dropdown box

20

Click Test Query Button to test the query translated by the Result Source selected under Select a query

Search Result Preview Panel on the left will display all the results returned by the query we just configured.

With this we are done with creation a new Search Result Page.

It is time now to Configure Search Navigation to include new Search Vertical on the Search Center

Go to Site Settings

Go to Search >> Search Settings

21

Click on Add Link under Configure Search Navigation

22

Enter Title as My Documents

Click on Browse Button

23

Select MyDocuments.aspx Page from Page Library

24

Click OK

This will create a new Search Vertical on the Search Center with name My Documents.

25

26

Finally we need to test this new Search Vertical.

Currently I am logged in as sp\spdeveloper

Go to Search Center

Enter Search Query in our case which is *.pdf to return all the documents with the extension .pdf.

Everything Search Vertical will show all the PDF documents returned by the query

27

But My Document Search Vertical will show only those PDF documents which are Authored or Co-Authored by me

28

29

Creating new Search Verticals can be helpful in the scenarios where business user needs to filter out the results returned by the queries under different names by limiting the results based on the Result Sources.

Hope this will help someone in need.

Sharepoint 2013: How To Develop Custom Search Refiners

There could be scenarios where we need to have additional Search Refiners apart from the refiners provided by SharePoint OOTB.

Business Scenario:

In this article we are going to take care of a scenario where :

  1.  We need to add one additional property to the User’s Profile with the name “Last Company”. This property will contain the name of the User’s Previous Organization.
  2.  This property must be mapped with one of the Term Sets created in Managed Term Store.
  3.  This property must be available as an additional Refiner for the People Search

Prerequisites:

  1. Managed Metadata Service Application Instance must be created & configured.
  2.  User Profile Service Application Instance must be created & configured.
  3.  Search Service Application Instance must be created & configured.
  4.  Content Source must be created for User Profiles. Full crawl must be executed once.
  5. Search Center Site Collection must be created.

Now let’s see Custom Refiners in action.

Go to Central Administration = > Manage Service Application

1
Select Managed Metadata Service Application Instance.

2

SharePoint provides three Terms Sets Department, Job Title, Location which is available OOTB and mapped to User Profile Properties.

3

Now let’s create a new Term Group “Companies”.

Under “Companies” create a new Term Set “My Past Companies”.

Under “My Past Companies” create new Terms as shown below. Each term should represent a single company that can be selected from within User’s Property Page using “Terms Picker”.

4

With this we are done with the Managed Term Store Configuration.

Now it is time to create a new User Property “Last Company” which is mapped to the Term Set “My Past Companies”.

Go to Central Administration = > Manage Service Application

Select User Profile Service Application Instance

5

Go to “Manage User Properties”

6

Click “New Property”

7

Enter Name, Display Name, Type and Choose Term Set as shown below:

8

Scroll down and make sure “Default Privacy Settings” must be set to “Everyone” else Search Crawler won’t be able to crawl this property.

9

Click OK.

This will create a new User Property under Custom Property Section as shown below.

10

Now go to “Manage User Profiles” to modify the User Property Page for the User.

11

Find the User and Edit its profile by selecting “Edit My Profile” from ECB as shown below

12

Scroll down and locate the “Last Company” property.

Enter the company name using “Term Picker” as shown below

13

14

Save and Close the User Property Page by clicking the “Save an Close” button.

15

With this we are all done with the creation and configuration of the Custom User Property.

Now it is time to trigger the Crawl on User Profiles so that this new property gets crawled and available for the search queries.

Go to Central Administration = > Manage Service Application

Select Search Service Application Instance

16

Click on “Content Sources” to open “Manage Content Sources” Page

17

Choose “People Search” Content Source and click “Start Full Crawl” using ECB as shown below:

18

Wait till the Crawl Status is “Idle”.

19

Go to Search Center and Click on “People” Vertical.

Enter Search Term and Click Find Icon

As soon as the Search Results appear we can notice a new Refiner “Last Company” available on the Refiner Panel as shown below:

20

We can easily refine the incoming results by using “Last Company” Refiner as shown below:

21

By this simple walkthrough we can conclude that the capability of creating new Refiners is quite powerful and gives us enormous power to create different kind of refiners based on the incoming result sets.

Hope this will help someone in need…

SharePoint 2013: How to develop Filtered Views for External Lists using Business Data Connectivity Service

There are scenarios where we need to interact with LOB Data Sources containing Lakhs of records, and it is not feasible to interface all the data into SharePoint at once without significant performance loss.

But this business scenario can be taken care by developing Filtered Views for External Lists using BDC.

With this simple Walkthrough we are going to investigate the Filtered Views for External Lists which provides a mechanism of interfacing Large Volume of LOB data into SharePoint using “External Content Types” now onwards we call them ECTs.

By Implementing Filtered Views we can achieve high performing solutions with “No Code Solution” Approaches.

Now let’s start our journey to see BDC Filtered Views in Action.

Start SharePoint Designer and navigate to the required site

1

Click on “External Content Types” in the Site Objects Panel on the left

2

Click on “External Content Type” in the Ribbon Bar at the top

3

Enter the following information on the ECT Definition Page shown on the right

  1.  Name: <Enter any Name of your choice>
  2.  Display Name: <Enter any Display Name of your choice>
  3.  Namespace: <Enter any Namespace of your choice. Make sure it must be a unique value>

Then Click on “Click here to discover external data sources and define operations” as shown below

4

Alternatively you can Click on “Operations Design View” in the Ribbon Bar at the top

5

Create New Connection to LOB System by clicking “Add Connection” Icon in “Operation Design View”

6

  1. Enter Database Server Name
  2. Enter Database Name
  3. Name of the Connection which will be shown in Data Source Explorer
  4. When it comes to User Authentication, we can choose any of the three available modes as per the requirements. In this walkthrough we are going to configure an Application ID with the name “SQLServer” under SharePoint Secure Store Service and use it here for User Authentication.

Right Click on the Table you want to map in BDC model, (in our case it is “Customers” Table) and select “Create All Operations”.

7

Click Next.

8

You will see a couple of errors visible under “Errors and Warnings” section. We need to be carefully gone through all the Errors/Warnings and make sure to fix them all before proceeding any further.

The errors shown in the following screen shot can be fixed by making the following modifications in BDC Model:

  1.  Customer ID Field must be selected as Identifier as this column represents the Primary Key Field in the LOB System.
  2.  Customer ID field can either be “Required” or “Read-Only”, so we need to choose any one of the options as required
  3.  There is atleast one Field for which “Show in Picker” option must be selected, this option is necessary to enable Picker Values for fields of type “External Data”

9

We can easily fix the issues by making following modifications in the model:

Select “CustomerId” column on the left

  1.  Select “Map to Identifier”
  2.  Un-Select “Required” Checkbox (this is applicable in our scenario as Customer ID will be generated automatically by the LOB System)
  3.  Select “Show in Picker” Checkbox

Though it is absolutely optional but we should modify the “Display Name” for the column as this is the name which will be displayed to the users as List Fields when they create and access the External Lists referring this ECT.

10

Follow the same steps for other columns as necessary.

Then Click Next.

It is always a good idea to apply filters on the data fetched from LOB systems using BDC Model Definition.

Based on Microsoft recommendations on BDC Models, having atleast a “Limit Filter” applied on the data improves the overall performs of the solution to the great extent as this filter avoid large result sets to interface into SharePoint.

In order to add the Filters click on “Add Filters Parameter” button

11

Now click on “Click to Add” Link as shown below

13

Specify the name of the Filter as “LimitFilter”

Select Filter Type as “Limit”

Filter Field will be selected by Default to the Identifier column in our case it is “CustomerId”

Click OK.

14

Set the default value for the filter parameter as applicable

Click Finish.

15

Great! We are done with creating all the required data operations.

All the created data operation can be seen on to the right side under “External Content Type Operations” section as shown below

16

BDC offers us a very powerful feature of creating any number of “Read List” Operations with in the same BDC Model Definition, this feature provides us the base for creating Filtered Views.

We can create as many Read List operations based on different filter criteria, like one operation could be created with Limit Filter to limit the number of records displayed from LOB System, other one could be created with Comparison filter to match a specific value with a specific column, or might be we can create a Read List Operation with Wildcard filter to match a pattern with a specific column and so on.

Now we will create a new Read List Operation based on a Data View already present in the LOB system. This data view takes a parameter of “Wildcard” type and return the results matching the pattern.

Expand the Views Folder then select the view on which this new Read List Operation will be based. Right Click and Select “New Read List Operation”

17

Configure Read List Operation as we did in the previous steps.

18

Add a new Filter as we did before, but this time we are going to create a filter of type “Wildcard”

19

20

Here we can see that the BDC Model Editor is intelligent enough to identify the Input Parameter required by LOB System to provide the data, in our case this parameter is “@CustomerIdWc” .

Also we can make changes to the Display Name for this parameter, this display name will be shown to the users when they get into the External List Views created by this BDC model.

Configure rest of the Read List Definition as we did in earlier steps.

Click Finish. This completes the definition of new Read List Operation with Wildcard Filter.

21

22

We can revisit the connection Properties by clicking on “Connection-To-Northwind” link as shown below, in case we want to make any further changes to them.

23

24

Save the BDC Model Definition inside Business Connectivity Service Instance by clicking save Icon in the Tool Bar as shown below

25

With this we are all done with the development of External Content Type (ECT) that is capable of supporting Filtered Views for any External List which is consuming this ECT.

But before we proceed any further we need to provide the necessary permissions to ECT by navigating “Business Data Connectivity Service” Instance

Go to Central Admin => Manage service applications

26

Click on Business Data Connectivity Service Instance, it will display all the ECTs saved under this instance as shown below

27

Select the required ECT and Click on “Set Object Permission” in Ribbon Bar

28

Add required Users or Group and assign them the proper permissions.

“Execute” permission must be granted at the minimum in order to get the data in External Lists using this ECT.

29

Now let’s test the ECT by creating a new External List and associating it with this ECT as shown below
Browse Site => Site Content => Click on “add an app”

30

Choose “External List” Template

31

Choose appropriate ECT using ECT Picker and Click Create.

This will create an External List based on ECT we created.

32

33

As soon as the list is created, default View of the List will be displayed.

Note that this default view will always be based on default “Read List” operation as defined with the BDC Model for the ECT.

34

Now if we got to Ribbon Bar “List” Section and look for the Dropdown list for all the defined views for the External List (remember each view is mapped to one of the Read List Operations defined with in the BDC model for ECT).

In the following screen shot we can see one more View which is mapped on a “Read List” Operation supported by Wildcard Filter.

35

If we choose the view “Get Matching Items”, it will filter out the result sets to limit only those customers where Customer ID matches the Pattern provided to the Wildcard Filter as value.

In order to assign value to Wildcard Filter Parameter, edit “Get Matching Items” View and provide a value to Wildcard Parameter under “Data Source Filters” section.

36

Specify the pattern and click OK.

And sure enough you will get all the record where Customer ID starts with “Alf”.

37

By this Walkthrough we can derive the following conclusions:
1. Filtered Views are really a very powerful way of dealing with the large volume of LOB data while keeping the performance of the solution to a high.
2. As there are any number of Read List Operations can be defined with in the same BDC Model, it presents us with an opportunity to create as many Filtered View as required in order to deal with the LOB data.
3. This solution is presenting with “No Code Solution Approach” so can be developed easily and require lesser number of testing iterations.

Hope this will help someone in need…