Need help to complete my C# program. I have four content sources in my farm. I need to get all the content sources and start full crawl if the content source is idle.
What is the best way to do it. Please can someone point me to a good article for Sharepoint search object model / fast search object model.
you can get all ContentSourceCollection using like this:
/*
Replace <SiteName> with the name of a site using the SSP
*/
string strURL = "http://<SiteName>";
SearchContext context;
using (SPSite site = new SPSite(strURL))
{
context = SearchContext.GetContext(site);
}
Content sspContent = new Content(context);
ContentSourceCollection sspContentSources = sspContent.ContentSources;
foreach (ContentSource cs in sspContentSources)
{
Console.WriteLine("NAME: " + cs.Name + " ID: " + cs.Id);
}
if you want to specific ContentSource
than :
string strContentSourceName = "FASTQuerySSA"; //which indicates the name of the content source to retrieve
ContentSource cs = sspContentSources[strContentSourceName];
Console.WriteLine("Crawl Status = " + cs.CrawlStatus);
Console.WriteLine("Crawl started at: " + cs.CrawlStarted.ToString());
Console.WriteLine("Crawl completed at: " + cs.CrawlCompleted.ToString());
cs.StartIncrementalCrawl();
break;
cs.StartFullCrawl();
break;
cs.PauseCrawl();
break;
cs.StopCrawl();
break;
for more details see here : http://msdn.microsoft.com/en-us/library/aa679491%28v=office.12%29.aspx
Here's some code to enumerate all of the search service applications in your farm. It DOES include all of them, including both FAST content and FAST query:
SearchService s = new SearchService("OSearch14", SPFarm.Local);
foreach (SearchServiceApplication ssa in s.SearchApplications)
{
//do something with the proxy here
}