Recent

Content Search web part (CSWP) Setup

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.
cswp-1

Once the web part is on the page, click on the dropdown and select Edit Web Part.
cswp-2

Editing the CSWP query

In the web part properties, click the Change query button
cswp-3

When the query window opens, click the Switch to Advanced Mode option.
cswp-4

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.
cswp-5

The Keyword filter has a couple helpful pre-existing filters like sites, lists or libraries, or items (which is really files or items).
cswp-6

So for example, if you choose only return items and add the filter, it will insert the (contentclass:STS_ListItem OR IsDocument:True) filter:
cswp-8

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.
cswp-9

There are a ton of Property filters to choose from.
cswp-10

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:
cswp-11

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:
cswp-12

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.
cswp-13

Once you find a refiner or two that you were looking for, remove the refiners and return to the Query text (Basics tab).
cswp-14

You can now type out the refiner, so SPContentType=Item accomplishes the same thing as the refiner did.
cswp-15

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:
cswp-16

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.
cswp-17

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.
cswp-18

Or by ViewsRecentUniqueUsers Descending then by ViewsLifeTimeUniqueUsers descending.  This should display the content that has had the most unique people view it first.
cswp-19

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.
CSWP-20.jpg

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.
cswp-21

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.
cswp-23

Picture URLs

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?
cswp-24

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.
cswp-25

Scroll down to the Rollup Image column, and Add it to the list or library.
cswp-26

You will now be able to specify an image for your list or library items.
cswp-27

In this example I specified Rollup Images for documents in my library.
cswp-28

About Nick Hurst (84 Articles)
SharePoint and Nintex developer who strives to find easy to deploy and maintain solutions for business problems.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: