Starting an incremental crawl in Share point programmatically
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