Stage 9: Configure the query in a Content Search Web Part on a category page

This is a blog post in the series “How to set up a product-centric website in SharePoint Server 2013.”  In this series, I'll use data from a fictitious company called "Contoso" to show you how to use search features to set up a website based on product catalog data.
Note: Most of the features described in this series are not available in SharePoint 2013 Online.

For an overview of the blog posts in this series, go to How to set up a product-centric website in SharePoint Server 2013.


Quick overview

In previous blog posts, I showed you how to create a category page and a catalog item page. I also showed you how to assign these two pages to terms within the Site Navigation term set.  When we browsed to the "Audio" category, we couldn't see any content. This was because when we created the category page, we didn't add any Web Parts.


In this stage we will start to merge different pieces of what we have done in previous steps. In this blog post we'll learn:


Start stage 9

To display content on our Contoso website, we'll use the Content Search Web Part.


About the Content Search Web Part

The Content Search Web Part (CSWP) uses, as its name implies, search technology.

Most of us use search technology on a daily basis. Think about how many times a day you enter query terms in a search box, for example on; how after pressing Enter, you scan search results that are almost immediately displayed on a search results page (by the way, how did you find this blog post?).

When visitors browse to a page that contains a CSWP, they're probably not aware of this, but they're actually issuing a query. However, the thing that differs with CSWPs is that instead of entering query terms in a search box, the query is contained within the Web Part itself. This means that when a visitor browses to a page that contains a CSWP, this query is automatically issued.

Another thing that is different from the search scenario is that search results aren't displayed on a separate search results page, but within the CSWP. In most cases, visitors won't even know that search technology is being used to display the content they're viewing. To them, it'll look and feel like any other webpage.


How to add a Content Search Web Part to a page

Browse to the page where you want to add the CSWP. In our scenario, let's browse to "Audio".

  1. Click the Settings menu, and then click Edit Page.
  2. In the Web Part Zone where you want to add the Web Part, click Add a Web Part.
  3. In the Categories list, click Content Rollup.
  4. In the Parts list, click Content Search, and then click Add.

In our scenario, we'll add a CSWP to Zone 3.

CSWP added

The CSWP contains a default query, so it already displays some content (Audio, Cameras and Computers) -- but not the content we want to display. To make the Web Part display Contoso catalog content , we'll need to configure the query in the Web Part.


How to configure a query in a Content Search Web Part on a category page

  1. In the Web Part, click the Web Part Menu , and then click Edit Web Part.

Edit Web Part

  1. In the Web Part tool pane, click Change query. This will open a dialog box.

Change query

In the dialog box, notice that "Audio" is shown in the top left corner. This is the category which we navigated to and selected to edit the page from. Also notice, that in the RelevantResults section, the top three results, Audio, Cameras and Computers, are listed. These are the same three results that were shown in the Web Part when we added it.

CSWP default query

  1. From the Select a query list, select your catalog result source. In our scenario, it's catalog - Products Results.

CSWP result source

A result source narrows the scope from which search results can be retrieved. When we connected our publishing site to our catalog, SharePoint Server 2013 automatically created a result source for our catalog. In our scenario, this result source is named catalog - Products Results. By selecting this result source, only search results from our catalog are retrieved.

For more information about result sources, see Plan result source and query rules.

When we selected this result source, the number of RelevantResults changed from 864 to 775. 775 happens to be the number of items we have in our catalog. Therefore, selecting this result source confirms that we're on the right path to configuring the query.

  1. In the Restrict by tag section, select Restrict by current and child navigation terms.

CSWP restrict by tag

A key phrase in this selection is navigation terms. This refers to the category in the site navigation the visitor is browsing. In this particular case, the visitor is browsing the "Audio" category.

Audio URL

Remember, one of the first things we did in this series was to import catalog content into a list. We also imported terms into the term set Product Hierarchy, and associated each item in the list with a term from that term set.  When we connected our publishing site to our catalog, we specified that the full site navigation should contain terms from the Product Hierarchy term set. Because we have used the same term set to tag the items in our catalog and to build our site navigation, we can use a term from our site navigation to search for catalog items that have been tagged with that same term.

So, our query in the CSWP will therefore display search results for items that are in the catalog - Products Results result source, and that have been tagged with either "Audio", or any of the children of "Audio", for example "MP3 players" or "Speakers".

This selection reduced the relevant search results to 114, which happens to be the number of items in our catalog that belong to the "Audio" group.

Another key phrase from the selection Restrict by current and child navigation terms is "current." I'll talk more about the importance of this phrase in the next section.

  1. Click OK, and save the page.

On the "Audio" category, the search results have changed to show different results.

Audio results

If you browse to the "Cameras" category, you'll see three other search results displayed.

Camera results

If you browse to the "MP3" category, you'll see three other different search results are displayed.

MP3 results

If you are now thinking "OK, I understand how we got the correct search results for the "Audio" category, because that is the category we clicked, and where we changed the query in the Web Part. But why do we see different search results when we browse the catalog? And shouldn’t we change the query for all the other categories as well?"

Well, let's take a closer look at what's going on.


About the query configuration

We only had to configure one query because the same page is used for all categories. Remember how in stage 8 we assigned the page ContosoCategoryPage.aspx to all terms within the Site Navigation term set? We assigned this page to all terms, so even though we edited this page in the "Audio" category, we could have edited it in any other category, and achieved the same result.

We only had to configure the query once, because the query issued from the Web Part differs depending on which category we browse to. Remember that the CSWP contains a query that is automatically issued whenever someone browses to a page that contains a CSWP, and that search results are displayed in the Web Part. Also, remember that we selected Restrict by current and child navigation terms when we configured the query in the Web part. The word "current" is very important, because it means that the query issued by the CSWP will change depending on the category the visitor is currently browsing. If you edit the Web Part from another category, you can see that the Web Part has changed.

For example, if I browse to the "Cameras" category and take a closer look at the CSWP, I can see that:

  • "cameras" is included in the URL.
  • "Cameras" is in the top right corner of the query configuration.
  • The number of RelevantResults has changed to 118, which happens to be the number of items in the catalog that belong to the "Cameras" group.

CSWP camera query

So, when I browse to the "Audio" category, the CSWP issues a query for catalog items that have been tagged with "Audio" or any children of "Audio", and displays search results. When I browse to the "Cameras" category, the same CSWP (remember, we only used one page for all categories) issues a different query, this time for catalog items that have been tagged with "Cameras" or any children of "Cameras", hence different results are displayed.


How to view details of the query configuration

To view details of the query configuration, click on the TEST tab. The actual query issued by the CSWP, is shown in the Query text field.


In our example, the query that is issued by the CSWP from the "Audio" category looks like this:

(contentclass:sts_listitem OR IsDocument:True) SPSiteUrl:http://contoso/sites/catalog ListId:3a3f66cd-9741-4f15-b53a-b4b23c3187ea owstaxidProductCatalogItemCategory:#c771504f-6a2f-423f-98de-0e12fcfa08c9

If this doesn't make any sense to you, don't worry!  There is a logic to it, and I'll break it down to make it clearer.

  • (contentclass:sts_listitem OR IsDocument:True) SPSiteUrl:http://contoso/sites/catalog ListId:3a3f66cd-9741-4f15-b53a-b4b23c3187ea
    is our catalog result source, catalog - Products Results 
  • owstaxidProductCatalogItemCategory
    is the managed property for the site column Item Category (remember, our Product Hierarchy term set is tied to the Managed Metadata site column Item Category)
  • #c771504f-6a2f-423f-98de-0e12fcfa08c9
    is the GUID of the term in the current navigation, in this case "Audio"


In our Product catalog site collection, in the Product Hierarchy term set, you can see that the GUID represents the term Audio.

GUID audio term


So now we have configured the query for the CSWP on our category page. We still have to do some configuration to make it display more than three search results, and also give it a "Contoso look." I will show you how to do this in a later post. The next step is to add a CSWP to our catalog item page, and configure the query to show individual catalog items.



Next blog post in this series
Stage 10: Configure the query in a Content Search Web Part on a catalog item page



Additional resources
Configure Search Web Parts in SharePoint Server 2013
Scenario: Create SharePoint sites by using cross-site publishing in SharePoint Server 2013

