Call the
CasCrawler.startCrawl()
method to start a crawl.
The syntax of the method is:
CasCrawler.startCrawl(CrawlId crawlId, CrawlMode crawlMode)
The
crawlId
parameter is a
CrawlId
object that has the crawl ID set. The
crawlMode
parameter is one of the following
CrawlMode
data types:
CrawlMode.FULL_CRAWL
performs a full crawl and creates a crawl history.CrawlMode.INCREMENTAL_CRAWL
performs an incremental crawl and updates the crawl history. There are several cases in which theCrawlMode
automatically switches over fromINCREMENTAL_CRAWL
to run aFULL_CRAWL
. A full crawl runs in the following cases:
This method does not return a value.
To start a crawl:
Make sure that you have created a connection to the CAS Server. (A
CasCrawler
object namedcrawler
is used in this example.)Instantiate a
CrawlId
object and then set its Id in the constructor.For example:
// Create a new crawl Id with the name set to Demo. CrawlId crawlId = new CrawlId("Demo");
Call the
CasCrawler.startCrawl()
method with the crawl ID and the appropriate crawl mode. To catch exceptions, use a try block with the appropriate catch clauses.For example:
try { crawler.startCrawl(crawlId, CrawlMode.INCREMENTAL_CRAWL); } catch (CrawlNotFoundException e) { System.out.println(e.getLocalizedMessage()); }
If the
CasCrawler.startCrawl()
method fails, it throws an
exception:
CrawlInProgressException
occurs if the CAS Server is already running the specified crawl.CrawlNotFoundException
occurs if the specified crawl (thecrawlId
parameter) does not exist or is otherwise not found.InvalidCrawlConfigException
occurs if the configuration is invalid. You can callgetCrawlValidationFailures()
to return the list of crawl validation errors.ItlException
occurs if other problems prevent the crawl from running.
As shown in step 3, use a
try
block to catch these exceptions.