You are here: com.dtsearch.engine Package > Interfaces > IIndexStatusHandler Interface
Close
dtSearch Engine API for Java
IIndexStatusHandler Interface

IIndexStatusHandler provides an interface to obtain detailed information on the progress of an index update.

File: IIndexStatusHandler.java 

Package: com.dtsearch.engine 

Syntax
Java
public interface IIndexStatusHandler;

IIndexStatusHandler is designed for situations where it is important to have complete information, such as logging the names of documents indexed and how each file was indexed. Each time IIndexStatusHandler.onProgressUpdate is called, the IndexProgressInfo.updateType will indicate the reason for the notification. The updateType is a MessageCode value that indicates when, for example, a file was successfully indexed (dtsnIndexFileDone) or could not be indexed due to an error (dtsnIndexFileOpenFail, dtsnIndexFileEncrypted). 

To use IIndexStatusHandler, 

(1) Create an object that implements the IIndexStatusHandler interface, and 

(2) Attach it to an IndexJob prior to calling execute using setStatusHandler2(). 

Example:

/* Demonstrates use of the IIndexStatusHandler API to monitor an IndexJob in Java */ package misc; import java.util.*; import com.dtsearch.engine.*; public class IndexStatusHandlerDemo { // private class MyIndexStatusHandler implements IIndexStatusHandler { public void onProgressUpdate(IndexProgressInfo prog) { if (prog.updateType == MessageCode.dtsnIndexFileDone) System.out.println("File: " + prog.file.name + " id=" + prog.file.docId + " type=" + prog.file.type + " \n"); else if (prog.updateType == MessageCode.dtsnIndexFileEncrypted) System.out.println("Encrypted: " + prog.file.name); else if (prog.updateType == MessageCode.dtsnIndexFileOpenFail) System.out.println("Corrupt: " + prog.file.name + " " + prog.file.openFailMessage); } public int checkForAbort() { return AbortValue.Continue; } }; public static void main(String[] args) { if (args.length == 0) { System.out.println("Usage: java IndexStatusHandler IndexPath DocPath\n"); } else { IndexStatusHandlerDemo demo = new IndexStatusHandlerDemo(args[0], args[1]); demo.run(); } } private IndexJob indexJob; private MyIndexStatusHandler statusHandler; public IndexStatusHandlerDemo(String path, String toIndex) { indexJob = new IndexJob(); statusHandler = new MyIndexStatusHandler(); indexJob.setIndexPath(path); indexJob.setFoldersToIndex(toIndex); indexJob.setActionCreate(true); indexJob.setActionAdd(true); indexJob.setStatusHandler2(statusHandler); } void run() { indexJob.execute(); System.out.println("Indexing complete"); } }
com_dtsearch_engine_IIndexStatusHandler
Copyright (c) 1998-2021 dtSearch Corp. All rights reserved.