Trouble with ossearchresult, droppdown box and scopes?
Have you tried to create custom scopes in a SSP ? Guess you expected them to show up in your newly created sites as well, right? Unfortunately, they don't. And you might even run into some more trouble along the way. But let's explore in an ordered fashion:
- Create a portal with a search center.
- Create a team sub-web.
- Create another team site collection (not a subweb).
- Enable "Standard sharepoint site collection features" -feature, on top level of both site collections.
- Create and compile one or more new scopes in your SSP.
The new scopes you now created are now available in both site collections. But how can you enable the dropdown search box to include them and be available in every new site, point to your search center and still have local search (This site) pointing to a local search page?
First of all you need to create a feature so you can change the search box to your liking. That's easy enough. (remember you just used a delegate! :)
If you activate the new feature on your portal, add your new scopes (site settings - search scopes - search dropdown - check boxes). Your scopes are propagated to all subsites as expected. But not to your team site collection.
Now try and set the search settings in the team site collection.
Point it to your search center. That will enable scopes and let you still search locally. You can also add the new scopes manually as you did on the search center. Works great! Let's move on to automating this.
The plan is:
- Create one feature with feature actication eventreciever:
- Set the connection to the search site
- Add scopes to the "search dropdown" list
- Staple the feature to the site defs.
This actually was a bit of pain. The search settings was not easily found. It turned out it was RootWeb.AllProperties with a strange name: SRCH_ENH_FTR_URL.
Here is the code:
public override void FeatureInstalled(SPFeatureReceiverProperties properties)
(...)
using (SPSite spSite = (SPSite)properties.Feature.Parent)
{
using (SPWeb spWeb = spSite.RootWeb)
{
// Set the link to the search center
spWeb.AllProperties["SRCH_ENH_FTR_URL"] = properties.Feature.Properties["SearchCenterUrl"].Value;
spWeb.Update();
}
}
(...)
//update the search scopes for the dropdown
ServerContext serverctx = ServerContext.GetContext(properties.Feature.Properties["SSPName"].Value);
SearchContext searchctx = SearchContext.GetContext(serverctx);Scopes scopes = new Scopes(searchctx);
Uri uri = new Uri(((SPSite)properties.Feature.Parent).Url);
ScopeDisplayGroup group = scopes.GetDisplayGroup(uri, "Search Dropdown");
group.Clear();
string[] eScopes = properties.Feature.Properties["Scopes"].Value.Split(';');
foreach (string arg in eScopes)
{
Scope newScope = scopes.GetSharedScope(arg);if(!group.Contains(newScope))
{
group.Add(newScope);
group.Update();
}
}
Be careful here. The scopes must exist otherwise the feature will fail - add error handling. Consider also what you would like to take place in the deactivation part.
Let me know if you run into anything else unexpected.
Tip: add a width element in the ossearchresults.aspx, if you want to left align or center the search box. For some reason the web control keeps overrunning all other values.
Ref:
https://msdn2.microsoft.com/en-us/library/bb428856.aspx
Comments
Anonymous
April 25, 2008
PingBack from http://microsoft-site2008yr.freehostia.com/?p=733Anonymous
May 23, 2008
I've created a GUI automation for deploying shared search scopes that you may want to check out... http://codeplex.com/SSPScopeDeploy This tool injects itself into every SSP's Search Section and allows you to deploy Search Centers, Deploy Shared Scopes, and Retract Shared Scopes from your site collections.Anonymous
May 23, 2008
PointedMan, your tool looks cool and I can see it put to good use in a lot of situations. But it is really not applicable when you have several houndreds or thousands site colletions. Maybe it would be a good idea to expand your tool to include something like "Install on all site collections on this web application"? Stian.