CSWP: Display Template Listing Sites/Site Collections

1 Comment

One of the clients I’m working with wanted to list all of their site collections and place a “directory” on a single page with some groupings (based on managed paths).

The easiest way I could think of was to use Content Search Web Parts (CSWPs).

I used the following query:

QueryBuilderSiteCollection

My search result looked like this.

SiteCollectionPreview2

Note: You can change the query to display all sites within a site collection by using STS_Web instead of STS_Site.

The OOTB list of sortable items of the Query Builder didn’t have an option for me to sort the site title alphabetically.  So, I made a change to the SiteTitle in Search Scope (Managed Properties) to include sortable.  And I waited until Search finished crawling/indexing the modified setting.

After Search finished indexing, I was able to select the the setting I needed to sort the sites by their titles.

I selected the Two Lines Display Template.  However, the OOTB display was not exactly what the client was looking for.

TwoLineDT2

So I started modifying the display template to get rid of the icon/image displayed in front of each link and the spacing between the links.

I renamed my Display Template to “Item_NoImageOneLine.html”, changed the Title to “No Image One Line”, added a style tag, and commented out the image section.

<div class="cbs-Item" id="_#= containerId =#_" data-displaytemplate="Item1Line" style="padding-bottom:5px">
<!--<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>
<!--#_

Here’s the final result.

TwoLineDTFinal

Learn more about Centric’s Portals and Collaboration Practice

Advertisements

Add E-mail to People Search Display Template

2 Comments

This is a follow up to my previous post on adding phone extension to people results page (PeopleResults.aspx).

This post provides steps on how I added e-mail with action (mailto) to people search.

WorkEmail is one of the default user profile properties already mapped in SharePoint both in User Profile Property and in Search Schema. This makes my job a bit easier because all I have to do is modify my Display Template to include this value.  Some of the steps listed here are the same as my previous post.  I hope this makes things easier than flipping back and forth between the two.

  1. If you already have a custom display template for Item_Person, skip to step 6.  If this is the first time you need to edit the display template for people results, continue to the next step.
  2. From Search Center, select the following:
    • Site Settings
    • Master pages and page layouts
    • Display templates
    • Search
  3. Download ‘Item_Person.html’, save it on your local drive with a different name (ex: My_Item_Person.html)
  4. Modify Title. This will be used later when I modify the People Search Core Results Web Part.
  5. <title>My People Item</title>
  6. In <div id=”ContactInfo”>tag, add
<!--#_ 
                                        if(has_email == true) {
_#-->
                                            <div id="WorkEmailField">
<!--#_ 
                                                var encodedWorkEmail = $htmlEncode(ctx.CurrentItem.WorkEmail);
                                                var displayWorkEmail = Srch.U.getSingleHHXMLNodeValue(hhProps, "workemail");
                                                if ($isEmptyString(displayWorkEmail)) { displayWorkEmail = encodedWorkEmail }
_#--> 
                                                <div id="WorkEmailValue" class="ms-srch-ellipsis" title="_#= encodedWorkEmail =#_"><a href="mailto:_#= encodedWorkEmail =#_"> _#= displayWorkEmail =#_ </a></div>
                                            </div>
<!--#_ 
                                        }
_#-->

7.  Save My_Item_Person.html, upload it to the Display Template/Search gallery, and publish it

8.  From Search Center, type in a query term (ex: Executive)

9.  From ‘Site Settings’, select ‘Edit Page’

10.  Edit ‘People Search Core Results’ Web Part

11.  Expand ‘Display Templates’, select ‘Use a single template to display items’, select My People Item, then select ‘OK’

12.  Check In and Publish the People Results page (PeopleResults.aspx)

Your results page shoud look similar to the following.  Note that the OOTB results page only displays Name, Title, and Department

PeopleResults

Again, these steps may not be the greatest, but they worked for me.

Add Phone Extension to Display Template for People Search

