MOSS MVP

I've moved my blog to http://blog.falchionconsulting.com!. Please update your links. This blog is no longer in use--you can find all posts and comments at my new blog; I will no longer be posting to this site and comments have been disabled.

Monday, October 15, 2007

Set Search Center

This was a pretty simple command to create and only took me a few minutes. Basically I needed to be able to set the search center for a site collection. You can do this via the browser by going to http://[portal]/[site collection]/_layouts/enhancedSearch.aspx.  The command I created is called gl-setsearchcenter.

The code for this is beyond simple - it was just a matter of setting a string based property via the AllProperties collection:

   1: string url = Params["url"].Value;
   2:  
   3: using (SPSite site = new SPSite(url))
   4: using (SPWeb web = site.RootWeb)
   5: {
   6:  string searchCenter = null;
   7:  if (Params["searchcenter"].UserTypedIn)
   8:  {
   9:   searchCenter = Params["searchcenter"].Value;
  10:   if (searchCenter != null && searchCenter.Trim() == "")
  11:    searchCenter = null;
  12:  }
  13:  
  14:  web.AllProperties["SRCH_ENH_FTR_URL"] = searchCenter;
  15:  web.Update();
  16: }

The syntax of the command can be seen below:

C:\>stsadm -help gl-setsearchcenter

stsadm -o gl-setsearchcenter

Sets the search center for a given site collection (settings can also be set via: "{site collection}/_layouts/enhancedSearch.aspx").

Parameters:
        -url <site collection url>
        -searchcenter <search center url (leave empty or ommit to use {site collection}/_layouts/osssearchresults.aspx)>

Here's an example of how to set the search center for a site collection:

stsadm –o gl-setsearchcenter -url "http://intranet/hr" -searchcenter "/SearchCenter/Pages"

You can also clear the setting by leaving the -searchcenter parameter empty or by simply not providing it.

4 comments:

Usman said...

i want to set Search Center according to site Variation or language of a site Collection, like if my current language is English then i should go to search center in english site, if my language is german then i should go to search center in german site.

Gary Lapointe said...

Unfortunately this is a web based property and not a user based property. You might try providing the url to a redirect page which you can then use to put your own custom login within.

Anonymous said...

I have a branding question about the search center. The client want the search center pages to reflect the site theme. The theme is not only a color change but the navigation tabs are different as well. The current search center applies to all sites and sub sites. I need a second search center for some sites and the standard search center for the rest.

Question one Will the command apply a custom search center to only specific sites.

Question two What is a good resource on how to create the new search center.

Gary Lapointe said...

The search center property is at the web level so you can set it individually for each web. The search center itself is just a standard template so creating one is simple - you'll need to search around for branding info.