Home > Microsoft SharePoint, SharePoint 2013 Search, SharePoint2013 > SharePoint 2013 Remove ‘Nothing here matches your search’ from search results web part

SharePoint 2013 Remove ‘Nothing here matches your search’ from search results web part

Hi Friends,

SharePoint 2013 search have huge potential, with the integration of FAST and SharePoint search it becomes very powerful search solution. There are couple of new search web parts added like Content Search web part which is excellent search web part. New search result rendering mechanism called display templates is provided which are similar like JSON to HTML templates.

We will discuss a scenario about Search result web part and the solution related to the problem using display templates.

Scenario: If we add a search result web part on page and above that a search box web part to enter search term and according to that search term we want search result web part will display results. When we add both these web parts on page and before entering the search term also the results web part show  “Nothing here matches your search” (as shown in below image), which we don’t want to display unless we enter something in search box.

Search_Result_SP_2013

Obviously we may think that there will be some web part property available which will help us to resolve this issue, but web part do not have any property like this. Here come display templates in our help, we will see how we can use display templates to achieve this.

Search Results web part of SP 2013 uses ‘Control_SearchResults.html’ display template which is available under Master Page Library –> Display Templates –> Search.

Solution:

  1. Rename the ‘Control_SearchResults.html’ file to some other name e.g. ‘Control_Test_SearchResults.html’
  2. Open this file in any text editor like notepad.
  3. Change the Title in this HTML file(I have used Test Default Result for demo), this title will be available for selection in web part properties.
  4. Now we want to get the search text entered in to search box web part, for that we will use ctx object as following ctx.DataProvider.get_currentQueryState().k
  5. Search     if(ctx.ClientControl.get_shouldShowNoResultMessage()){    line in HTML file (as shown in below image).
    Search_Result_SP_2013_Display_Template_1
  6. Replace this line with
    var currentQueryTerm = ctx.DataProvider.get_currentQueryState().k; if(ctx.ClientControl.get_shouldShowNoResultMessage() && currentQueryTerm!=””){
    (As shown in below image)
    Search_Result_SP_2013_Display_Template_2
  7. Save the modified HTML file.
  8. Go to Master Page Library –> Display Templates –> Search and upload new control template.
  9. You will see that respective ‘Control_Test_SearchResults.js’ will be created by SharePoint.
  10. Now go to your page where Search Result web part is added, edit Search results web part. Under Display Templates section select newly uploaded display template.( as shown in below image).
    Search_Result_SP_2013_Display_Template_3
  11. Save the changes and that’s it, you will see the  expected result.
Advertisements
  1. July 23, 2013 at 9:11 pm

    Great Article!

    I’m using SharePoint 2013 online (plan 1). I don’t see the ’Control_SearchResults.html’ file anywhere, just the .js file. Is this something that cannot be done with SharePoint Online as offered by Microsoft?

  2. July 29, 2013 at 6:05 am

    Hi Brian,

    Sorry for delayed reply, the reported behavior observed by you is because ‘publishing infrastructure feature’ may not be activated for that site.
    Please check after activating publishing infrastructure feature.

    Regards,
    Prasad Pathak

  3. Brant Williams
    July 29, 2013 at 8:35 pm

    Thank you for the article. I have followed your instructions. When I choose the new Display Template in the properties of the Search Results webpart, I immediatlely get the error “~path/Control_Test_SearchResults.js’ not found or has syntax errors. (LoadTemplate)” I do see the file on the server, so I’m assuming there is an error with the .js file. Do I need to edit the .js file? Thanks for the help.

  4. July 31, 2013 at 5:38 am

    Hi Brant,

    We can check couple of things-

    1. Check the js file Control_Test_SearchResults.js available under ~sitecollection/master page gallery/display templates/ by accessing .js file in browser.
    2. If the file is available and still you are getting same error you can attach the javascript debugger in IE developer tool and check where exactly the error coming from.
    3. If still you have an issue please share the control template with me using some file sharing web site, I will check.

    Regards,
    Prasad Pathak

  5. January 24, 2014 at 8:45 pm

    There seems to be a syntax error if you copy the code directly from this page. The last two quotes turn into some characters like “� when they are pasted and uploaded to SharePoint. So before you paste it in your page, just type in the two quotes manually.

    ..currentQueryTerm!=””){

    This solution worked great for us btw. Thanks, Prasad!

    • January 25, 2014 at 9:16 am

      Thanks Mike, looking like HTML encoding issue.
      Please make a note of Mike’s suggestion.

      Best Regards,
      Prasad Pathak

  6. Pablo
    April 21, 2015 at 8:35 pm

    Hello, thank you for sharing this solution. I have successfully installed the new display template and the ‘Nothing here matches your search’ is no longer appearing on the Search Results web part. However, I have noticed that when ‘Show ranked results’ is disabled, nothing I search for is found. I have the query looking up items by content type (post) on the current site. When I turn the ‘show ranked results’ back on, I am able to successfully pull up any of the items I was looking for. However, if the ‘show ranked results’ is on, then any user coming to the site sees all of the items as soon as the page loads

  7. August 1, 2016 at 5:56 am

    Prasad, thank you! This information was very useful. To me, this is what the default search results behaviour should be.

  1. May 27, 2015 at 3:11 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: