How to Configure Result Source for Search in SharePoint 2013

Posted on June 3, 2014 by Michael Simmons in SharePoint 2013 with 0 Comments

This article is going to demonstrate create a no-code solution to a simple problem in SharePoint 2013, which is how to display limited information to a user based on their permissions. More specifically, this solution will be a web page that shows a user a directory of all of the project sites within SharePoint that the user has permissions to view.

Result Source for Search in SharePoint 2013

Like any good solution, we are going to need a problem! It only makes for a good use of your valuable time and effort to begin with trying to solve a problem with your solutions.

The business need we’re trying to solve with this solution is this: We need a place for people to find all of the project sites that they have access to. It needs to automatically update – that is, new sites need to be added to the list without somebody going into the list and updating manually.

Using the SharePoint Search Service

At the heart of this approach is the SharePoint search service. We’ll be making some calls to the search service to get the list of sites. This takes care of one of our business needs – avoiding manual updates.

This search will be performed through a web part. However, instead of prompting the user to enter in search terms, we’re going to configure a web part to return a specific search query.

The specific search query we’re going to run will be created as a result source, which can be used like search result building blocks. If you only ever wanted to perform a search in one place, you could just enter that query directly into the web part. But by using a result source we can reuse that search result easily, in multiple places and in multiple web parts. And if we need to make a change to the result source, all of the web parts that use the result source are updated automatically.


Display Only Project Sites a User Has Permission to See

Are you ready to begin? We’ll have configuration items in a few places, so let’s get started.

Create a Result Source

  • Go to Site Settings.
  • Click Configure Search Result Sources under the Site Collection Administration heading.

Result Source for Search in SharePoint 2013 site settings

  • On the Result Sources list, click Add New Result Source.

Result Source for Search in SharePoint 2013 new result

  • Name the Result Source and provide a description. Click the Query Builder.

Result Source for Search in SharePoint 2013 query builder

Using Query Builder

Oh, now you’ve done it. You’ve started using the Query Builder. You just opened up a Swiss Army knife of search query goodness. The query builder lets you see the results that you get while you’re building the search query to make sure that your results match your expectations, and it gives you the tools to build exactly the kind of search you want. You’ll want to spend a lot of time exploring the query builder because you’ll be back here a lot now that you’ve seen it.

  • Select Only return sites from the keyword filter drop-down menu, then click Add keyword filter.

Result Source for Search in SharePoint 2013 return only sites

This adds contentclass:STS_Web into the query text. That will give us any webs in our search results, but in my testing I’ve gotten poor results with only this search term, with only subsites being returned and not the root sites in a site collection.

  • To remedy that, click Add keyword filter again (while “Only Return Sites” is still selected. This adds a second term to the query. Change the contentclass on one of the search terms from “STS_Web” to “STS_Site,” as shown below.

Result Source for Search in SharePoint 2013 sts site

  • From the property filter list, choose Show all managed properties. The chooser list then closes.

Result Source for Search in SharePoint 2013 show all managed properties

  • From the property filter list, which now has the full list displayed, choose WebTemplate, and then select Equals as a condition, and Manual Value as the value selector.
  • Add the manual value PROJECTSITE, then click Add property filter.

Result Source for Search in SharePoint 2013 property filter

  • Click Test Query to see a list of your project sites.

Result Source for Search in SharePoint 2013 test query

Note: Hopefully you’re seeing that what I’m showing you is a really specific use, and it’s not likely that this is exactly what you were going to use. It should be adapted for your use case. You might want sites of a different template, or you might want no template restrictions at all and try to get a totally different search result.

  • When you have your result source returning the sites the way you want them, click OK on the Query Builder.
  • Leave all of the other settings as default and click Save on the Add Result Source page.

Create a Page

  • Back on your site, click the Site Actions (the gear icon) and click Add a page. Give your page a name (I’m using “Projects”) and click Create.

Result Source for Search in SharePoint 2013 add page

  • If you having trouble adding a new page, you may have a feature turned off that needs to be enabled. You can continue with this exercise by editing an existing page. Just select the Page tab from the ribbon, then choose Edit page.

Add a Search Web Part to the Page

You can place the web part either into a web part zone, or into a content section of the page.

  • Click the section that you want to place the web part, and then choose “Web Part” from the “Insert” tab of the ribbon.

Result Source for Search in SharePoint 2013 insert web part

  • In the web part menu, choose the Search category and then choose Search Results. You can specify the web part zone where you want to add the part. Then click Add.

Result Source for Search in SharePoint 2013 web part

Configure the Search Web Part

Now that the search web part is added to the page, click on the web part. Once the web part is selected, a “Web Part” tab appears on the ribbon. Select the Web Part tab of the ribbon, then click on “Web Part Properties”.

Result Source for Search in SharePoint 2013 web part properties

Set the Search Query

  • Click the Change Query button.

Result Source for Search in SharePoint 2013 change query button

  • At the Select a Query drop-down, choose the result source you made (mine is “Project Sites”), then click OK on the Change Query dialog box.

Result Source for Search in SharePoint 2013 select query

Configure the Display Template

It’s worth mentioning the display templates at this point because it will determine how the results are formatted. Since we’re just getting started, we’ll leave them as default, but you should come explore the different display templates to see which style fits you best.

Remove the Language Selection Tool

If your site is in only one language, it doesn’t make sense to have the language selection option sitting out there. You can make it go away by expanding the Settings and removing the check in the Show language drop-down. Then click OK on the Web Part Properties

While it might not seem like we’ve done a lot, if this is the first time you’ve used a result source and a search web part on a page, then you’ve taken some huge steps. You now have a page that meets our initial requirements: a simple place where anyone can come and see the project sites that they have access to. Since the search is still being run under the context of a user running the page, only sites that the user has read permissions to will be returned in the results. And since the search results are being returned in real-time when the page loads, if somebody adds in a project site anywhere in the SharePoint farm you’ll see it the next time the search service performs an incremental search.

Have you made yourself a project site page? How has it worked for you? Let us know, or feel free to ask a related question in the comments below.


Tagged with