Leave a comment

One of the clients I worked with store users’ phone extension in a string (Multi value) field in their Active Directory, though this value could be stored in a regular string field. Regardless of where the value is stored, my objective was to display this value in people search (PeopleResults.aspx). Steps I used below may not be the greatest, but they worked for me.

  1. Map a SharePoint user profile property to this AD attribute. I used ‘PhoneExtension’ for this one.
  2. Start Full Profile Synchronization
  3. Start Full or Incremental Crawl in Search
  4. From Search Service Application, select ‘Search Schema’
  5. Select ‘Crawled Properties’ and search for ‘PhoneExtension’. I did this step to verify that the property I created was crawled, and to allow me to move to the next step. You should see ‘People:PhoneExtension’ for your search.
  6. Select ‘Managed Properties’, then select ‘New Managed Property’. I created ‘PhoneExtension’ as a ‘Text’ type, and selected the following:
    • Queryable
    • Retrievable
    • Safe
  7. Select ‘Add a Mapping’, type ‘PhoneExtension’ in the ‘Crawled property selection’ window
  8. Select ‘People:PhoneExtension’, then click ‘OK’ to close the ‘Crawled propety selection’ window
  9. Click ‘OK’ again to close the ‘New Managed Property’ window
  10. Start Full Crawl, wait for this to complete
  11. From Search Center, select the following:
    • Site Settings
    • Master pages and page layouts
    • Display Templates
    • Search
  12. Download ‘Item_Person.html’, save it on your local drive with a different name (ex: <Client>_Item_Person.html)
  13. Modify title. This will be used later when I modify the People Search Core Results Web Part.
<title>Client People Item</title>

14.  Add ‘PhoneExtension’:’PhoneExtension’ to the end of the mso:ManagedPropertyMapping line (about line 13 or so).  Since ‘WorkPhone’ is already mapped in SharePoint as one of the default user property mappings, I added it here as well.

ManagedPropertyMapping

<mso:ManagedPropertyMapping msdt:dt="string">'AboutMe':'AboutMe','AccountName':'AccountName','BaseOfficeLocation':'BaseOfficeLocation','Department':'Department','HitHighlightedProperties':'HitHighlightedProperties','Interests':'Interests','JobTitle':'JobTitle','LastModifiedTime':'LastModifiedTime','Memberships':'Memberships','PastProjects':'PastProjects','Path':'Path','PictureURL':'PictureURL','PreferredName':'PreferredName','Responsibilities':'Responsibilities','Schools':'Schools','ServiceApplicationID':'ServiceApplicationID','SipAddress':'SipAddress','Skills':'Skills','UserProfile_GUID':'UserProfile_GUID','WorkEmail':'WorkEmail','WorkId':'WorkId','YomiDisplayName':'YomiDisplayName','WorkPhone':'WorkPhone','PhoneExtension':'PhoneExtension'</mso:ManagedPropertyMapping>

15.  In <body><div id=”Item_Person”> tag, add var has_wphone = !$isEmptyString(ctx.CurrentItem.WorkPhone);
var has_ext = !$isEmptyString(ctx.CurrentItem.PhoneExtension);

Item_PersonDiv

16.  In <div id=”ContactInfo”> tag, add

<!--#_ if(has_wphone == true) { _#-->



<div id="WorkPhone">
<!--#_ var encodedwphone = $htmlEncode(ctx.CurrentItem.WorkPhone); var displaywphone = Srch.U.getSingleHHXMLNodeValue(hhProps, "WorkPhone"); if ($isEmptyString(displaywphone)) { displaywphone = encodedwphone } _#-->



<div id="WorkPhoneValue" class="ms-srch-ellipsis" title="_#= encodedwphone =#_"> _#= displaywphone =#_ </div>



</div>



<!--#_ } _#-->
<!--#_ if(has_ext == true) { _#-->



