Skip to content

Adding a Google Search Option in Your SharePoint 2010 Search Scopes Without Code

It turns out that integrating internet search providers into the drop down list in SharePoint – the search scopes dialog is relatively easy and doesn’t require any code. Here’s how you can do it.

Create the Scope

If you want to create a global scope you can go into Central Administration then Service Management for the Search Service and finally Scopes on the left, or you can create the scope at the site collection level by selecting the Search Scopes option from Site Settings as shown:

Once there, you need to create a new scope and set it up as follows:

Note that you’ll want to check the Search Dropdown checkbox to get it to show up in the search scopes drop down and that the page being referred to in the target results page must be created. Also, you’ll need to add a rule to the scope. Once you hit OK you’ll be back at the list of the scopes and there will be a link to add rules. You should add a rule for all content (because it’s simple) – The add rules page should look like this:

Help Your SharePoint User

Once you hit OK you’ve got a fully functioning scope that’s ready for use – just as soon as the system gets around to it. While we’re waiting, let’s go setup the page.

Creating the Redirect Page

In my case, I am using a simple search center for this demo (SRCHLITE) so I went in and copied the default.aspx page and removed the existing web parts. Then I added a content editor web part with some JavaScript to do a redirect to the Google search page. So here’s the bit that’s important. SharePoint automatically appends the search terms with a k= to the query string (k is for keyword). Google needs the query to be a q=, so we’ll have our JavaScript change the k= for a q=. The script looks like this:

<script language=”javascript”>
var queryString = window.location.search;
if (queryString.indexOf(‘k=’) != -1) {
var fullUrl = ‘http://www.google.com/search’ + queryString.replace(‘k=’, ‘q=’);
window.location.replace(fullUrl);
}
</script>

You’ll notice that in the script I check to see if there’s a k= in the querystring and only redirect if there is one – this is so we can manage the page without being redirected. I wrapped this script up into a Content Editor Web Part (which you can get here). I added this web part to my page and it was ready to redirect me to google.

Processing Scopes

If I was patient (and I’m not) I could have just waited for everything to be ready, however, I can also go back into Search management (through central administration) and if there’s a Scopes needing update shown there is also a Start update now link you can click to force search to compile the scopes for use as shown:

Once the search scope is compiled you can enable the scopes drop down list and use the link to Google.

Turning on Scopes for Most Pages

For the standard search box you can enable the scopes drop down list by going to Site Settings – Search Settings and changing the search dropdown mode to show scopes:

Once you hit OK, everywhere that there is a search box in the site collection should now have a scopes drop down list – that is except a search page, which has its own settings.

Turning on Scopes for a Search Page

For a search page you can turn on the scopes dropdown box by placing the page in edit mode then select Edit Web Part from the web part control menu (upper right). Expand the Scopes Dropdown section and select ‘ Show scopes dropwdown’. This will cause the scopes to show.

Testing

To test the setup just go into search, select the Google search scope and enter a search term.

1 Comment

  1. Worked like a charm. This is exactly what I needed. Thank you.


Leave a Reply to Tony Herrera Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share this: