Friday, July 17, 2015

How to do a light weight search center using osssearchresults.aspx (part 1/3)

Most times these days the Team Site template is the starting point for any site template I create. At my current project we are creating a template for sites to be used by external users. For this particular SharePoint farm we don’t have a search center set up, as the search center is only available to internal users on the internal farm – a full-on center with custom branding etc.

At the moment we decided to go with using the default result page osssearchresults.aspx per site (site collection), to allow search within the site. Which is all out of the box.

But, we do want some customizations to the search page, which we cannot easily do as osssearchresults.aspx is a layouts page and you cannot edit the web parts. Which brings us to the meat of this post. How do you go about customizing the controls on the osssearchresults.aspx page when you can’t edit it?

Issue 1: Fixing the scope drop-down

image
By default the search boxes in your team site will have four choices, each pre-set to redirect to a particular search page.
  • Everything – {SearchCenterURL}/results.aspx
  • People – {SearchCenterURL}/peopleresults.aspx
  • Conversations – {SearchCenterURL}/conversationresults.aspx
  • This Site – ~site/_layouts/15/osssearchresults.aspx?u={contextUrl}
As you can see, the first three expects a search center, something we don’t have set up, which means we have to re-configure the scopes. We basically have two options, the first one is to configure the scope options to point to osssearchresults.aspx, and the second one is to remove/hide all scope drop-downs in the UI. We'll go with the a hybrid solution :)

Go to site settings for your site, and click Search Settings below the Search header.

image

Next uncheck Use the same results page settings as my parent, and add the scope options you want. If you want search within the site, only add the first one, if you want to search in all available content, then add the second one as well.
Unfortunately we cannot use token values for the URL itself via the UI, so it has to be the full path to osssearchresults.aspx for the site you are working on. If you do it programmatically you can skip the path part before _layouts/15/osssearchresults.aspx  and it will append the full path upon save for you – a bit more flexible for automation.

image

The u={contextUrl} part ensures you scope results to this particular site.

image

Once saved, the drop down of the top search box should be updated, as well as the osssearchresult.aspx page as seen in the image below.

image

Summary

By creating two custom scopes we now have a light-weight search center which gives users the ability to search within the site only or in all content the user have access to – without redirecting out to a full blown search center.

3 comments:

  1. you should really mark this post as applies to 2013 and not 2010/2007.

    ReplyDelete
    Replies
    1. Kind of obvious when you see the post date and references to the 15 hive in the file paths don't you think?

      Delete
  2. Worked for Sharepoint Online too. Thanks!

    ReplyDelete