Creating a Content Source and More for Searching MCMS with SharePoint - Building a Custom Search Implementation
(Page 4 of 4 )
As outlined previously, there are advantages and disadvantages to the MCMS Connector search controls. The most obvious is the fact that the SearchResultControl does not allow us to configure the results returned by the SPS search We will now build our own search implementation that will leverage the SPS search Web Service, offer advanced and specialized searching to our users, and present the results in a customizable manner.
About the SharePoint Portal Server Query Service
Everything we are about to build depends upon the Query Service Web Service, included in SPS, that exposes search functionality to remote clients, such as our website. This web service accepts a request in the Microsoft.Search.Query XML format and returns a response in the Microsoft.Search.Response XML format. In order to build a robust solution, the request we submit will use the Microsoft SQL Syntax for full-text Search. One method offered by the Query Service is QueryEx, which we will use as it returns results in the form of a DataSet.
For more information and documentation on the Microsoft SharePoint Portal Server Query Service Web Service, see the MSDN documentation at:
http://msdn.microsoft.com/library/ default.asp?url=/library/enus/
spptsdk/html/ cSPSQueryService_SV01004360.asp.
Building a Search Input Control
The first thing we'll do is build a search input control that will submit a search query to a page for processing. This implementation will allow us to add a small search component to all of our templates quickly. Upon submitting a search query, our user control will add the query parameters to the querystring and redirect the request to the results page.
Let's first start by creating a new user control.
- In Visual Studio .NET, right-click the User Controls folder in the Tropical Green project, and select Add | Add Web User Control.
- Name the new control SearchInput.ascx.
- While in Design view, drop controls from the Toolbox onto the Web Form and arrange them as shown below:
| Control | Properties |
| TextBox | ID = txtSearchInput |
| Button | ID = btnExecuteSearch Text = Go |
| LinkButton | ID = lnkAdvancedSearch Text = advanced search options |

- The LinkButton we created will take the user to the search results page, which we'll add some advanced searching features to later. Double-click our LinkButton. Visual Studio .NET will create an empty event handler for the Click() event. Add a single line of code to this empty event handler to redirect the user to the search results page:
private void lnkAdvancedSearch_Click(object sender, System.EventArgs e)
{
Response.Redirect(Request.ApplicationPath + "/SearchResults.aspx");
}
- Next, we need to create an event handler for when a user clicks our Go button. We'll take the keywords entered in the TextBox and send the search request to the search results page. Double-click the Go button and add the following code to the event handler:
private void btnExecuteSearch_Click(object sender, System.EventArgs e)
{
string keywords = this.txtSearchInput.Text;
keywords = HttpUtility.UrlEncode(keywords);
Response.Redirect(Request.ApplicationPath
+
"/SearchResults.aspx?keywords="
+ keywords);
}
Let's see if everything is OK with our new search input control. Save your changes and build the project. If you receive any error messages, retrace your steps and ensure that there are no typos.
Before this control can be used, we need to add it to an existing template. While we'd ideally want to provide the search on all pages on our site (typically by adding it to a global heading control), we'll just add it to the homepage for now.
- Open the \Templates\HomePage.aspx template and drag our new SearchInput.ascx into the top cell, to the right of the logo.
- Switch to HTML view and find the control we just added. It will likely have an opening tag of uc1:SearchInput. Wrap this control in an HTML DIV and set its alignment to right as shown in the following code:
<td width="100%" colspan="2" valign="top" bgcolor="#ffcc00">
<img src="/tropicalgreen/images/Logo.gif">
<div align="right">
<uc1:SearchInput id="SearchInput1" runat="server"></UC1:SearchInput>
</div>
</td>
The HomePage.aspx template should now look similar to the following:

Please check back next week for the conclusion of this article.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
|
This article is excerpted from chapter five of the book Advanced Microsoft Content Management Server Development, written by Lim Mei Ying et al. (PACKT, 2005; ISBN: 1904811531). Check it out today at your favorite bookstore. Buy this book now.
|
|