October 04, 2007 12:10 AM

The Search Is On: Part I

Introducing Collaborative Microsoft Office SharePoint Server Search Techniques
DevConnections
Rating: (0)

CoverStory

LANGUAGES: C#

ASP.NET VERSIONS: 2.0

 

The Search Is On: Part I

Introducing Collaborative Microsoft Office SharePointServer Search Techniques

 

 

Imagine this scenario: A new employee to a company sitsdown at the company?s SharePoint Server intranet portal and is told to figureit out. Right there on the portal home page is an inviting little Web part thatsays, ?I?d like to find out more about:? with a dropdown list full ofinformation about such topics as 401(k), employee stock purchase plans, thelatest technical buzzwords, and the company performance reports. By clickingthrough to these destinations, the employee learns a significant amount aboutthe company ? all without having to ask any questions. Six months later, thesame employee is still frequently using this same Web part because the contentsof the dropdown list change often, and always reflect the things that his co-workersare talking about ? all without any administrators keeping the content fresh.

 

How is this happening? The contents of this simpledropdown list are really driven by the search terms entered into the SharePointportal?s search center. As the frequency of the search terms change, thedifferent list items bubble up and down in the dropdown list. (This functionalitycan be seen in action on some prominent Microsoft SharePoint intranets.)

 

This two-part series will walk you through the process ofcreating a SharePoint Web part with such a dropdown list, beginning with theout-of-the-box configurations required to ensure that search is successfulinside your Microsoft Office SharePoint Server portals, through the discoveryof where the search result and click-through data is kept, and, finally, thecreation of the Web part itself in Part II.

 

Configuring SharePoint Search

Because you are interested in providing your users withthe best possible results whenever they use the SharePoint search technologies,you need to configure SharePoint Search, along with some best bets for certainkeywords or search terms. At the most basic level, SharePoint Search iscomprised of a crawler service that builds an index of terms that can besearched for maximum performance. The crawler service reads from identifiedcontent sources and tags the discovered material as belonging to one or moresearch scopes, or categories. Examples include searching file shares forMicrosoft Word documents or searching SharePoint sites for Excel spreadsheets. Thefollowing walkthrough will show you what is required to correctly configureSharePoint Search and create a search scope for targeted results.

 

Start by visiting your site?s Central Administration site.SharePoint?s Central Administration is the single central location where youcan administer your farm?s Web applications, site collections, backups,security, policies, and more. On the Operations tab of Central Administration,you can check the status of the server?s Search service.

 

Central Administration also surfaces a middle level ofconfiguration known as Shared Services. The Shared Services Provider is thehost for application services on a portal such as Search and MySites, and, assuch, is the destination for search configuration. Follow these instructions toturn on Search in your MOSS portal:

  • Click Start, point to All Programs, point toAdministrative Tools, then click SharePoint Central Administration.
  • Use the quick launch navigation on the CentralAdministration page to click Shared Services Administration, then click thedefault Shared Services Provider.

 

Under Search on the Shared Services Provider home page,click Search Settings (see Figure 1). If you need to create additional contentsources, such as external WSS team sites or network file shares, click theContent sources and crawl schedules link. By default, the Search service isalready configured with the Local Office SharePoint Server sites. Clicking thecontent source link will allow you to modify a variety of settings, such as theURL or file path of the content to crawl, the schedule for full and incrementalcrawls, and more. Figure 2 shows the settings available for the content source ofthe default Local Office SharePoint Server sites. This default content sourceis more than sufficient to demonstrate the concepts of this article, so adding additionalcontent sources is not necessary at this time.

 


Figure 1: Configure search settings.

 


Figure 2: Edit content source.

 

Among the other options available on the Search Settingspage are the Scopes settings. A search scope is a way to classify data acrosscontent sources and return narrower sets of results to search users. Examplesof search scopes might be Word documents or images. To create a new searchscope, click the View scopes link from the Configure Search Settings page, thenclick the New scope button.

 

The next step is to identify a search scope that searchesonly for Word documents to assist users in finding the content they want. Titleyour new scope ?Documents? and click OK. You?ll be brought back to the ViewScopes page, where your new scope has been defined but is currently empty andawaiting the addition of some content rules. Click Add rules next to currentlyEmpty status of your new Search scope.

 

You?ll be presented with a screen where you are givenseveral options to define your search scope?s rules. Your Search scope is ableto restrict search results by URL, by content source, or by matchingproperties. It is this property query option that allows you to restrict thesearch scope to certain file types. By default, there is a property namedFileExtension that can be used to restrict searches to specified file types. However,by default, this property is not available for search scopes and must beenabled. Without making any changes to your scope?s rules, return to the ConfigureSearch Settings page and click the Metadata property mappings link, which willtake you to the page shown in Figure 3.

 


Figure 3: Metadata property mappings.

 

Click the FileExtension managed property and check the boxat the bottom of the page to make the property available for search scopes. Withthe FileExtension property now available for use in scopes, return to the rulesfor your search scope by clicking Search settings in the breadcrumb navigationat the top of the page, then click View scopes, then click the Add rules link. Selectthe Property Query rule and select the FileExtension property as the propertyrestriction. Type ?doc? into the ?=? box and leave the behavior set to Include.Your screen will look like Figure 4. Click OK to exit.

 


Figure 4: Add scope rules.

 

Add a second FileExtension restriction rule to this scopeto include docx extensions (so Word 2007 documents are also returned). Click onthe Documents scope and select New rule in the Rules section of the page. Onceyou?re finished, your Scope Properties for search are set up on your Rulespage.

 

The server is now configured for search, but the crawlerservice must be started and the scopes updated before your users can actuallysee any search results. Follow these steps to run the full crawl and update thesearch scopes:

1)     InCentral Administration, click the Shared Services link on the Quick Launch menuto return to the top of the site.

2)     ClickSearch settings, then click the Content sources and crawl schedules link.

3)     ClickLocal Office SharePoint Server sites, check the box at the bottom of the screento run a full crawl, and click OK to confirm this action.

4)     Repeatstep 2 on all other content sources to ensure that search scopes that spanacross content sources are fully updated.

5)     Returnto the Search settings page. Once the crawler is idle, update the scopes byclicking Start update now (in the Scopes section).

 

Now search has been fully configured at the SharedServices level, including defining the search scopes that help your users findexactly what they are seeking. Next it?s time to configure the site to use thesearch scope you just created. Log in to the top-level site of your sitecollection as an administrator; click the Site Actions menu and select SiteSettings. From the Site Collection Administration menu, select the Searchscopes link. Notice that your new scope is at the bottom of the page, in theunused scopes section. To activate the new search scope in the Search Dropdownand Advanced Search groups, click the names of each group to get to the EditScope Display Group page, where you can activate the new scope by checking thebox next to its name, as shown in Figure 5.

 


Figure 5: The Edit Scope DisplayGroup page.

 

Now your site is ready to be searched. Basic searchcapabilities are automatically built in to every page, but to grant your usersa truly advanced search experience, create a site using the Search Center with Tabs template. Clickthe Site Actions menu and select the Create option. In the Web Pages group,select the Sites and workspaces option. Give your new search center a title,description, and URL. The Search Centerwith Tabs template is located in the Enterprisegroup. Select the template and click the Create button at the bottom of thepage. Your new site will be created and you?ll automatically be taken to thetabbed search center. The first thing to observe is that the search scopes seenin the Shared Services admin pages are represented as individual tabs, allowingusers to easily restrict search results to the subcategories defined by thescopes.

 

Keywords and Best Bets

Search has been configured, but how, as an administratoror content owner, do you direct people to a specific document or page as thebest possible resource for specific information. For example, when an employeesearches on the phrase ?company benefits?, you might want to provide thecompany?s HR benefits guide as the first place they should go. This is referredto as a best bet; the following walkthrough will guide you through configuringa keyword and the associated best bet.

 

Log in to the top-level site of your site collection as anadministrator; click the Site Actions menu and select Site Settings. In theSite Collection Administration menu, select the Search keywords option. Clickthe Add Keyword button. Fill in the form with the word or phrase for which youexpect your users to search. Be sure to add any pertinent synonyms. Notice thatyou can assign an expiration date for this keyword. Click the Add Best Bet linkto enter the URL of the best bet, as well as a short description. Your pageshould now look like the sample screenshot shown in Figure 6. Notice that youcan have multiple best bets for a keyword. Return to the site and search foryour keyword. The results page will have a new section on the right side withthe best-bets results.

 


Figure 6: Adding a keyword.

 

Search is now up and running with some administrator-specifiedbest bets. Employees are using the portal to store and work with their content.Insightful navigation options direct users through the portal, and search isfilling in the gaps, helping users quickly find relevant information. As anadministrator or content owner looking to improve the portal navigation andsurface the most requested documents, you are interested in the top-searchedterms and the results of those searches. Fortunately, SharePoint has Searchreporting built in. To discover what users have been requesting, the followingwalkthrough will guide you to the various reports at the Shared Services level.

 

Open Central Administration and click the default SharedServices provider. Click the Search usage reports link; notice that the searchreports that come up have no data ? you must enable usage reporting on theserver before the search usage reports work.

 

To enable usage reporting, go back to CentralAdministration; from the Operations tab click Usage Analysis Processing. Enableboth logging and usage analysis processing. Be sure to set your processingwindow to a time close at hand, as the search usage reports will empty untilthe usage analysis processing has been run.

 

When the usage analysis processing has been given ampletime to run for the first time, return to the Shared Services search usagereports; there is now data available (see Figure 7).

 


Figure 7: Usage reports.

 

Behind the User Interface

