update: Fixed typo in ShowD_Contextual

update: Part 2 can be viewed here.

Scenario

You have implemented a wonderful search solution using MOSS and have built up all these wonderful scopes for use in all sites, now your users still want to use the “This Site” and “This List” contextual search scopes; problem is that the search result page for contextual search is the default “_layouts/ossearchresults.aspx” which looks completely different from your MOSS search centre pages.

Most solutions to address this problem that are available on the web will either instruct you to add a “redirect” javascript into the default “ossseachresults.aspx” page; not recommended by me as this is modifying a default MOSS file and could end up invalidating Microsoft support for your solution. Other solutions recommend creating a new search control class; this is a long and complicated process that I have yet to find an example of and the difficulty lies in ensuring new search scopes are included in your new search control when they are added.

Now I have done a TON of research into this problem and have come up with a workable solution for my client, my solution combines both methods; I provide two separate search controls through the master page, the one displays only contextual search and the other display only scopes and no contextual.

My solution is built by modifying the ContentLightUp search feature. Other related features are:

  • OsearchBasicFeature: The souped up version of the above, includes custom search scopes.
  • OsearchEnhancedFeature:  Even better, links to the advanced search and search centre.

Interesting Fact:
If you are using the enterprise version of MOSS with all features on your web application enabled, all the above features are activated. How MOSS decides which feature should be used is through a “Sequence Number” which is assigned to each feature:

  • ContentLightUp: Sequence = 100
  •  OsearchBasicFeature: Sequence = 75
  • OsearchEnhancedFeature: Sequence = 25

MOSS will always use the feature with the lowest sequence number first.

Solution

Process to create the Contextual Redirect Search

Setup the files:

  • Copy the osssearchresults.aspx and paste into the same folder as searchredirect.aspx
    (12\Template\Layouts)
  • Open the searchredirect.aspx page in your favourite editor and copy the sample code just after the </styles> tag:

<script language = "javascript">

function getURLParam(strParamName){

var strReturn = "";

var strHref = window.location.href;

if ( strHref.indexOf("?") > -1 ){

var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();

var aQueryString = strQueryString.split("&");

for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){

if (

aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){

var aParam = aQueryString[iParam].split("=");

strReturn = aParam[1];

break;

}

}

}

return unescape(strReturn);

}

var urlstring = '[YOUR SEARCH CENTRE URL]/Pages/results.aspx?k=' + getURLParam('k') + '&cs=' + getURLParam('cs') + '&u=' + getURLParam('u')

 

location.replace(urlstring);

</script>

  • In the code, rename “YOUR SEARCH CENTRE URL” to your relevant search centre.
  • Copy the searcharea.ascx user control and paste in the same directory as newsearcharea.ascx (12\Template\ControlTemplates)
  • Open the newsearcharea.ascx in your favourite editor and replace the code “/_Layouts/SearchResults.aspx with “/_Layouts/SearchRedirect.aspx
  • Copy the ContentLightUp (12\Template\Features\) folder as ContextualSearchRedirect (into 12\Template\Features\)
  • In the ContextualSearchRedirect folder: open the Feature.xml file in your favourite editor and change the following:
    • The Feature ID to a new one (you can use the VS GUID generator).
    • Rename the Title to “New Search Redirect”.
    • Change the Scope to Site (or “Web” if you only want it valid on a web site basis)
  • In the ContextualSearchRedirect folder: open the searcharea.xml file in your favourite editor and change the following:
    • The Sequence number from 25 to 23.
    • Change the ControlSrc to point to your _layouts\newSearchArea.ascx file.
    • Change the ControlID to ContextualRedirectBox.

Install the new feature:

  • Open command prompt and CD to the following location: cd \program files\common files\microsoft shared\web server extenstions\12\bin
  • Run the following command to install the new feature: stsadm –o installfeature –name ContextualSearchRedirect
  • Run the following command to activate it to a site collection: stsadm –o activatefeature –name ContextualSearchRedirect –url http://[your site collection url]

Update Master Page

  • Update your relevant master page to include this new search ControlID wherever you want =)
  • Process cancan be viewed here

 

Process to create the Scopes Only Search Control

Create the Feature:

  • Copy the OSearchEnhancedFeature folder as ScopeSearchOnly in the same directory (12\Templates\Features)
  • In the ScopeSearchOnly folder: open the feature.xml and change the following:
    • The Feature ID to a new one (you can use the VS GUID generator).
    • Rename the Title to “Scope Only Search”.
    • Change the Scope to Site (or “Web” if you only want it valid on a web site basis)
  • In the ScopeSearchOnly folder: open the searchArea.xml and change the following:
    • The Sequence number to 23
    • Add the following property tag:
      <Property Name="DropDownMode">ShowDD_NoContextual</Property>
    • Rename the ControlID to ScopeOnlyBox

Install the new feature:

  • Open command prompt and CD to the following location: cd \program files\common files\microsoft shared\web server extenstions\12\bin
  • Run the following command to install the new feature: stsadm –o installfeature –name ScopeSearchOnly
  • Run the following command to activate it to a site collection: stsadm –o activatefeature –name ScopeSearchOnly –url http://[your site collection url]

Update Master Page

  • Update your relevant master page to include this new search ControlID wherever you want =)
  • Process cancan be viewed here

Regards,

Doug 'bobTheBuilder' McCusker