Programmatically starting and incremental crawl in Sharepoint SSP

Hi,

 

When working is Sharepoint we have to work with Sharepoint search. Search point search works with indexed data. The data is indexed with the help of the Sharepoint crawl. For crawling purpose, we normally make one full crawl and after that incremental crawl at different interval based on the requirement.

 

But some times business might require that incremental crawl must be executed on update of some very important records. At this point we have two option one to schedule the incremental crawl to lowest possible time difference (like 2 minutes). But this can be very resource exhaustive for the server and can cause some performance issue on the server.

 

Another possible solution can be that we start the incremental crawl by code itself. This crawl should be started by on the update of any important data as per the business requirement.

 

I had a similar requirement where the business wanted to get the updated data in the search result in 1 minute for a particular list. For this I created a way which would make incremental crawl on call. Below is the code for the same.

 

string strURL = SPContext.Current.Site.Url;

SearchContext context;

 

using (SPSite site = new SPSite(strURL))

{

     context = SearchContext.GetContext(site);

}

 

Microsoft.Office.Server.Search.Administration.Content sspContent = new Microsoft.Office.Server.Search.Administration.Content(context);

 

// fetch the name of the Content Source from the config file
string strContentSource = ConfigurationManager.AppSettings["ContentSources"];               

ContentSourceCollection sspContentSources = sspContent.ContentSources;

ContentSource cs = sspContentSources[strContentSource];

 

if (cs.CrawlStatus == CrawlStatus.Idle)

{

     cs.StartIncrementalCrawl();

}

 

That’s all you need to do to start an incremental crawl in the Sharepoint SSP.

 

Regards

Vikram


Share this post   Email it

Feedback

Posted on 2/16/2009 1:31:00 PM

I executed the exe. But i guess it didn't my event handler. Can I have the code.

Posted on 10/5/2009 10:52:13 AM

Hi
Thanks a lot for the post. It was good. But, can you tell when did you call this code that programmatically monitors the incremental crawling.

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 

Copyright © 2006 - 2010 Vikram Lakhotia