At this point, we begin to enter the territory outlined inthe scenario presented in the first paragraph. The goal is to build a Web part thatuses the search results data that SharePoint is displaying in the reports tobuild a custom Web part that can act as a navigation aid. The first step alongthat path is to figure out how SharePoint itself is able to report on searchdata. This voyage of discovery will require the use of Lutz Roeder?s Reflector for.NET (http://www.aisto.com/roeder/DotNet/),SQL Server Management Studio, and a tool to view code, such as Visual Studio orNotepad.

 

To find which Web parts, namespaces, and database objectsare used in the search usage reporting, begin by navigating to one of theSharePoint Search reporting pages. Take note of the URL (for example,http://demoserver/ssp/admin/_layouts/SpUsageSspSearchResults.aspx). Locate thefile on disk at C:\Program Files\Common Files\Microsoft Shared\web serverextensions\12\TEMPLATE\LAYOUTS\ SpUsageSspSearchResults.aspx and open the filewith Visual Studio or Notepad. At the top of the aspx page you?ll find the <%@Page %> directive with the Inherits attribute (Inherits=?Microsoft.SharePoint.Portal.Analytics.UI.SspQueryLoggingReportPage,Microsoft.SharePoint.Portal,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c?).This directive states that the source code for the page is stored in theMicrosoft.SharePoint.Portal.dll and the namespace, the aspx page?s class, is inis Microsoft.SharePoint.Portal.Analytics.UI. Further down in the source codeyou?ll see that the Web parts used on the page includeAnalytics:TopBestBetsReportControl and Analytics:TopDestinationsReportControl.

 

Using Reflector, open the Microsoft.SharePoint.Portal.dll,located at C:\Program Files\Common Files\Microsoft Shared\web serverextensions\12\ISAPI. Expand the following nodes of the tree:Microsoft.SharePoint.Portal | Microsoft.SharePoint.Portal.dll |Microsoft.SharePoint.Portal.Analytics.UI to reveal SspQueryLoggingReportPage,as well as TopBestBetsReportControl and TopDestinationsReportControl, amongother choices (see Figure 8).


Figure 8: Reflector viewing theMicrosoft.SharePoint.Portal.Analytics.UI namespace.

 

To view the class? source code, right-clickTopBestBetsReportControl and select Disassemble from the menu. In the rightpane, select the Expand Methods link at the bottom of the code listing to seethe code shown in Figure 9.

 

[SharePointPermission(SecurityAction.Demand, ObjectModel=true),

 AspNetHostingPermission(SecurityAction.LinkDemand,

 Level=AspNetHostingPermissionLevel.Minimal)]

public sealed class TopBestBetsReportControl :

 QueryLargeListReportControl

{

 // Properties

 protected override stringRdlFileName

 {

     get

     {

         return"ResultsTopBestBets.rdlc";

     }

 }

 

 protected override stringStoredProcedureName

 {

     get

     {

         return"proc_MSS_QLog_TopBestBets";

     }

 }

 

 protected override stringTitleText

 {

     get

     {

         returnStringResourceManager.GetString(

          LocStringId.SearchAnalytics_TopBestBetsTitle);

     }

 }

}

Figure 9: Reflectorview of TopBestBetsReportControl.

 

From this glimpse at the source code, you can see thatSharePoint is using an embedded form of Reporting Services to generate thereports, and you can see the name of the stored procedure feeding data to thereport. Searching the SharePoint server?s hard drive reveals that the .rdlcfile ResultsTopBestBets.rdlc is located at C:\Program Files\Microsoft OfficeServers\12.0\Bin\Analytics, along with 24 other rdlc files. An rdlc file is acompact Reporting Services report definition file. The major difference is thatconnection information is not stored inside the file in the case of rdlc reportdefinitions. To learn more about adding reporting services to your application,visit http://msdn2.microsoft.com/en-us/library/aa964126.aspx.

 

The next logical step in this investigation is to find thestored procedure and see what kinds of data it (and similar reporting storedprocedures) makes available. Open the SQL Server Management Studio and expandthe Programmability section of the SharedServices_DB database (not theSharedServices_Search_DB) to find the stored procedureproc_MSS_QLog_TopBestBets. Here you can see the data returned, as well as thesource tables where the raw data is stored.

 

Conclusion

At this point, you?ve learned how SharePoint ships withsome Web parts that execute SQL Statements and presents the results usingcustomized SQL Server Reporting Services display logic. Now the challenge is touse this knowledge to build our own custom Web part ? which is what we?ll do inPartII.

 

The source code accompanyingthis series is available for download.

 

Matthew S. Ranlett,a senior consultant with Intellinet?s Information Worker team, is based out of Atlanta.A Microsoft SQL Server MVP, Matt is co-author of ProfessionalSharePoint 2007 Development, and co-founder of the Atlanta.NET Regular Guys, hosted at DevCow (http://www.devcow.com).

 

Brendon Schwartz is a principal consultant with Slalom Consultingin Atlanta specializing inSharePoint 2007. Brendon is a Microsoft MVP, co-author of Professional SharePoint 2007 Development, andco-founder of the Atlanta .NETRegular Guys, hosted at DevCow (http://www.devcow.com).

 

 

 

Add a Comment

There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement




Comments from the DevConnections Community

Join our community of development pros.

Windows problem

I all, I have a problem on my Windows Vista that began afetr the purchase of an external Hard Disk Freecom. A few days afetr the purchase I discon...

Most Recent Posts

GOOGLE LINKS
SPONSORED LINKS
FEATURED LINKS