Tuesday, September 29, 2009

Custom Search Control inheriting from OOTB SearchBoxex

Creating a Custom Search webpart that inherits from SearchBoxEx is a simple task. Also we can set a scope where we can perform search using the property 'AppQueryTerms'. Following code snippet shows how do we create the webpart.


this.AppQueryTerms = string.Empty;
this.AppendToQuery = false;
this.DropDownMode = DropDownModes.HideScopeDD;
string searchScope = specify your custom scope//
this.AppQueryTerms = "Country:Global Scope:" + searchScope; //I am querying on basis of scope and managed property country
string searchPageUrl = searchCenterSiteName + "/" + pageListName + "/" + RESULTSPAGE;
string advancedSearchpageUrl = searchCenterSiteName + "/" + pageListName + "/" + ADVANCESEARCH;
this.ShowAdvancedSearch = true;
this.SearchResultPageURL = Path.Combine(SPContext.Current.Web.ParentWeb.Url, searchPageUrl).Replace('\\', '/');//setting the url of the Search page url
this.AdvancedSearchPageURL = Path.Combine(SPContext.Current.Web.ParentWeb.Url, advancedSearchpageUrl).Replace('\\', '/');//setting the url of the advanced Search page url


Following link conatins some details about the Search settings.
http://blogs.msdn.com/markarend/archive/2007/01/24/search-results-page-may-be-different-per-search-scope.aspx.