Pages

Thursday 7 May 2015

Content by Search Web Part

Adding the Content by Search Web Part

Before we being, you must first add a CSWP to your SharePoint page.
1. Click Edit on the Page ribbon.
clip image001 thumb Content by Search Web Part
2. Click the Insert ribbon and then click Web Part.
clip image003 thumb Content by Search Web Part
3. From the Content Rollup category, select ‘Content Search’ and then click Add.
4. Choose the drop down arrow of the Content by Search web part and click Edit web part.
clip image004 thumb Content by Search Web Part

Configuring the Query

Now that you have added the CSWP to the page, we can configure the query to return the desired results. The CSWP can aggregate content from any list or library from within the SharePoint farm and then filtered based upon the type of content or by meta data. Once the query has been built, you will be able to configure the display options.
To configure the query:
1. From the toolpane of the content by search web part, click the ‘change query’ button.
clip image005 thumb Content by Search Web Part
2. The CSWP dialog displays allowing you to configure the query using four different tabs.
clip image007 thumb Content by Search Web Part
3. The Basics tab displays some configuration options on the left hand side pane and preview results in the right hand pane. This is useful allowing you to see what content your web part will display prior to completing the configuration.
4. The first field in the Basics tab is the ‘Select a query’ field. The queries that you can select from are ‘Result Sources’ which are configured within the Search Service application through SharePoint Central Administration or via the Site Settings.
clip image009 thumb Content by Search Web Part
5. The example I will give is a configuration to rollup Tasks from Task lists. One thing we know about Tasks is that they are created using the Task content type of a content type that derives from Tasks. Therefore, I will select ‘Items matching a content type’ as my result source.
clip image010 thumb Content by Search Web Part
6. You can then choose your scope using the ‘Restrict by app’.
clip image011 thumb Content by Search Web Part
7. Although, the field is not in the correct order, the next field to set would be the ‘Restrict by content type’. Note that this field will change depending on your Result Source. Set the option to Task to rollup tasks. The preview pane should show the tasks that you will be aggregating.
clip image013 thumb Content by Search Web Part
8. You can then further restrict the results using the Restrict by tag or Add addition filter options.
9. You can further refine the results using the Refiners tab. An example would be filtering by Author or Assigned To.
clip image015 thumb Content by Search Web Part
10. The Settings tab allows you to set certain settings that affect the load behaviour of the web part among others.
clip image016 thumb Content by Search Web Part
11. The first setting it whether to use Query Rules. The Query Rules are set within the Site Settings and can be used to fine tune the search results.clip image018 thumb Content by Search Web Part
12. Finally the Test tab provides you with the query text which can be used to test the search results.
clip image020 thumb Content by Search Web Part

Configuring the Display of your results

Now that the scope and the query is set, we need to make the results look better. The CSWP toolpane contains Display Templates depending on how you want to display the results. There are three types of control. List, List with Paging or Slideshow. The Item will field will then show variations of the displays using the display templates.
clip image021 thumb Content by Search Web Part
Once you have selected the display template, expand the Property Mappings and populate the managed property fields with the columns that you wish to display. In my example I have configured the display settings for a Task List.
clip image022 thumb Content by Search Web Part
The results are now shown within the Web Part.
clip image023 thumb Content by Search Web Part
Clicking the hyperlink for each result will navigate you to the item itself.

No comments:

Post a Comment