Creating a Content Source and More for Searching MCMS with SharePoint
Last week, we began preparing our MCMS-using website for content indexing so that it could be searched with SharePoint. This week, we continue the work; among other topics, we discuss building our own search controls. 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).
Another option is to manually create the content source in SharePoint rather than allowing the SearchSetup.exe utility to create it for us. We'll walk you though these steps so you will have an understanding of what's involved in creating a content source and source group in a SharePoint portal.
Although we're explaining how to create a content source both with the SearchSetup.exe utility and manually using the same content source names, you must choose only one method as it is not possible to create two content sources with the same name.
Let's start by creating an index of our Tropical Green website in our SharePoint portal:
Refer to Appendix A for a walkthrough of the steps in creating a portal.
Start the SharePoint Central Administration by pointing to Start | All Programs | SharePoint Portal Server | SharePoint Central Administration.
Click List and manage portal site under the Portal Site and Virtual Server Configuration section.
The Manage Portal Sites page contains a list of all portals in the SharePoint farm. Drag your mouse cursor over the right-hand side of the list and click the drop-down arrow that appears when the mouse cursor is over a portal and select Manage Portal Site Properties (as seen in the image below):
Under the section Search Settings and Indexed Content, click the Configure search and indexing link.
The following instructions assume you have not enabled SharePoint's advanced search administration mode. The main difference between basic and advanced mode is advanced mode allows you to work directly with content indexes. Basic mode creates content indexes when you create a content source. In our example, basic mode is adequate for our needs.
Now we will create the content source.
Under the General Content Settings and Indexing Status section, click the link Add content source.
On the Add Content Source page, select Web page or Web site and click Next.
After selecting that you want to create an external website index, enter the following information on the Add Content Source: Web page or Web site page. Once you have filled out the form, click Finish.
Field
Value
Address:
http://www.tropicalgreen.net/TropicalGreen/
Description:
Tropical Green web site
Crawl Configuration
This site follow links to all pages on this site
Participate in adaptive updates
Checked
If you intend to use the manually-created content source with the MCMS Connector controls, you need to name the content source "CMSChannels" as this name is hard-coded in the connector controls.
In this example, the virtual server acting as an MCMS Web Entry Point for our Tropical Green website handles requests for http://www.tropicalgreen.net/. The example will still work if you have set up the Tropical Green website on http://localhost/; you'll just need to make the appropriate changes in the steps to point to the correct domain.
Once you click Finish in the previous step, SharePoint will create the content source and present you with a confirmation page. At the bottom of the Created Web page or Web site Content Source, in the Start Update section, check the Start full update option and click OK. This will trigger the gatherer to start building an index of the Tropical Green website.
Once you have created a content source manually, follow the instructions under the section Creating a New Search Scope above to create a new source group using the settings in the following table:
Field
Value
Name:
TropicalGreen.net
Topics and Areas:
Include no topic or area in this scope
Content Source Groups:
Limit the scope to the following groups of content sources:
SharePoint portals typically do not allow anonymous users to access the site, and users must log in. The SearchResultControl included with the MCMS Connector, which we'll use in a moment, uses the account of the application pool identity that contains the MCMS site from which a search query is triggered to access the SharePoint search service.
Browse to the portal we created earlier by opening Internet Explorer and navigating to http://portal.tropicalgreen.net. Then, click Site Settings in the upper right corner.
Under the General Settings section, select Manage security and additional settings.
On the Manage Site Groups page, click Add a Site Group. When prompted to enter information about the new group, enter the following values:
Property
Value
Site group name
Search Only
Description
This site group grants a user the right to query the search index
Rights
Search Search the portal site and all related content
When you select Search Search the portal site and all related content, SharePoint automatically checks the View Pages View pages in an area option. Uncheck the View Pages option after you check the Search option.
On the Manage Site Groups page, click Search Only, the name of our new group.
On the Members of "Search Only" page, click Add Members. Add the account that's configured as the identity of the application pool your MCMS site runs under. Once you've selected the account, click OK.
To find the identity of the application pool your MCMS site runs under, open Internet Information Services. Expand the nodes for local computer | Application Pools. Look for the application pool that your MCMS site is configured to use and view its properties. The identity is listed under the Identity tab.
After selecting the account, on the Add User page, ensure that Search Only under the Step 2: Choose Site Groups section is checked and click OK.
On the last page, where SharePoint asks you to confirm the details of the account you're adding, make sure the Send the following e-mail to let these users know they have been added option is unchecked, and click Finish.
Our MCMS site now has the permissions needed to log in to our portal and execute a search.
Adding a Search Page to the MCMS Site
We have two options available to implement a search capability for our Tropical Green site:
Leverage the ASP.NET Server Controls included in the MCMS Connector for SharePoint Technologies that allow search queries to be executed.
Create our own solution.
The MCMS Connector includes the following three controls that assist you in implementing search functionality for an MCMS site by leveraging SharePoint search scopes:
SearchInputControl: Used to create the search form input for a search to be submitted.
SearchResultControl: Takes search criteria entered in the SearchInputControl, executes the search against the SPS search Web Service, and displays the results in list form.
SearchMetaTagGenerator: Creates HTML META tags based on the PropertyType setting. META tags generated can include standard page properties as well as custom properties.
You can use these three controls on the same page or separate pages. This is very convenient as you may wish to include a small search keyword input box on all pages in your site that submits the search to a separate results page, but you might want to provide the search input on the search results page as well.
Once we have created a working search page using the MCMS Connector controls, we'll create a custom solution that won't include anything provided in the MCMS Connector. Our solution will include an advanced search, specific to our site, and a customized search result listing.
Both options have distinct advantages and disadvantages. Which one you'll implement on your MCMS site will depend entirely upon your requirements, customization needs, and available development time. The following table outlines a few of the more prominent advantages and disadvantages of using the MCMS Connector controls as well as rolling your own solution:
The first thing we'll do for this is to create a new search page in our Tropical Green project. This page will not be a new MCMS template, but a regular ASP.NET page. You could make this a template, but there's no real advantage in doing so because there will only be a single search page on our site with no extra content.
In Visual Studio .NET, right-click on the Tropical Green project and select Add Web Form.
Name the new ASPX page Search.aspx and click Open.
If the page doesn't load in Design mode, click Design in the lower left corner.
Change the page layout to FlowLayout.
Drag the /Styles/styles.css, /UserControls/TopMenu.ascx, and /UserControls/RightMenu.ascx files from Solution Explorer onto the designer.
Switch to HTML mode and modify the body tag as follows:
Why did we drag the user controls onto the page and then replace the resulting HTML?
Dragging the user controls onto the page adds the <%@ Register %> lines to the ASPX for us as well as adding the user control ASP.NET tags to the HTML. We then only need to modify the HTML to make it more presentable.
You should now have a page that looks like the following when viewed in Design mode:
Let's save our new search page, build the Tropical Green project, and navigate to it in a browser to make sure everything is in order before we go about adding the search input and results controls.
Save all changes to the search.aspx page.
Right-click the TropicalGreen project and select Build.
If there are no errors in the build, open a browser and navigate to: http://www.tropicalgreen.net/ TropicalGreen/Search.aspx.
If there are any issues, retrace the steps we've taken to this point, address the errors, and retry the URL.
Now that we have a working search page, we need to add some functionality to it. We'll add the two MCMS Connector server controls, make some configuration changes, build the solution, and test our search page.
Open the search.aspx page in Visual Studio .NET if it's not already open, and switch to Design view.
Open the Visual Studio .NET Toolbox and drag the SearchInputControl and SearchResultsControl into the table cell below the Tropical Green Search cell. Refer to the following image for placement:
Select the SearchInputControl we added to search.aspx and set the following properties in the Visual Studio .NET property window:
Property
Value
SearchMode
Simple
SearchResultPage
/TropicalGreen/Search.aspx
Select the SearchResultControl we added to the search.aspx page and set the following properties using the Visual Studio .NET property window:
Property
Value
PortalUrl
http://portal.tropicalgreen.net/
SearchResultPageSize
10
We're using the URL of the portal created in Appendix A. Replace this URL with whatever portal you configured for the content source and search group in the steps already covered in this chapter.
Let's see if our search is working. Save all changes to search.aspx, build the Tropical Green project, and go to http://www.tropicalgreen.net/TropicalGreen/ Search.aspx in a browser. You should see a page similar to the one below:
Enter a word you know will be found on the site, such as ficus. You will see the same list of search results that were returned when searching for the same string in the portal containing the content index.
If you receive an error message stating "There was a problem loading the input control. The error returned by the system is: Could not find part of the path c:\inetpub\wwwroot\ tropicalgreen\cms\wssintegration\ searchpropertycollection.xml", double-check that you added the CMS virtual directory in your TropicalGreen web application.
At this point, we have got search capabilities on our site thanks to the MCMS Connector controls and SPS's search features. But this solution is very limited, for instance there is no way to change the look and feel of these controls and there is also no way to configure which properties are displayed in the result page, for instance to show a short description for the returned documents.
To address this, we will now build our own search controls.
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.