Sharepoint’s ‘ordinary’ sites, such as Team Sites or Blank Sites, have a small search box (the SmallSearchInputBox) at the top which does not show search scopes, as we would be used to in a Collaboration Portal, for example…
The reason for this is that they are not, by default, pointed at a particular Search Center – so they don’t have any idea what scopes to show. However, you can set this through the Site collection Search Settings…
And suddenly, your search scopes appear! Hurrah!
Now, what if we are creating a bunch of site collections? (Our current project could create quite a lot of site collections. And we need them created automatically, as required). Can we point them to a specific search center automatically?
Well, it sounds like a job for a stapled Feature Receiver (that is, one run whenever a site is created – in our case, the root site for our site collection). Here’s my code, run in FeatureActivated…
SPSite site = properties.Feature.Parent as SPSite;
SPWeb rootweb = site.RootWeb;
SPFeatureProperty url = properties.Definition.Properties["SearchUrl"];
if (site == null)
{
throw new SPException("Feature must be activated at site scope");
}
rootweb.AllProperties["SRCH_ENH_FTR_URL"] = url.Value;
rootweb.Update();
As you can see, we get the SPSite for the collection, and then its root SPWeb. The Search Center URL is actually stored as a property on the root site of the site collection. Bit of a weird place to store it, but there you go.
EDIT: Actually, you can do this in the site definition through a site collection feature.
Thanks a ton man…!!!
I have been searching all over the internet for the “Search Center” property of the Site Collection and wasn’t finding anything. But you found it :-).
This is MOST DEFINITELY the weirdest place to store the setting.
I don’t know why but sometimes Microsoft folks behave ultra stupid while developing a product and we keep suffering all the time…lol