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 –
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
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:
However I plan to do a few more tips-and-tricks so i added
References Added in my Windows Project.
Step 3: We will verify what is in the Content Sources now and as we can see we have two currently
- Local Office SharePoint Server sites
- Just Stuff (the one we added in Part 1) via the Central Administration
Step 4: Crack open your Visual Studio and Create a Windows Form Application. Make References to the .NET Libraries mentioned in Step 2
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”
Step 6: Now we re-verify by refreshing the page and you will see “Demo Test FileShare”
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
Step 8: We see from the two screen shots below the crawling has begun and the end of the crawl from our Coded Event
Step 9: Next on the list is to create a Crawl Schedule to set up a consistent crawl
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.
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
Step 12: Verify in the Search Setting Page that the Crawl Schedule is created
Have Fun with this…
No comments yet.