Content Search Web Part (CSWP) is one of the great web parts introduced in SharePoint 2013 and Office 365. This web part uses the Search API and index to dynamically display results based on specific queries and rules on a content page.
The way it works is pretty simple; when a user navigates to a page, the web part initiates a query based on different inputs such as search box keyword, URL parameter, token, etc. You can also apply filters, refiners, and apply relevancy to the search results to make your SharePoint experience much more enjoyable.
I have spent a lot of time building dynamic portals, and, of course, at the same time troubleshooting issues why results do not show up. Let’s take an example where you want to build an image slider that loads the content from an image library. It’s pretty simple to build this in CSWP, where you pass the URL where you want to display, add some filters and voila, the results should show.
The Query can look like this:
path:"<URL of the library>“(IsDocument:"True" OR contentclass:"STS_ListItem")
In the above example I am submitting a query to load from a specific URL and return only the items. This will exclude for example, the AllItems.aspx page.
Let’s say you can build a complete portal based on CSWP, however, our topic here is not how to build a CSQP, but to troubleshoot why CSWP does not display results for you.
But wait, what if you are not getting any results back? Here are few tips to help you troubleshoot the issue.
In my recent scenario, my content was indexed, showing up in the default search results, and I had no filters. In fact, just adding the CSWP with no extra queries in it did not return anything. Typically, when you add the CSWP, it will automatically show you this:
After further investigation, looking at the way the portal is configured, I noticed something not adding up in the Alternate Access Mapping (AAM). The default AAM of the portal was not the same as the one it is being crawled. In my case the default AAM was http://portal and in the search content source I had http://portal.contoso.com.
Here’s the AHA moment! AAM did not match the content source; once I made sure that the default AAM and content source are a match, the content started showing up in my CSWP.