Comments (31)
  1. Anonymous says:

    How and when "Product Catalog – Product Results" result source got created in the publishing site?
    Why can't I edit it?

  2. Anonymous says:

    Its a really a good Article !

  3. Bella_Engen says:

    Hi Lisamariew71,

    Glad to hear that you are eagerly awaiting the next article 🙂

    Last week and this week I have hit a bit of a snag, but I will do my best to get the rest of the articles out as soon as possible.


  4. Catch my 5 stars rate!

  5. Bella_Engen says:

    Hi again Lisamariew71,

    I will publish the next post on May 23rd.


  6. Bella_Engen says:

    Hi Rothrock,

    I’m sorry, but I’m still a bit unsure about your scenario. Are you trying to set up a search center on your publishing site? If so, have you created a new site collection for where you can configure your search results page?


  7. Bella_Engen says:

    Hi Ravi,

    Glad to hear that the posts have been useful 🙂 At the moment, I don’t have an ETA on the next step, but will post a publishing date soon.

    However, note that in the step on how to customize the catalog item page, I will show you how you can do this by using a Content Search Web Part (I will explain why I want to use a Content Search Web Part and not Catalog Item Reuse Web Parts in the blog post). Also, I will only explain how to set the query in the Content Search Web Part, and not talk about any design elements.  

    If you are interested in how to customize the automatically created catalog item page, see this article on MSDN:…/dn144674.aspx

    Hope this helps.


  8. Bella_Engen says:

    Hi Rothrock,

    Just to be sure, you’ve set up your sub site on your publishing site, correct? If so, you’re definitely on the right path.

    On the sub site, create a new page that you’ll use to display your search results. On your publishing site, configure the Search Settings so that queries are sent to your newly created search results page.

    You can configure your new search results page in several different ways. But to make sure that you get search results from your catalog, add a Search Results Web Part to your new page, and configure it to use your catalog result source. If you then enter the
    query "cameras" on your publishing site, the Search Results Web Part will display only catalog item. By default, the URL that’s displayed in the Search Results Web Part, is the URL of the catalog item itself. Most likely this URL will be /DispForm.aspx?ID
    something. However, when you hover over a search result, notice that the friendly URL is displayed. Also, when you click on a search result, you’ll be taken to the item on your publishing site. To change the way your search results are displayed, you have
    to modify the display template(s) for the Search Result Web Part. For information on how to do that, see this blog series:

    Now, regarding the other content that you want to display on your search results page. I don’t know your content well enough to say if you can use KQL so that all content is shown within the same Search Results Web Part. But, have you considered using different
    search verticals for the different content? For more information about search verticals, see this blog article:


  9. Bella_Engen says:

    Hi Rothrock,

    When you set up your result source, in the Protocol section, select from where the search results should be retrieved (

    Regarding the search box, I don't quite understand your question. Could you please elaborate?


  10. Bella_Engen says:

    Hi Jimbo,

    Just to make sure we’re on the same page, you mean the result source that is automatically created when you connected to your catalog, correct?

    If so, have you in anyway made changes to this result source?


  11. Bella_Engen says:

    Hi Zach,

    Have you tried to use the Local People Results result source when you configure the query of the CSWP? This result source will return items from the profile database and the User Profile service application.

    When you have the search results that you want, you'll have to modify the display template. To see how people results are displayed in the Search Center, you can take a look at the Item_Person display template (Site settings –> Master pages and page layouts –> Display Templates –> Search).

    Hope this helps,

  12. Anonymous says:

    Any idea when the next article will be available?  I am waiting with bated breath! 🙂

  13. Anonymous says:

    Great article! Very useful!!

  14. Bella_Engen says:

    Hi Muralee,

    Glad to hear that you like the series :-)

    At the moment, a seperate series on how to integrate e-commerce is not planned. However, should that change, I’ll be sure to let you know.


  15. Bella_Engen says:


    The result source was automatically created when you connected your publishing site to your catalog ( You can edit the result source by going to Site settings –> Search Result Sources.​

    Hope this helps.


  16. Bella_Engen says:

    Hi Rothrock,

    I’m glad to hear that you got it to work 🙂

    It sounds like you have quite a few different data sources. You might be able to combine them and set up a solution that uses your current data set, but you run the risk of this becoming increasingly difficult to maintain when your data set grows.

    I think search verticals are a very good way to "separate" results on a search results page. Depending on how your data is structured, you might be able to filter the different types of search results by using refiners (
    But that really depends on how your data is structured.


  17. Bella_Engen says:

    Hi Bernado,

    Yes, you can configure the CSWP to collapse, or group, search results. To do this, in the CSWP tool pane, click Change query.  In the Web Part dialog box, click the REFINERS tab, and then Show more. This will open an option where you can group results by
    a managed property.

    To use the Contoso scenario as an example, the color versions of the products are grouped under Group Number (…/stage-10-configure-the-query-in-a-content-search-web-part-on-a-catalog-item-page.aspx).
    On the category page, I could configure the CSWP to group results based on the managed property for Group Number.

    Hope this helps.


  18. Ravi Sakaria says:

    This whole series of posts has been extremely useful – the only problem with it is that I'm eagerly waiting for you to write step 10 (customizing the category-item pages)!

  19. Muralee says:

    Bella Nice work, Hope you can churn out whole stuff for e-commerce from SharePoint 2013.

    Like a connected web part in category page for ale-carte.

  20. Bernado Nguyen-Hoan says:

    Hi Bella,

    Thanks for this great series!

    Is there a way to configure the CSWP to collapse and display only 1 result for items with the same title (but different colours)? So instead of displaying 3 results for "Compact Digital Camera M190" (because it is available in 3 colours) – just display 1 result for that item on the category page?



  21. Vinay Gupta says:

    Its a really a good Article !

  22. Rothrock says:

    How do I use the result source to include the remote catalog in my local site search? I find it odd that all the term-driven pages rely on search behind the scenes, but that the actual search box doesn't include the remote content. And if I change the
    scope to "everything" I find the items on my catalog site.

  23. Rothrock says:

    When I connect my managed catalogs to my publishing site, new search result sources are automatically creatted for me. And if I go in and launch the query builder dialog I see those catalog items in the search result preview. So that is all good.

    The default search result source is "Local SharePoint Results." I tried changing the default to the result source of my catalog, but that didn't help. Ideally we want both the local results and any connected catalogs to all appear together as "this site." Because
    from the user's perspective the site is the site, there isn't anywhere else. They can navigate to something on the site then they would expect search this site to also find that same item.

    But when the user performs a "search this site" using the search box they don't get any results. So for your contoso example it is as if a user typed "mp3" in the search box and got no results. Which from the user's perspective is completely wrong.

    The next step after they get no results is that the default search results page offers the user to "expand your search to everything" which takes the user to the Everything search — which searches beyond our site/site-collection. At that point the results
    from our catalog site are returned. So in your contoso example the "mp3" search would show all the mp3 players in your catalog site — taking the user away from contoso and to the catalog. Again, not what we would want.

    I've spend weeks trying to figure this out and can't find anyway to make the remotely connected catalogs/lists appear in user initiated searches.

  24. Rothrock says:

    I don't know what the solution is. If setting up a search center will get me the result I want then that is what I'm trying to do!

    Just like in your example. If the user was to type "camera" into the "search this site box," what would they get as results? In the cross-site publishing set up I have, they would get zero results. Even if they were on a page full of cameras. If in your example
    they would get results, then what did you do to include the remote catalog into the search results?

    I have three search result sources: Local SharePoint Results (provided by SharePoint), and two lists provided through cross-site publishing LS CSP CAT – Products Results and Learning Sessions Results. I want all three of those to be considered as "Search this
    site" because from the user's perspective those are the things they could navigate to on the site and they are the things they should be able to search on the site.

  25. Rothrock says:

    PS: I have set up a sub site for a search center. I created my own search result source that includes my best guess as to how to combine the KQL from the three individual sources. But I get things from other sites and the catalog items aren't rewritten
    to look like they are local.

  26. Rothrock says:

    Yes! That is it. Thank you. This is making some sense. Last night I was able to get it working by creating a new source and a basic search center sub-site. But since we have several managed catalogs coming together the KQL for that will probably get unmanagable.
    I'll try what you have suggested. Do you think it will be easier to combine multiple result sources with this approach?

    The verticals also look very promising and I hadn't even thought of those.

  27. Zach W says:

    This is a great write up. After reading it got my mind thinking…do you know of a way to use this CSWP to display people results along with their display picture? I am thinking it would make a good dynamic employee directory if I could get the query to
    return all people results with their picture, title, and dept.


  28. Jimbo says:

    Great series!

    When I attempt to configure the query, the Result Source created for the catalog doesn't show up in the dropdown in Quick Mode, only in Advanced Mode (where I don't have the option to select the Navigation term and its children). Any idea what might be going
    on with that?

  29. Jimbo says:

    Correct, I mean the Result Source that is automatically created when connecting to the Catalog; it doesn't show up in Quick Mode, only in Advanced Mode when configuring the Content Search Web Part.

    I've made no changes to the Result Source.


  30. Ann says:

    Hi Bella, I would be really grateful if you could guide me for the below query :

    I have a requirement where there we have authoring site and publishing (public facing internet site).

    We have a set of modules and each module has a set of courses.

    The course structure is such that the content authors can upload and download pdf document for each course. But the same structure in publishing site should allow only downloading of pdf documents for users.

    Query1 :In such a scenario, should I use a document library or custom list?
    Query 2: Is it mandatory to have managed metadata column…terms and term sets for list and libraries. Does it contribute anything to the search index?

    Being a sharepoint beginner, I'm really stuck as to where to start from. Please guide me. 🙁

Comments are closed.

Skip to main content