Question

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.

Was it helpful?

Solution

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];

To check the crawl status values for a content source

 Console.WriteLine("Crawl Status = " + cs.CrawlStatus);
 Console.WriteLine("Crawl started at: " + cs.CrawlStarted.ToString());
 Console.WriteLine("Crawl completed at: " + cs.CrawlCompleted.ToString());

To start an incremental crawl of the content source

   cs.StartIncrementalCrawl();
   break;

To start a full crawl of the content source

   cs.StartFullCrawl();
   break;

To pause a crawl in process

  cs.PauseCrawl();
  break; 

To stop a crawl of the content source

  cs.StopCrawl();
  break;

for more details see here : http://msdn.microsoft.com/en-us/library/aa679491%28v=office.12%29.aspx

UPDATE:

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
   }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top