SharePoint 2013: How To Create Custom Result Blocks Using Query Rules

In this article you will learn how to create Custom Result Blocks using Query Rules in SharePoint 2013.

In this article we are going to explore SharePoint Search Custom Result Blocks configured using Query Rules.

What are Results Block?

A Result Block is a set of filtered results that are combined with core search results and displayed on top of the core search results as a block or they can be ranked with in the Core Search Results depending on how you configure it.

It is not required to have results for Result Blocks from Local Search index only. A Result Block can use any of the result sources from the below list:

  1. Local SharePoint farm
  2. Remote SharePoint farm
  3. OpenSearch
  4. Exchange

In order to setup this demo, I have prepared the system with some test User Profile data as described below:

I have setup three User Profiles with different job titles as shown below:

User 1 : SP\Administrator

Administrator

User 2 : SP\Guest

Guest

User 3 : SP\SPDeveloper

SPDeveloper

In order to configure Result Block, we need to start it with Query Rules configuration by using the following steps:

Go To Site Settings,

4

Under Search, Click Query Rules,

5

Choose Result Source as applicable, here I am working on Local SharePoint Search Results,

Click on New Query Rule

Rule

Under General Information, Enter Rule Name

Under Query Conditions,

  1. Select Query Options as needed, here Advanced Query Text Match works for me
  2. Select phrases which you want to be included while matching query text issued by the user

add

Click on Add Result Block

Block

Enter Block Title, this title will be added as Header with the Result Block displayed on Search Result Page.

Click on “Launch Query Builder” Button

Select the number of items to be displayed inside the result block from Items Dropdown as shown below, here I will go with 4 items to be displayed inside Result Block.

Builder

Configure the Query as shown below:

  1. Select a Result Source to as target for the query, here I am using “Local People Results” as I have setup test data in User Profiles.
  2. Choose suitable property to filter on from Property Filter Drop Down
  3. Choose suitable Operator
  4. Choose suitable value type
  5. Choose suitable value as shown below
  6. Click on Add property Filter
  7. This will add the query filter to the Query Text box
  8. Click on the Test Query Button, to validate the query you have just created
  9. Search Result Preview Section will show few of the total search results returned by the query just configured in the previous steps
  10. Click OK to close Query Builder Dialog

Dialog

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. I am choosing here not to display it.

display

And That’s it.

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:

Configuration

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.

result

result

result

Hope this will help someone in need.

Read more articles on SharePoint: