Microsoft introduced the Content Search Web Part (CSWP) with SharePoint 2013. It's a powerful feature most accurately compared to the Content Query Web Part (CQWP) which came with previous SharePoint versions.
Unlike its predecessor, Content Search allows you to query and display information from any site collection and beyond. Essentially, if SharePoint can crawl and index it, the CSWP can rollup that content and display it.
And if you've worked with CQWP you probably experienced the long load time while it ran its query, especially when a CQWP surfaced on a home page. CSWP remedies that issue by surfacing content during the regular SharePoint crawl.
Below we'll take a look at the different CSWP parts and some basic configuration tips.
Getting Started with Content Search
1. First step is to edit your SharePoint page and add the CSWP. This can be found in the Content Rollup.
2. To configure the web part, first click anywhere in the web part, then choose the Web Part tab in the ribbon. From that tab click Web Part Properties.
3. You will need to set up the query. To do so click Change Query from the web part properties box.
4. A Build Your Query dialog box will open. There are four tabs available — Basics, Refiners, Settings, Test. From the Basics tab you should see Switch to Advanced Mode in the upper right corner. If you see Switch to Quick Mode, click it. We will start with Quick Mode, which allows you to quickly create a query, select the scope, refine by metadata and add additional filters as needed.
5. The Select a query menu includes Documents, Items matching a content type, Items matching a tag, Items related to a current use, Pictures, Recently changed items, etc.
6. Under Restrict by app you can opt to query the Current Site Collection, Current Site, Specific URL, or you can choose Don’t restrict results by app and query everything that you are currently crawling.
7. Restrict by tag allows you to select a single Managed Metadata term to further filter the content that your query returns.
8. At this point you, can add additional filters or Switch to Advanced Mode for more options. You will need a general understanding of search query syntax to use some of the features of advanced mode. However I've found it possible to click through the options to add a few additional advanced queries with a limited knowledge of the syntax. Some examples include receiving a parameter from my URL (i.e., Query String), and filtering on managed properties (site columns, etc.). For more information on working with managed properties see my search feature article here.
9. The right hand side of the query builder displays a sample of what is currently returning to the web part.
10. The Refiners tab allows you to filter your query even further.
For example, my query returned all items with the tag Scientist, which included documents in the results. If I was only searching for images, I could use this tab to refine the results by content type — Picture. This is also possible in the Quick Mode view, so one takeaway is that the query builder gives you several options for getting the results you need.
11. The Sorting tab allows you to choose a managed property to sort your query by. You can fine tune this further by using a ranking model or setting up ordering to demote or promote certain results based on a value. For example, if a result includes a certain metadata tag, it should always appear above other results.
12. The Settings tab has a few additional options including the use of Query rules and the loading behavior of your query. You can choose whether the query is issued on the server while the page is loading (which is preferred) or from the browser after the page load.
13. The tab Test gives you your final query text for testing purposes. When finished simply click OK at the bottom of the Build Your Query dialog box.
The final step is to setup how results will display. From the Web Part Properties box you have the following options:
- Number of items to show: how many results do you wish to display at once?
- Under Display Templates — Control: options include list, list with paging, and slideshow
- Under Display Templates — Item: determines how images and text will display. Options include diagnostic, Large Picture, Picture on left 3 lines on right, Picture on top 3 lines on bottom, Recommended items, Two Lines and Video
- Under Display Templates: Don’t show anything when there are no results (leave this checked to avoid blank space, especially when using the slideshow control)
- Under Property Mappings — Uncheck “change the property mapping of managed property” if you wish to customize which fields are shown with the result. The fields available here correlate directly with the Item chosen in the option above. I have used this in the past to display a custom site column with my results instead of the default title, path etc. The options in the dropdown menu are your managed properties
When you're happy with your settings, right click OK to close your web part and you’re done!