<div id="PhoneExtension">
<!--#_ var encodedext = $htmlEncode(ctx.CurrentItem.PhoneExtension); var displayext = Srch.U.getSingleHHXMLNodeValue(hhProps, "PhoneExtension"); if ($isEmptyString(displayext)) { displayext = encodedext } _#-->



<div id="PhoneExtensionValue" class="ms-srch-ellipsis" title="_#= encodedext =#_"> _#= displayext =#_ </div>



</div>



<!--#_ } _#-->

ContactInfoDiv

17.  Save Client_Item_Person.html, upload it to the Display Templates/Search gallery, and publish it

18.  From Search Center, type in a query term (ex: Executive)

19.  From ‘Site Settings’, select ‘Edit Page’

20.  Edit ‘People Search Core Results’ Web Part

21.  Expand ‘Display Templates’, select ‘Use a single template to display items’, select Client_People_Item, then select ‘OK’

22.  Check In and Publish the People Results page (PeopleResults.aspx)

Your results page should look similar to the following.  Note that the OOTB only displays Name, Title, and Department.

PeopleResults

On my next post, I’ll cover how to add the e-mail to People Results page.

Happy search editing.

SharePoint 2013 Include People in Search Results – Duplicate Results

Leave a comment

I followed instructions in Steve Mann’s post on how to add people results in ‘Everything’ search results page.  All is well when you type in only first name or last name of the person.

When I typed in first and last name, two results are shown.

TwoPeopleResults

One titled ‘People Results’ came from the newly created query rule (People in Everything), and one titled ‘People Named’ came from OOTB SharePoint query rule.

This is not the desired results for me.  I only want one people results returned.

I modifed the ‘People in Everthing’ query rule to match either first or last name (unless you have the same first and last name, this rule will not work).

{subjectTerms} (LastName:”{subjectTerms}” OR FirstName:”{subjectTerms}”)

PeopleQueryRule

The search results now looks like this.

OnePeopleResultsBlock

Happy searching!

Add Term Sets to SharePoint 2013 Search Refinement Panel

Leave a comment

Following my previous post on working in Search Center.  Now I need to add crawled properties to the Search Refinement Panel.  These crawled properties can be content types, custom columns, or term sets.  In this post, I’ll use term sets.

My term store has regions which has U.S. States within each region populated.  For this example, we’ll use the West Region.

TermStore

Here’s my list with region term sets used.  I called that column “Store Region”.

BookList

After the list is populated with some values, go to List Settings –> Advanced Settings –> Reindex List

Just to make sure I get the crawled properties without waiting for the next scheduled crawl, I started the incremental crawl.

I then mapped the managed property to the crawled property.  In this example, I used RefinableString02 managed property.

In the mappings to crawled properties –> Add a Mapping –> I typed region and clicked Find

CrawledPropertySelection

Here I selected, ows_Store_x0020_Region, after a full crawl, I can now see the values in this mapped property.

From Search Center, after typing in a search term –> Edit Page, Edit Refinement web part properties, click Choose Refiners

In the list of Available Refiners, select RefinableString02 (this is what I mapped to in my earlier step).  Here, the list of available values displayed in the preview.

RefinableString02

Click Add –> Type a meaningful name in the Display name text box.  In my case “Store Region”, click OK to close the refinement configuration window, then click OK to close the web part properties window.  Check-in and publish the page.

Here’s the end product.

RefinementPanel2

Customize SharePoint 2013 Search Navigation

Leave a comment

I’ve been working on search, mostly search center, lately. I need to create a custom search navigation to display only content from a legacy SharePoint site. So, I thought I’d share my process here.

First, the content needs to be indexed by the local search service. In other words, SharePoint 2013 must index legacy SharePoint site(s). Second, you’ll need to have access to modify the search center. Since I created my Search Center in its own site collection, the steps outlined below reflect that.

