Partager via


How to configure the Search Results Web Part to use a new result source in SharePoint 2013

This is a blog post in the series “Set up a Search Center in SharePoint 2013”. 

In the previous blog post, I showed you how to create a Search Center Site Collection and enable crawling of your content. In this post you’ll learn:

 

How to turn off versioning for the Pages library
If you don’t want to check pages in and out when you configure the Search Results Web Part, you can turn off versioning for the Pages library.

To turn off versioning for the Pages library:

  1. Go to Site settings --> Site contents.
  2. On the Site Contents page, click the Pages library.
  3. In the Pages library, click the LIBRARY tab and then Library Settings.
  4. On the Settings page, click Versioning settings.
  5. On the Versioning Settings page, in the Content Approval section, for Require content approval for submitted items, select No.
  6. In the Document Version History section, for Create a version each time you edit a file in this document library, select No versioning.
  7. In the Require Check Out section, for Require documents to be checked out before they can be edited, select No.

Turn off versioning for the Pages library

 

Why you should consider creating a result source for your Search Center
A result source specifies where your search results can come from.

For example, in my scenario, I did not want search results to come from all sites within the SharePoint farm. I only wanted search results from one specific site within the farm.

The default result source in a Search Center returns search results from the entire SharePoint farm. If you want search results from the entire SharePoint farm, you can skip to the next blog post in this series.  However, if you want search results from only a sub set within your SharePoint farm (in my scenario, one specific site), you should create a result source.

 

How to create a result source
Depending on your permission level, you create a result source on three levels:

Permission level Where the result source will be added
Search service application administrator To all site collections within the farm
Site collection administrator To all sites within a site collection
Site collection owner To a single site

To save space, I will only show you how to create a result source as a Site collection administrator.

  1. Go to Site settings --> Search Result Sources.
  2. On the Manage Result Sources page, click New Result Source.

New result source

  1. On the Add Result Source page, enter a Name. Select values for Protocol and Type, and click Launch Query Builder. This will open a dialog box.

    In my scenario, I named the result source Articles, and kept the default values for Protocol and Type.

Specify new result source

  1. In the Build Your Query dialog box, define the result source.

    Remember, in my scenario, I only wanted search results to come from a particular site within the farm, so in the Query text field, I added the following:
    {searchTerms?} (contentclass:sts_listitem) path:https://<path>

Specify query for new result source

Now, before we move on, let me break down what I entered:

  • {searchTerms?} In my result source, I wanted to include the words that users type in the query box whey then search for something. Obviously I have no way of knowing what users will type, so I added the query variable {searchTerms?} By the way, you can tell it’s a query variable because it’s enclosed in curly brackets.  When users enter a query, this query variable will be replaced by the words the users have typed in the query box. The question mark at the end of the variable means that if no words have been entered, the variable should be ignored.
  • (contentclass:sts_listitem)  This means that only list items will be included in my result source.
  • path:https://<path>   This is the path to the site from where I wanted search results to come from.  
  1. Test that the result source is working correctly by clicking on the TEST tab, and then Show more.

Test result source

  1. In the {searchTerms} field enter Query words to simulate a query entered by a user, and then click Test query.

    In my scenario, I entered search configuration.

Test specific query for result source

Notice that 52 results were returned (I will tell you why this is kind of cool in the next section…).

  1. Click OK to close the dialog box, and then Save.

So now that we have a result source for the Search Center, we can move on to configuring the Search Results Web Part to use the new result source.

 

How to configure the Search Results Web Part to use a new result source
By default, the Search Results Web Part is used on the search results page. In order to configure the Search Result Web Part, you have to navigate to the search results page.

  1. On your Search Center home page (the default URL to this page is <site>/Pages/default.aspx), enter a query in the search box, and press Enter.

    In my scenario, I entered search configuration.

Enter query on search page

When you press Enter, you will be taken to the to the search results page (the default URL to this page is <site>/Pages/results.aspx).

In my scenario, 1,051 search results were returned.

Default search results showing 1,051 results

Remember, by default you’ll get search results from the entire SharePoint farm. To change this so that only search results from your newly created result source are returned, here’s what you should do:

  1. On the search results page, click the Settings menu --> Edit Page.
  2. In the Search Results Web Part, click the Web Part Menu, and then 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 Web Part tool pane

  1. In the dialog box, from the Select a query menu, select your newly created result source.

    In my scenario, I selected the Articles (Site Collection) result source.

Select new result source

  1. Click OK in the dialog box, OK in the Web Part Tool pane, and then save the page. To verify that the configuration is working, enter a query.

    In my scenario, I entered search configuration.

Final search results with new result source

52 results were returned, which is the same number of items that was returned when I tested the query in the result source configuration. Cool, don’t you think?

Now that the Search Results Web Part displays the search results we are interested in, the next step is to make it easier for users to filter these search results. To do this, we'll use refiners, which is the subject of the next blog post. 

 

Next blog post in this series
Plan to use refiners on a search results page

Comments

  • Anonymous
    January 01, 2003
    Hi darsh, It’s a bit difficult to say exactly what is causing your issue, but does the query in your Search Results Web Part have something in it that returns search results? For example, does your query contain a phrase or word? Bella

  • Anonymous
    January 01, 2003
    Hi NP,

    Could you please explain a bit more what content you want to query for?

    Thanks,
    Bella

  • Anonymous
    January 01, 2003
    Hi Vlad,

    To retrieve items from a specific list, you can create a result source for that list, and then use the your newly created result source it when you configure the query in your Search Results Web Part.

    Bella

  • Anonymous
    January 01, 2003
    Hi, Just so that I can understand your scenario a bit better, are you getting this error message when you’re creating a new result source? If so, at which level are you creating the result source? In Central Admin, or on a site collection level? Bella

  • Anonymous
    January 01, 2003
    Hi Olav,

    I'm not sure I quite follow your scenario. You can add a Content Search Web Part to a category page, and then configure the query in that Web Part to show only items within the category. I explain how you can do this in another blog post:http://blogs.technet.com/b/tothesharepoint/archive/2013/04/30/stage-9-configure-the-query-in-a-content-search-web-part-on-a-category-page.aspx

    Does this answer your question? If not, good if you can give me some more details about what you want to accomplish.

    Thanks,
    Bella

  • Anonymous
    January 01, 2003
    Hi NP,

    Sorry, I don't have the details on how you can achieve this.

    Bella

  • Anonymous
    January 01, 2003
    Wonderful blog Bella! I have created a People Search with refiners for Company (we have multiple) and Department on the left. I'd like the initial search to use a default Company refiner value, but then the user must be able to change the Company refiner. Setting this in the Result Source would limit the result to only that company. Any ideas?

  • Anonymous
    January 01, 2003
    Hi NP,

    I have now verified that there isn't a token that translates to "now". You'll have to write custom code in order to implement this.

    Bella

  • Anonymous
    January 01, 2003
    Hi Olav,

    Regarding your first question about the word "extra". You can use a custom entity extraction and create a refiner for the word "extra". For more information on how to do this, see this article:http://technet.microsoft.com/en-us/library/jj219480(v=office.15).aspx

    Regarding your second questions, does your Managed Metadata column allow multiple values? If so, it won't show up in the drop down list on the Catalog Settings page.

    Hope this helps,
    Bella

  • Anonymous
    January 01, 2003
    Really thanks for the content.

  • Anonymous
    January 01, 2003
    Can you please elaborate more how to archive this by custom code at least general approach? thanks NP

  • Anonymous
    January 01, 2003
    Hi Varun,

    Check out the blog series How to display recommendations and popular items on a SharePoint Server 2013 site (http://blogs.technet.com/b/tothesharepoint/archive/2014/01/15/how-to-display-recommendations-and-popular-items-on-a-sharepoint-server-2013-site.aspx).

    Bella

  • Anonymous
    January 01, 2003
    Hi Alain,

    I believe you should be able to do this by creating a custom result source. For more information on how to do that, see this article:http://technet.microsoft.com/en-us/library/jj683115(v=office.15).aspx

    Bella

  • Anonymous
    January 01, 2003
    Hi Dave,

    I'm not quite sure I follow your scenario. What do you mean by "I'd like the initial search to use a default Company refiner value"?

    In the Search Result Web Part, there's a REFINERS tab. Have you tried to use that?

    Bella

  • Anonymous
    January 01, 2003
    Hi NP,

    Sorry for not updating, but I'm still looking into this.

    Bella

  • Anonymous
    January 01, 2003
    The comment has been removed

  • Anonymous
    January 01, 2003
    Hi Optimas,

    From what you describe, it seems like your Search Results Web Part (SRWP) uses a Query Rule or a custom Result Source. To see the query that your SRWP uses, go to your search results page, edit your SRWP, go to the TEST tab, and there Show more. In the last section, what does the Query text say? This is the query that's being sent by your SRWP.

    If it turns out that a Query Rule or a custom Result Source is kicking in, you could try to edit either the Query Rule or the Result Source with a conditional statement by adding {?}, for example {?{searchTerms} <YourQueryRuleOrResultSource> }

    Hope this helps,
    Bella

  • Anonymous
    January 01, 2003
    SOLUTION for those who had this problem:

    "The Search display templates are not present on this site collection. To add them, you need to activate the "Search Server Web Parts and Templates" feature on the Site Collection Features page. Correlation ID: 744e619c-a77a-205e-8df1-3232307431a4 Display Error: The display template had an error. You can correct it by fixing the template or by changing the display template used in either the Web Part properties or Result Types. Template '~sitecollection/_catalogs/masterpage/Display Templates/System/Control_QueryBuilderPreview.js' not found or has syntax errors. (LoadTemplate: )"

    Instructions

    - Open SharePoint 2013 Management Shell as Administrator.
    - Write the following script:

    " Enable-SPFeature SearchWebParts -url http://"

    http:// is the URL you have in your browser when you access the Central Administration of SharePoint.
    For example:

    " Enable-SPFeature SearchWebParts -url http://c4968397002:3695"

  • Anonymous
    January 01, 2003
    Hi Kate,

    It's difficult to say what could be causing your exact issue. I suggest you contact Microsoft Support with your question.

    Thanks,
    Bella

  • Anonymous
    January 01, 2003
    Hi Michael,

    I don't quite understand your question. Can you give me some more detail about what you want to accomplish?

    Thanks,
    Bella

  • Anonymous
    January 01, 2003
    Hi Steve,

    I'm not sure I completely understand your situation.
    Can you give me some more details about what you're trying to accomplish, and what issues you're encountering?

    Thanks,
    Bella

  • Anonymous
    January 01, 2003
    Hi vkmahesh,

    There are no such thing as silly questions :-)

    Yes, you should be able to show the publishing URL instead of the authoring URL. I've described how you can change how search results are displayed in another series:http://blogs.technet.com/b/tothesharepoint/archive/2013/09/03/how-to-change-the-way-search-results-are-displayed-in-sharepoint-server-2013.aspx.

    Unfortunately I don't know the name of managed property that your could use in your specific case.

    Bella

  • Anonymous
    January 01, 2003
    Hi Bella,

    I'm trying to restrict the search in a document library to just the current folder. I'm not sure what query expression to use from here:https://technet.microsoft.com/en-us/library/jj683123

    So for example instead of:
    {?path:{Site.URL}}
    what would be the correct SharePoint way to do it?

  • Anonymous
    January 01, 2003
    Hi Bella,

    Thanks for this awesome article. I have a question which may be silly... but I am doing something silly.
    Here is my scenario, I have authoring and Publishing sites where I am getting the contents from Authoring site using CSWP. Now I am trying to implement search Center where users what to search for the content from publishing site. When I perform the search I am getting the results using the query you mentioned {searchTerms?} (contentclass:STS_List_850) path:https://authoringsiteURL. But my question is whether I can show the publishing URL instead of authoring URL in the search result.

  • Anonymous
    January 01, 2003
    Hi Mahesh,

    Could you give me some more information about your scenario? Specifically, when you click on a search result, are you taken to the item in the authoring site, or are you redirected to the correct page on the publishing site?

    Bella

  • Anonymous
    January 01, 2003
    Hi Luca,

    I'm not sure I completely understand your scenario. From where do you want your users to search, and are you using the Search Results Web Part to display your results?

    Bella

  • Anonymous
    December 17, 2013
    No matter what i do with building the query, I get the following error, and the feature referenced is activated:The Search display templates are not present on this site collection. To add them, you need to activate the "Search Server Web Parts and Templates" feature on the Site Collection Features page.Correlation ID: 744e619c-a77a-205e-8df1-3232307431a4Display Error: The display template had an error. You can correct it by fixing the template or by changing the display template used in either the Web Part properties or Result Types.Template '~sitecollection/_catalogs/masterpage/Display Templates/System/Control_QueryBuilderPreview.js' not found or has syntax errors. (LoadTemplate: )

  • Anonymous
    February 03, 2014
    The comment has been removed

  • Anonymous
    February 04, 2014
    Search recommodation to user based on their past visit, setting for relevancy,activities etc Any help.

  • Anonymous
    May 15, 2014
    Pingback from SharePoint Search | Share your knowledge

  • Anonymous
    July 28, 2014
    Hi,
    How can I use Now() to compare date/Time field, instead of using {Today()} in my Search query?

  • Anonymous
    July 29, 2014
    Hi Bella,
    I want to display Item with PressDate less than or equal to current time in my search result webpart.

    {searchTerms} ContentType="ABC" PressDateTime<{Today+1}

    Above query not supporting for Now(), due to that it is showing items which are less than or equal to current (today's) date.
    How can I check time with current system Time?..Thanks

  • Anonymous
    July 29, 2014
    Hi,
    It is possible to configure search results web part to retrieve items from a single specific list?
    Thanks

  • Anonymous
    August 06, 2014
    Hi Bella,

    any luck on my query? or any suggestion?

  • Anonymous
    September 01, 2014
    The comment has been removed

  • Anonymous
    September 02, 2014
    Hi Bella,
    My apologies for not being clear. My category page has the CSWP and I have configured Control and Item Display Templates as well as refiners. It all works very well as you have explained. So, when I click on one of the page navigation links in the publishing site, I get the corresponding category page showing the appropriate items. If I want to refine the set of items, I can use a refiner, but this implies using a pre-configured property for refinement. Say there are many items on the page, and I know that the ones I want have the word "extra" somewhere in their "Description" column. How do I set up a refiner to do this? So I want a refiner, where I can type in the word "extra". I hope this makes more sense.
    Olav

  • Anonymous
    September 02, 2014
    Hi Bella,
    Another squeak from me! I have tried to follow the first few stages of your blogs, but defined my own site column of type Managed Metadata which I am hoping will play the role of "Item Category". However, it does not appear in the Navigation Hierarchy drop down list in the Catalog Settings page for the authoring library. Is there a something I need to configure so that my site column behaves like "Item Category"?
    Thanks once again,
    Olav

  • Anonymous
    September 03, 2014
    Thanks Bella - You're a star! Please publish lots more blogs!

  • Anonymous
    September 03, 2014
    Hi Bella,

    I have just discovered something in relation to the multiple values restriction: In order to have the Managed Metadata column appear under Navigation Hierarchy, it must be single valued, as you mentioned above. Once you have set up the catalog on the authoring side and then connected to it on the publishing side, you can change the definition of the Managed Metadata column to be multiple valued. The publishing then works exactly as you would expect with the item tagged with multiple terms appearing on multiple category pages. Perhaps most experts already know this, but I haven't read it anywhere, so thought it might be useful to add it here.

    Olav

  • Anonymous
    September 05, 2014
    Hi I'm having the same issue as darsh way up at the top of the comments. Once you add property filters to your basic query, when you navigate to the page, it is showing all results even if no search term is entered. Is there any way to have the search results show nothing until a user actually enters a search term?

  • Anonymous
    September 25, 2014
    Hello,

    I am looking for a way to search projects in our MS Project server 2013. I have seen that I can configure the search engine of the associated sharepoint (source, result, etc...)

    Is it possible? easy to configure? any template or add-on to use ?



    Thanks
    Alain

  • Anonymous
    November 10, 2014
    Hi Bella,
    Thanks for wriitng so informative blogs with minute details. For beginners like me its next to bible.
    Keep the great work up..!!! :)

  • Anonymous
    November 21, 2014
    Hi Bella,

    This article is so helpful, thanks very much!

    I'm having the same problem as Optimas and Darsh. All of the results appear as soon as I add my SRWP. Before I've even performed a search. For my users, I'd like the results list to be empty until they type a search term and click Search.

    Here's what I have:

    My Result Source is just a path to a document library on another site, and looks like this: {searchTerms?} path:http://

    When I go to the SRWP Test tab, as you mentioned above (go to your search results page, edit your SRWP, go to the TEST tab, and there Show more.), I see only this: path:http://

    I tried adding the query rule ({?{searchTerms} }) but that didn't seem to help.

    Do you have any ideas?

    Thank you for your help, and thanks for doing this post!

    Lisa

  • Anonymous
    November 26, 2014
    Thanks for the reply Bella. I am using the Refiners tab/webpart. But rather than return results from all companies before the user checks a refiner, I'd like the search results to default to a particular refiner value (Company A). I know I can limit the results via the result source, but then the results are limited to only that particular company value. I'd like for the results to be refined by default to Company A, but if the user wants to change to another company, they can select Company B in the refinement panel. Is there another way to achieve this that you know of?

  • Anonymous
    March 02, 2015
    Hi Bella,
    I think this is exactly what I'm after, but am having some trouble getting this to work on my site.
    The path my site is set up on it https:// rather than just the http:// Will this be why it won't work for me?
    I'm at the point of build your query, but the search results just return 0 if I remove the 's' or "Sorry something went wrong" if I enter the path
    {searchTerms?} (contentclass:STS_ListItem OR IsDocument:True) path:https://
    Thanks for any help.

  • Anonymous
    March 24, 2015
    I'm using this in a cross site publishing scenario. My results show up but when I click the link to display the item, I get a blank page. If I change my catalog connection to take me directly to the item it works (obviously this is a public site and that is not optimal) Any suggestions?

  • Anonymous
    April 07, 2015
    Hi Bella!
    Thanks for this article.
    It is possible to build a custom query for the "Find an Item" and "Find a file" searchbox?

  • Anonymous
    April 28, 2015
    Hi Bella,
    I am working on Cross Site publishing model and as per the model I have all the content in the Authoring site and would like to provide the search page in publishing site for getting the contents from authoring. I am getting those content but search result returns the Authoring site content which points to authoring site URL while returning the results. Is there any way that I can show the search result with Publishing URLs? Please guide how to achieve this?

  • Anonymous
    October 02, 2015
    Pingback from Plan to use refiners on a search results page in SharePoint 2013 | SharePoint Interests