SharePoint 2013: Create custom Result Blocks using Query Rules
Introduction
In this article we are going to explore SharePoint Search Custom Result Blocks configured using Query Rules.
What is Results Block?
A Result Block is set of filtered results that are combined with core search results and displayed on top of the core search results as a block or can be ranked with in the Core Search Results depending on how you configure it to be.
It is not required to have results for Result Blocks from Local Search index only. A Result Block can use any of the result source from the below list:
- Local SharePoint farm
- Remote SharePoint farm
- OpenSearch
- Exchange
Preparation
In order to setup this demo, have prepared the system with some test User Profile data as described below:
We have setup three User Profiles with different job titles as shown below,
User 1: SP\Administrator
https://howtodowithsharepoint.files.wordpress.com/2015/05/19.png?w=450&h=294
User 2: SP\Guest
https://howtodowithsharepoint.files.wordpress.com/2015/05/22.png?w=450&h=293
User 3: SP\SPDeveloper
https://howtodowithsharepoint.files.wordpress.com/2015/05/32.png?w=450&h=294
Configure Query Rules
In order to configure Result Block, we need to start it with Query Rules configuration by using the following steps:
Go To Site Settings
https://howtodowithsharepoint.files.wordpress.com/2015/05/42.png?w=426&h=311
Under Search, click Query Rules
https://howtodowithsharepoint.files.wordpress.com/2015/05/52.png?w=282&h=300
Choose Result Source as applicable. Here we are working on Local SharePoint Search Results
Click New Query Rule
https://howtodowithsharepoint.files.wordpress.com/2015/05/62.png?w=450&h=138
Under General Information, enter Rule Name
Under Query Conditions:
- Select Query Options as needed, here Advanced Query Text Match works
- Select phrases which you want to be included while matching query text issued by the user
https://howtodowithsharepoint.files.wordpress.com/2015/05/72.png?w=450&h=317
Add Result Block
**
Click Add Result Block**
https://howtodowithsharepoint.files.wordpress.com/2015/05/82.png?w=450&h=122
Enter Block Title. T, this title will be added as Header with the Result Block displayed on Search Result Page.
Click “Launch Query Builder” Button
Select the number of items to be displayed inside the result block from Items Dropdown as shown below. Here we go with four items to be displayed inside Result Block.
https://howtodowithsharepoint.files.wordpress.com/2015/05/92.png?w=450&h=335
Configure the Query as shown below:
- Select a Result Source to as target for the query. Here we're using “Local People Results” as we have setup test data in User Profiles.
- Choose suitable property to filter on from Property Filter Drop Down
- Choose suitable Operator
- Choose suitable value type
- Choose suitable value as shown below
- Click on Add property Filter
- This will add the query filter to the Query Text box
- Click the Test Query Button to validate the query you have just created
- Search Result Preview Section will show few of the total search results returned by the query just configured in the previous steps
- Click OK to close Query Builder Dialog
https://howtodowithsharepoint.files.wordpress.com/2015/05/101.png?w=450&h=305
Always Choose the setting as shown below, if you want to have Result Block Displayed on top of Core Search Results as a separate block.
You can also choose to display “More” Items link, in case you want to show case the complete result set retuned based on the Query Rule. For this to happen you have to have a separate page configured with the same query to show all the results. Choosing here not to display it.
https://howtodowithsharepoint.files.wordpress.com/2015/05/112.png?w=450&h=135
And That’s it.
Test
We are all done with the configuration work for the result block and now it is time to test the results returned based on the configuration we did above.
Final Configuration would look like as shown below:
https://howtodowithsharepoint.files.wordpress.com/2015/05/121.png?w=450&h=177
In order to test the scenario, Enter “MOSS” or “sps” or “wss” as Search Term, remember we added **“MOSS, sps, wss” **in the search phrases while configuring Query Rules.
Since we got the search term “MOSS” or “sps” or “wss” as a Query issued by user, SharePoint Search System identifies a suitable query rule by matching this term with the phrases we specified while configuring Query Rules above and filter out the results based on the query we specified, in this case it was “JobTitle:SharePoint”, which mean finds any Profiles for which Job Title Property contains the word “SharePoint” .
Based on the query treatment as mentioned above we got two profiles “User 1: SP\Administrator” with Job Title “SharePoint Administrator” and “User 2: SP\Guest” with Job Title “SharePoint UI Designer”, displayed as valid results inside Results Block.
On the other hand, we do not get “User 3: SP\SPDeveloper” listed in the Result Block as Job Title Property for this profile is blank, due to this “JobTitle:SharePoint” match gets failed and this result get filtered out as shown below.
https://howtodowithsharepoint.files.wordpress.com/2015/05/131.png?w=450&h=377
https://howtodowithsharepoint.files.wordpress.com/2015/05/141.png?w=450&h=392
https://howtodowithsharepoint.files.wordpress.com/2015/05/151.png?w=450&h=402
Hope this will help someone in need.