Quantcast
Viewing all articles
Browse latest Browse all 21

Query Rules and Branding Search

A cool new SharePoint 2013 feature is the Search Query Rule where you can build statements that allow you to conditionally promote important results and show blocks of additional results.

In this post I will:

  • set up a simple Search Query Rule;
  • explain Result Blocks and Groups;
  • show what we can do with Groups in Display Templates.
  • make the look and feel somewhat more attractive.

Set up a simple Search Query Rule

Via the Site Settings > Search Query Rules (under Site Collection Administration) we can add new Search Query Rules. Choose a Content Source (context) for the rules to apply on. In this case I will choose the Local SharePoint Results. You will see SharePoint already provided some rules for e.g. Site and Image results. Choose New Query Rule.

Image may be NSFW.
Clik here to view.
SearchQueryRule

 

In this case we only add a Result Block that will show us some extra results while searching. For additional People results you can configure the Result Block to search in the Local People Results Content Source. Mind the Group Display Template is c Default Group instead of the Out of the Box Group Display Template Default Group. This new Group Display Template is a modified copy of the OOTB one and will be used for branding the additional results later on.

Image may be NSFW.
Clik here to view.
EditResultBlock

 

Give the Rule a name like “People Highlight” and click Save. We now have created a extra Search Query Rule that will give us additional People results when the Local SharePoint Results is used.

Image may be NSFW.
Clik here to view.
ResultBlock

 

Like many articles inlcuding the MSDN SharePoint 2013 Design Manager display templates (https://msdn.microsoft.com/en-us/library/office/jj945138.aspx) talk about Control and Item Display Templates. What not many people realize is that you have another level that is not really manageable via the UI, Groups. Note that the data-querryruleid matches the Search Query Rule ID we just created. The first Group is the default core results. ms-srch-group-border is shown in the previous image.

Image may be NSFW.
Clik here to view.
GroupDOM

 

Rendering the Groups will be done with the Search Query Rules and Core Results all as separated Groups. Of course this is not ideal when the customer asks something like this layout for their Local SharePoint Results. This is where the c Default Group Display Template can be useful.
Image may be NSFW.
Clik here to view.
GroupsLayout

Find the following line:
<div id=”_#= $htmlEncode(groupId) =#_” name=”Group” class=”ms-srch-group _#= markerCSS =#_” data-queryruleid=”_#= $htmlEncode(queryRuleId) =#_”>

and change it to:
<div id=”_#= $htmlEncode(groupId) =#_” name=”Group” class=”rightcolumn ms-srch-group _#= markerCSS =#_” data-queryruleid=”_#= $htmlEncode(queryRuleId) =#_”>

 

The rightcolumn class will let the Search Query Rule Group differ from the default Groups. With a short script in the c Control_Searchresults (copy from Control_Searchresults) these rightcolumn groups can be wrapped around with a parent DIV element for easier branding. col-6 in this case will float the rightcolumn Groups to the right side with a width of 50%. The left side of 50% will be filled with the Core Search Results.

Image may be NSFW.
Clik here to view.
WrapGroupsParent

 

The changed HTML for the Search Query Rule Result Block now looks like this:

Image may be NSFW.
Clik here to view.
WrapGroupsParentDOM

 

The final result is a cool looking results page where individual Groups can easily be styled. For example the first right column can be given a different background color so it will stand out with .rightcolumn:nth-child(1).

Image may be NSFW.
Clik here to view.
endResult


Viewing all articles
Browse latest Browse all 21

Trending Articles