Second Life of a Hungarian SharePoint Geek

May 4, 2011

Setting the target search result page URL of the Search Box web part

Filed under: Search, SP 2010 — Tags: , — Peter Holpar @ 22:10

Setting a custom target search result page usually means nothing extra. One should usually set only the Target search result page URL (the corresponding web part property in Microsoft.SharePoint.Portal.WebControls.SearchBoxEx is called SearchResultPageURL). It is important however, that the Use site level defaults checkbox (UseSiteDefaults) value must be cleared, otherwise site collection level settings take place instead of our custom value.

image

The scope dropdown mode has a similar configuration value pair, see Dropdown mode (DropDownModeEx) below, and Use site dropdown mode (UseSiteDropDownMode) above.

Both UseSiteDefaults and UseSiteDropDownMode have a default value of false.

image

The next figure illustrates global search settings (Site Collection Administration / Search settings), as defined at the site collection level. Notice the site level defaults and dropdown mode.

image

As the page above says, “By checking the "Use site level defaults" web part property, the search box will send custom scope queries to the Search Center defined in this "Site Collection Search Center" property.” and “By default, a Search Box will use the "Dropdown Mode" property in the web part.  By checking the "Use site dropdown mode" property, the search box will use this "Site Collection Search Dropdown Mode" setting instead.”

Recently I had to create a customized version of the OSSSearchResults.aspx that send custom scope queries to itself instead of the Search Center. After adding the correct SearchResultPageURL property value to the MSSWC:SearchBoxEx control, there was no change in the default behavior. Fortunately, I realized found the following property setting on the same control:

UseSiteDefaults = "true"

Removing this setting applied the default "false" value that ensured my custom target URL page settings.

You can read more about these web part settings here:

Change properties for the Search Box Web Part

For the more technologically minded it might be interesting that the SearchBoxEx stores and merges these settings in the private field _PropertiesOverrideableBySite of type private nested class PropertiesOverrideableBySite. See its EffectiveSearchResultPageUrl (String) and EffectiveDropDownMode (DropDownModesEx) property getters for implementation details, as well as the non-standard property setters like in the case of the SearchResultPageUrl property. This latter one is the property we set when assigning value to the SearchResultPageURL property of the SearchBoxEx class.

Effective property values are used on web part rendering (see OnPreRender method) and when getting the scope for contextual search (see GetSpWeb method called by HandleContextualScoping method).

Advertisements

1 Comment »

  1. Hello,

    This is a great post.

    I need to use this to allow users to use a “search box” to search the document library that they are in. I added a “search box Web part” but I’m having difficulty knowing what to put in the “Target Search Results Page URL” to only allow the search to be performed within the document library.

    Comment by Philip Todd — November 22, 2011 @ 15:13


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: