Fabian Williams SharePoint Blog

Solving problems with SharePoint day and night

How To: Part 2: Create Content Sources, Search Scope and Use the MOSS Object Model for Search


Part 2 of a 5 Part Series:

Part 1: How to Setup a Content Source, Search Scope in the SSP and Consume that Scope in a Site Collection
Part 2:  Coding Enterprise Search – Coding a Content Source, Coding a Crawl  Schedule (Full and Incremental)
Part 3:  Coding Enterprise Search – Coding Scopes, Crawl Rules, File Types (Inclusion and Exclusions) and Crawled Properties (Managed and Crawled)
Part 4:  Coding Federated Search –
Part 5:  Coding and Using the Web Service Query Object Model –

Scenario:

In this blog we will go about how to create a Content Source in the Shared Services Provider, we will create a File Share Content Source and a SSP Search Scope that may be consumed by Site Collection Administrators.  Once we complete that we will take a look into how one could enhance their search experience by a using the MOSS Object Model and Search Objects to further customize that experience. This will be a 5 Part Series and this Part 2 will cover how to Code what we did through the Central Administration in Part 1. So we will begin by creating the Content Source, create a Crawl Plan for Full and Incremental Crawl and to test this we will create a Windows Forms Application in C# to walk through the process.  Sit back have fun..

 

Step 1: We need to have a location to actually use as the Content Source, so we will create a folder on the Hard Drive, Share it out and ensure again that we give NTFS “Read Permission” to the SharePoint Crawl Account for that shared location

clip_image002

Step 2:  To facilitate a walkthrough of the Code I created a Windows Form Application in C# and set References to SharePoint Dll’s in the 12 Hive necessary for Coding against the Search Object Model. We only need the following:

  • Microsoft.Office.Server
  • Microsoft.Office.Server.Search

However I plan to do a few more tips-and-tricks so i added

  • Microsoft.SharePoint
  • Microsoft.SharePoint.Search

clip_image006

References Added in my Windows Project.

clip_image008

Step 3:  We will verify what is in the Content Sources now and as we can see we have two currently

  1. Local Office SharePoint Server sites
  2. Just Stuff (the one we added in Part 1) via the Central Administration

clip_image010

Step 4:  Crack open your Visual Studio and Create a Windows Form Application.  Make References to the .NET Libraries mentioned in Step 2

clip_image012

Step 5:  Once you Execute the Code a Content Source is created and the Message box denotes the Name and Type.  You will notice below that it is of File Type “FileShareContentSource”

clip_image014

Step 6:  Now we re-verify by refreshing the page and you will see “Demo Test FileShare”

clip_image016

Step 7:  After we complete creating the “Demo Test FileShare” Content Source. We code in a Full Crawl in the “Begin Crawl” button Click Event… see code below

 

image

 

clip_image018

 

clip_image020

Step 8:  We see from the two screen shots below the crawling has begun and the end of the crawl from our Coded Event

clip_image022

 

clip_image024

Step 9:  Next on the list is to create a Crawl Schedule to set up a consistent crawl

clip_image026

Step 10:  Code used to create the Crawl Schedule.  Things to point out as you will see when the crawl schedule is created is i indicated that the beginning of the week is Monday. Since today is Wednesday, the next Incremental crawl will not be till next Monday. 

clip_image028

Step 11:  In the code i took it a step further to re-use existing objects on the windows form. So what we have is:

  • You click the Get Search Context button to iterate through the Search Context Objects (Content Sources) in the SSP
  • When you click on the item in the List Box we fire off an event that we will capture and pass along to code that will create the Weekly Crawl Schedule
  • When you click “Set Crawl Schedule” it fires the code in Step 10

clip_image030

clip_image032

clip_image034

Step 12:  Verify in the Search Setting Page that the Crawl Schedule is created

clip_image036

Have Fun with this…

Advertisements

September 23, 2009 - Posted by | SharePoint Administration, SharePoint Development, SharePoint How-To | , , , , , ,

No comments yet.

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

%d bloggers like this: