Content Search web parts or CSWP are probably the most useful web parts in my opinion. This post will give an introduction to CSWP’s, show how to edit the content that is displayed, and links to how to customize the display of CSWP’s at the bottom.
Adding a CSWP to a page
Go to the page, edit the page, click Insert, Web part, Content Rollup (Category) and Content Search web part.
Once the web part is on the page, click on the dropdown and select Edit Web Part.
Editing the CSWP query
In the web part properties, click the Change query button
When the query window opens, click the Switch to Advanced Mode option.
The advanced mode lets you configure the Query how ever you would like. After making changes click the Test query to see what types of results would be returned. In this example only results from the /cs/testsc/ootb site and that a type of document or list item will be returned.
The Keyword filter has a couple helpful pre-existing filters like sites, lists or libraries, or items (which is really files or items).
So for example, if you choose only return items and add the filter, it will insert the (contentclass:STS_ListItem OR IsDocument:True) filter:
The Property Filter
The Property filter is what you will use to create most of queries though, they have a short list of common property filters and then a option to Show all managed properties.
There are a ton of Property filters to choose from.
One property filter that I use quite a bit is the Author property, you can set the CSWP to only return items that were authored by the current user:
Or you can add a Property filter to only return items that were created in the last 5 days. Notice in this example, I used the Today’s date (-5 days) property filter, then customized it to 10 days after it was in my Query text.
This query returns files or items, authored by the current user, AND was created in the last 10 days:
Using Refiners to build property Query’s
Click on the Refiners tab, the refiners are great to show you a list of properties and their values that you can use to edit your Query Text. I rarely leave a Refiner added, as they are pretty restrictive. But find a refiner and Add it to see what items would be returned. In this case we are filtering the SPContentType property to only return an Item.
Once you find a refiner or two that you were looking for, remove the refiners and return to the Query text (Basics tab).
You can now type out the refiner, so SPContentType=Item accomplishes the same thing as the refiner did.
Typing our the Query text provides much more flexibility than refiners. For example by putting brackets around the property you can add an OR so you can return both the Item OR Document type:
Sorting the displayed results
Click on the Sorting tab, by default your items will be sorted by search result rank which usually doesn’t make much sense for CSWP since no is entering a search term.
The two sort orders I use most often are either sorting by LastModifiedTime Descending then by Created Descending. This should display the most recently edited content first.
Or by ViewsRecentUniqueUsers Descending then by ViewsLifeTimeUniqueUsers descending. This should display the content that has had the most unique people view it first.
More web part settings
Once you are done editing your query, click the OK button to return to your web part properties. Below the Change query button you can change the numbers of items shown in the web part.
The Control lets you choose to regular list view of items, a list view with a paging control, or a slideshow version which usually works best for videos or images.
The Item control allows you to select which display template for the web part. The display template controls the number of fields you can show and whether to display an image or not.
Expand the Property Mappings section and check the Change the mapping of managed properties option. This allows you to specify different properties to display, depending on what display template you choose you will have a different number of fields shown here.
For example this is the ‘Picture on left, three lines on the right’ Item display template with properties changed to display the Title, Author, and LastModifiedTime.
By default the Picture URL property is configured to show the PublishingImage;PictureURL;PictureThumbnailURL. Unless the results are publishing pages or images though, they probably won’t have an image specified for them. So how do you change that?
You can actually add an existing column to any list or library on SharePoint that the CSWP will automatically display any image specified for. Just go to the list or library, click on list/library settings, and under the Columns section click on Add from existing site columns.
Scroll down to the Rollup Image column, and Add it to the list or library.
You will now be able to specify an image for your list or library items.
In this example I specified Rollup Images for documents in my library.