With SharePoint 2013, we saw the arrival of SharePoint 2013 sites search and a new Web Part. This was already covered in the SharePoint 2013 migration series we covered earlier. In this article, I want to cover something very specific but very useful. The scenario is fairly simple; I want to manage all my projects using SharePoint. For this, I created a Site called “Projects” and created a sub site for each project I want to manage. My goal is to have the list of all my projects or sites in order to show it up on my main Projects Site.
Video: I also recorded a video showing these steps - see below.
Setting up my Site Collection
First thing first, I need to create the necessary sites for my scenario. As I said, I want a site called Projects with a subsite for each project I will be managing.
So I created the necessary site using the SharePoint 2013 interface.
Exploring the new Content Search Web Part
As you may have noticed, one of the new Web Parts in SharePoint 2013 is called the Content Search Web Part. Thanks to the new and powerful Search offered in 2013 with the Continuous Crawl, we can really use it in our operational sites. Back in SharePoint 2010 we would use the Content Query Web Part because we needed to see results instantly and not wait for the next crawl. However the Content Query Web Part was limited to the Site Collection it was in.
The new Content Search Web Part will allow me to create my own query easily and display the results the way I want. It is one of the many factors that will influence your SharePoint migration to 2013.
Adding the Web Part on the Projects site home page
I navigated to the site called Projects since it’s where I would like to surface all the available projects. Then I clicked on Edit Page to add my Content Search Web Part.
It can be found under Content Rollup
By default, the Content Search Web Part will want to show you the recently modified items in your current site. So don’t worry if you see weird things popping up at first. There is a good chance you will see some grey squares with a question mark as well, don’t worry about it. Basically, the Web Part is told by default to show you the recently modified items of your site and display them using what we call a Display Template that is there by default. A Display Template is similar to an Item style if you have some experience with Content Query Web Parts. But to be honest, they are kind of reusable designs that you can apply to your searches. In this case it is using an image on the left and the title on the right. Even I am getting some weird stuff.
Editing the Web Part to build our query
What should be the most complicated part of our article is probably the easiest thanks to this Web Part. You see the Content Search WP has a “Query Builder” so that even a Power User, owner of a site, can build some very cool solutions.
Let’s tell the Query Builder to fetch our sub sites.
First, click on Edit Web Part then click on Change Query
Once the Query Builder is open, you will some basic options for you to run your Query. Some of these options include limiting our search based on a Result Source, what we used to call a Scope or some other tags. We’re going to need the Advanced Mode to do what we need to do, but don’t worry it’s not that bad… I promise.
In the Advanced Mode, will navigate to the Query Text box and remove anything we don’t want. As you can see, by default it wants to search:
path:"http://demo/projects" (IsDocument:"True" OR contentclass:"STS_ListItem")
What this tells SharePoint is to search everything under that URL but limit results to Documents and List Items. But we need Sites! So I erased everything after the path to have only this in my Query Text:
What’s fun is that you can always Test your Query and see some sample results in the right pane. Love it!
What I am going to do next is to tell the Query I only want Sites returned. So click on the Keyword Filter dropdown menu and select Only Return Sites.
After I click on Add Keyword Filter, my Query Text box now shows:
If I test my results, I should see something interesting now.
We’re almost there! There seems to be a tiny issue, it’s still showing me the current site “Projects” as a project. I need to exclude this site from the query. Since the Content Search is located on this site, I figured I could just tell it to only show results of Sites that are not “This Site” meaning the one it is on.
To do this I clicked on Property filter on the right and looked for the Site property and made sure it was not equal to “This Site”
And as you can see, I am now only showing the sub sites! Wonderful.
Let’s save all our changes and look at the results.
Cool! Now we can really see all our sub sites show up, in this case I can see all my projects. If I was building an Extranet for my customers, I could do something very similar as well. The next step is all about design. For this example, I will simply use another one available Out of the Box but you could create your own Display Template to show these results the way you like.
What I did is change the Managed Properties used by default for the Display Template we had with the pictures.
Then I simply pressed ok.
This is a good reason to migrate to SharePoint 2013
To be honest, the more I am working with SharePoint 2013 the more I find reasons to make the switch over. Migration to SharePoint 2013 doesn’t have to be tough.
I already started covering some of the aspects of migrating in my series which I recommend to read if you want to learn more on other features now available.
In this short article, we saw how to use a simple Query with the Content Search Web Part to show our subsites, which are projects to us. We then were able to display them the way we want.