1. Launch the Search Center site from the browser window
2. Select Site Settings
3. Under Site Collection Administration, select Search Result Sources
4. Select New Result Source
5. Provide a name for the new result source (ex: Legacy)
6. Under the Protocol section, select Local SharePoint
7. Under the Type section, select SharePoint Search Results
8. Under the Query Transform section, click Launch Query Builder
9. In the Query text box, type: {searchTerms} (contentclass:sts_listitem) path:http://<oldSharePointsite>
Your screen should look similar to the following screenshot:

LegacyQueryBuilder

10. To validate the query, click Test Query (This should return relevant results in the preview pane.)
11. Select the TEST tab, and select Show more
12. To mimic what a user will see in the Search Center, type a query in the {searchTerms}: box
13. Click Test query (This should return a filtered result view based on the value provided in the searchTerms box.
14. Click OK to close the Build Query window
15. Click Save to close the Result Source window
16. Select Add a page from the Gear Icon
17. Provide a name for the page (ex: Legacy), then click Create
18. In the Search Results web part, select Edit Web Part

19. In the Web part properties, click Change query

20. In the Select a query section, select Legacy (Site Collection) from the dropdown menu

LegacySiteCollection

21. Click OK to close the Build Your Query window
22. Click OK to close the Web part properties window
23. Check in and publish the page
24. From Search Center, select Site Settings
25. Under Search, select Search Settings
26. Under Configure Search Navigation section, select Add Link
27. Provide a title (ex: Legacy) (This will appear on the Search Navigation as “Legacy”)
28. Select Browse
29. Select Pages, select Legacy.aspx, then click Insert

30. Click OK to close the Navigation Link window
31. Click OK to close the Search Settings window
32. To validate changes made to the Custom Search Navigation, navigate to the Search Center site
33. Type in a query string – notice the results displayed at the bottom of the ‘Everything’ tab.
34. Click on the ‘Legacy’ tab, notice the results is less than the results in the ‘Everything’ tab

Your custom navigation should look similar to this:

CustomSearchNavigation

Happy searching!!

Content Search Web Part (CSWP) – Sort by Modified Date/Time

3 Comments

I was asked to look into Search crawl schedule because one Content Search Web Part settings was changed to sort the content by modified date.  Some contents were modified today, but did not appear at the top of page even though it was configured to sort in descending order.

Search was working fine.  It crawled at the schedule times for both incremental and full crawls.  I kicked off full crawl again, just to make sure.  Still the results displayed on the CSWP was incorrect.

I then looked into the CSWP settings itself.  Under SORTING, the only available field for modified time is LastModifiedTime.

CSWP - Sorting1

I select this property and sorted the list in descending order.

CSWP - Sorting2

I then went back to the Web Part settings and configured CSWP to display two lines with FileName and LastModifiedTime.  The page showed this:

CSWP - Sorting3

It sorted by LastModifiedTime, but this is not the result I was expecting.  It sorted by the LastModifiedTime that the documents were saved not when they were uploaded or the properties were modified in SharePoint.  I expected it to sort the same way my document library is sorted.  This is what I want to have displayed on my CSWP.  My document library looks like this.

DocumentLibrary

As you can see from the last two images, the result are nothing alike.

After searching many posts out on the internet, I did not find a solution.  So, I decided to do some testing on my own.

I went to Managed Properties and reviewed LastModifiedTime settings.  It contained this:

ManagedPropertyLastModifiedTime

After more research, I found that all Mappings to Crawl Properties listed above were related to documents.

I did not want to change any OOTB Managed Properties, so I decided to create a new one called Modified.

Here’s what I have in my new Modified Managed Property.

ManagedPropertyModified

I then started the full crawl.

Now my new Modified Managed Property is available for me to select in my CSWP Sorting.

CSWP - Sorting4

After changing the CSWP Web Part settings, it sorted in the same order as my document library, by Modified column.

CSWP - Sorting5

I hope this helps others who have the same problem I encountered.

Older Entries