public final class FileIndexingService
extends java.lang.Object
SimpleLuceneIndex
and automatically updates the index
whenever changes to the files are made. This class uses a FileIndexingServiceWriter
to create the Lucene Document
s that are placed in the SimpleLuceneIndex
. This class looks for changes made to items in a directory of files
and updates the index automatically by adding, updating or deleting items as appropriate. The frequency
for update checkes is configurable. There should be only one instance of this class for each SimpleLuceneIndex
that is being populated with this class.Modifier and Type | Field and Description |
---|---|
static int |
INDEXING_ABORTED
Indicates that indexing was aborted by request
|
static int |
INDEXING_DIR_DOES_NOT_EXIST
Indicates that indexing directory does not exist
|
static int |
INDEXING_DIR_READ_ERROR
Indicates a read error on the directory
|
static int |
INDEXING_ERROR
Indicates that indexing completed with a severe error
|
static int |
INDEXING_ITEM_ERROR
Indicates that indexing completed successfully, but one or more item was indexed with errors
|
static int |
INDEXING_SUCCESS
Indicates that indexing completed normally
|
Constructor and Description |
---|
FileIndexingService(SimpleLuceneIndex index,
long updateFrequency,
boolean saveDeletes,
java.lang.String idFieldToRemove,
java.lang.String fileIndexingServiceDataDir,
int maxNumFilesToIndex)
Indexes files to the given
SimpleLuceneIndex , checking for changes in the
files and reindexing them at the given update frequency. |
FileIndexingService(SimpleLuceneIndex index,
long updateFrequency,
java.lang.String fileIndexingServiceDataDir,
int maxNumFilesToIndex)
Indexes files to the given
SimpleLuceneIndex , checking for changes in the
files and reindexing them at the given update frequency. |
Modifier and Type | Method and Description |
---|---|
boolean |
addDirectory(java.io.File srcDir,
java.lang.Class documentWriterClass,
java.util.HashMap documentWriterConfigAttributes,
FileIndexingPlugin plugin,
int indexingPriority)
Adds a directory of files to be monitored for changes, or replaces the current one if one exists with the
same absolute path.
|
boolean |
addDirectory(java.lang.String sourceFileDirectory,
java.lang.Class documentWriterClass,
java.util.HashMap documentWriterConfigAttributes,
FileIndexingPlugin plugin,
int indexingPriority)
Adds a directory of files to be monitored for changes, or replaces the current one if one exists with the
same absolute path.
|
void |
changeUpdateFrequency(long updateFrequency)
Changes the frequency of reindexing to the new value.
|
boolean |
deleteDirectory(java.io.File srcDir)
Deletes the files in the given directory from the index and removes it from the configuration.
|
boolean |
deleteDirectory(java.lang.String sourceFileDirectory)
Deletes the files in the given directory from the index and removes it from the configuration.
|
java.lang.Object |
getAttribute(java.lang.String key)
Gets an attribute Object from this FileIndexingService.
|
java.util.HashMap |
getConfiguredDirectories()
Gets a HashMap of all directories that are configured in this FileIndexingService, keyed by absolute
path.
|
static java.lang.String |
getDateStamp()
Return a string for the current time and date, sutiable for display in log files and output to standout:
|
java.util.ArrayList |
getIndexingMessages()
Gets the last 10 indexing status messages.
|
long |
getLastSyncTime()
Gets the lastSyncTime attribute of the FileIndexingService object
|
int |
getNumRecordsToAdd()
Gets the numRecordsToAdd attribute of the FileIndexingService object
|
int |
getNumRecordsToDelete()
Gets the numRecordsToDelete attribute of the FileIndexingService object
|
int |
getNumRecordsToReplace()
Gets the numRecordsToReplace attribute of the FileIndexingService object
|
static java.lang.String |
getSimpleDateStamp()
Return a string for the current time and date, sutiable for display in log files and output to standout:
|
long |
getUpdateFrequency()
Gets the updateFrequency attribute of the FileIndexingService object
|
void |
indexFile(java.io.File fileToIndex,
FileIndexingPlugin plugin)
Indexes a single file.
|
void |
indexFiles(boolean reindexAll,
java.io.File directory,
FileIndexingObserver observer)
Updates the index to reflect the files in the directory indicated, which must have been previously added
to this FileIndexingService using
addDirectory(java.lang.String, java.lang.Class, java.util.HashMap, org.dlese.dpc.index.writer.FileIndexingPlugin, int) . |
void |
indexFiles(boolean reindexAll,
FileIndexingObserver observer)
Updates the index to reflect the files in the directories this service is monitoring, with the option to
run the update in the background.
|
boolean |
isDirectoryConfigured(java.io.File srcDir)
Determines whether the given directory is configured for indexing.
|
boolean |
isIndexing()
Determins whether indexing is in progress.
|
void |
reindexDocs(org.apache.lucene.document.Document[] docs,
boolean reindexAll)
Reindexes the given Documents.
|
void |
reindexDocs(ResultDocList docs,
boolean reindexAll)
Reindexes the Documents in the given ResultDocs.
|
int |
reindexDocs(java.lang.String query,
boolean reindexAll)
Reindexes Documents managed by this FileIndexingService that match the given Lucene query.
|
int |
reindexDocs(java.lang.String field,
java.lang.String[] terms,
boolean reindexAll)
Re-indexes all documents that match the given terms within the given field.
|
int |
reindexDocs(java.lang.String field,
java.lang.String term,
boolean reindexAll)
Re-indexes all documents that match the given term within the given field.
|
void |
removeDocs(java.lang.String field,
java.lang.String[] terms,
FileIndexingServiceWriter docWriter)
Removes all documents that match the given terms within the given field.
|
void |
removeDocs(java.lang.String field,
java.lang.String[] terms,
FileIndexingServiceWriter docWriter,
boolean saveDeletes)
Removes all documents that match the given terms within the given field.
|
void |
removeDocs(java.lang.String field,
java.lang.String term,
FileIndexingServiceWriter docWriter)
Removes all documents that match the given term within the given field.
|
void |
removeDocs(java.lang.String field,
java.lang.String term,
FileIndexingServiceWriter docWriter,
boolean saveDeletedRecords)
Removes all documents that match the given term within the given field.
|
void |
setAttribute(java.lang.String key,
java.lang.Object attribute)
Sets an attribute Object that will be available for access here and from the FileIndexingServiceWriters.
|
static void |
setDebug(boolean db)
Sets the debug attribute object
|
void |
setValidationEnabled(boolean validateFiles)
Sets whether or not to validate the files being indexed and create a validation report, which is indexed.
|
void |
startTester(java.lang.String docRoot,
java.lang.String sourceFileDirectory)
Starts a FileMoveTester iff one is not already initialized.
|
void |
startTimerThread(long updateFrequency)
Start or restarts the timer thread with the given update frequency.
|
void |
stopIndexing()
Stops the indexing process if it is currently taking place.
|
void |
stopTester()
Stops the FileMoveTester
|
void |
stopTimerThread()
Stops the indexing timer thread.
|
public static final int INDEXING_SUCCESS
public static final int INDEXING_ABORTED
public static final int INDEXING_ERROR
public static final int INDEXING_ITEM_ERROR
public static final int INDEXING_DIR_DOES_NOT_EXIST
public static final int INDEXING_DIR_READ_ERROR
public FileIndexingService(SimpleLuceneIndex index, long updateFrequency, java.lang.String fileIndexingServiceDataDir, int maxNumFilesToIndex)
SimpleLuceneIndex
, checking for changes in the
files and reindexing them at the given update frequency. Validation of files is enabled by default.index
- The SimpleLuceneIndex
that will be
populated and updated with Documents created from filesupdateFrequency
- The frequency by which files are checked for updates, in seconds. Zero
or less indicates no updates should be performed.fileIndexingServiceDataDir
- The directory where serialized data will be storedmaxNumFilesToIndex
- Max number of files to index per iterationsetValidationEnabled(boolean validateFiles)
public FileIndexingService(SimpleLuceneIndex index, long updateFrequency, boolean saveDeletes, java.lang.String idFieldToRemove, java.lang.String fileIndexingServiceDataDir, int maxNumFilesToIndex)
SimpleLuceneIndex
, checking for changes in the
files and reindexing them at the given update frequency. Validation of files is enabled by default.index
- The SimpleLuceneIndex
that will be
populated and updated with Documents created from filesupdateFrequency
- The frequency by which files are checked for updates, in seconds. Zero
or less indicates no updates should be performed.saveDeletes
- True to save removed documents in the index and mark them deleted,
else they will be removed from the index.idFieldToRemove
- An ID field whoes docs should be removed if found in duplicate.fileIndexingServiceDataDir
- Dir where persistent data files will be storedmaxNumFilesToIndex
- The number of files to index per iterationsetValidationEnabled(boolean validateFiles)
public void setAttribute(java.lang.String key, java.lang.Object attribute)
key
- The key used to reference the attribute.attribute
- Any Java Object.FileIndexingServiceWriter
public void stopIndexing()
public java.lang.Object getAttribute(java.lang.String key)
key
- The key used to reference the attribute.FileIndexingServiceWriter
public void changeUpdateFrequency(long updateFrequency)
startTimerThread(long
updateFrequency)
.updateFrequency
- The frequency by which files are checked for changes and reindexed.public void startTimerThread(long updateFrequency)
changeUpdateFrequency(long updateFrequency)
.updateFrequency
- The number of seconds between index updates.public void stopTimerThread()
public void setValidationEnabled(boolean validateFiles)
validateFiles
- True to validate, else false.FileIndexingServiceWriter.getValidationReport()
public boolean addDirectory(java.lang.String sourceFileDirectory, java.lang.Class documentWriterClass, java.util.HashMap documentWriterConfigAttributes, FileIndexingPlugin plugin, int indexingPriority)
sourceFileDirectory
- The file direcory that will be monitored for updates.indexingPriority
- The feature to be added to the Directory attributedocumentWriterClass
- The feature to be added to the Directory attributedocumentWriterConfigAttributes
- The feature to be added to the Directory attributeplugin
- The feature to be added to the Directory attributepublic boolean addDirectory(java.io.File srcDir, java.lang.Class documentWriterClass, java.util.HashMap documentWriterConfigAttributes, FileIndexingPlugin plugin, int indexingPriority)
srcDir
- The file direcory that will be monitored for updates.indexingPriority
- The feature to be added to the Directory attributedocumentWriterClass
- The feature to be added to the Directory attributedocumentWriterConfigAttributes
- The feature to be added to the Directory attributeplugin
- The feature to be added to the Directory attributepublic boolean isIndexing()
public boolean isDirectoryConfigured(java.io.File srcDir)
srcDir
- A directory of indexable files.public java.util.HashMap getConfiguredDirectories()
public boolean deleteDirectory(java.lang.String sourceFileDirectory)
addDirectory(java.lang.String, java.lang.Class, java.util.HashMap, org.dlese.dpc.index.writer.FileIndexingPlugin, int)
method.sourceFileDirectory
- The directory of files needing to be removed from the index.public boolean deleteDirectory(java.io.File srcDir)
addDirectory(java.lang.String, java.lang.Class, java.util.HashMap, org.dlese.dpc.index.writer.FileIndexingPlugin, int)
method.srcDir
- The directory of files needing to be removed from the index.public long getUpdateFrequency()
public long getLastSyncTime()
public int getNumRecordsToDelete()
public int getNumRecordsToAdd()
public int getNumRecordsToReplace()
public void indexFiles(boolean reindexAll, FileIndexingObserver observer)
reindexAll
- True to reindex all files regardless of file mod date, False to reindex only those
files that have changed since the last indexing.observer
- The FileIndexingObserver that will be notified when indexing is complete, or null to
use nonepublic void indexFiles(boolean reindexAll, java.io.File directory, FileIndexingObserver observer)
addDirectory(java.lang.String, java.lang.Class, java.util.HashMap, org.dlese.dpc.index.writer.FileIndexingPlugin, int)
. Any new, deleted or modified files that appear
in the directory will be reflected in the index.reindexAll
- True to reindex all files regardless of file mod date, False to reindex only those
files that have changed since the last indexing.directory
- The directory to index.observer
- The FileIndexingObserver that will be notified when indexing is complete, or null to
use nonepublic void indexFile(java.io.File fileToIndex, FileIndexingPlugin plugin) throws FileIndexingServiceException
fileToIndex
- The file to index.plugin
- A FileIndexingPlugin or null.FileIndexingServiceException
- If unable to indexpublic final void removeDocs(java.lang.String field, java.lang.String term, FileIndexingServiceWriter docWriter)
SimpleLuceneIndex.removeDocs(String,String)
but is synchronized with other operations occuring in this
FileIndexinService and handles deletes accordingly.field
- The field that is searched.term
- The term that is matched for removal.docWriter
- The FileIndexingServiceWriter to usepublic final void removeDocs(java.lang.String field, java.lang.String[] terms, FileIndexingServiceWriter docWriter)
SimpleLuceneIndex.removeDocs(String,String[])
but is synchronized with other operations occuring in this
FileIndexinService and handles deletes accordingly.field
- The field that is searched.terms
- The terms that are matched for removal.docWriter
- The FileIndexingServiceWriter to usepublic final void removeDocs(java.lang.String field, java.lang.String term, FileIndexingServiceWriter docWriter, boolean saveDeletedRecords)
SimpleLuceneIndex.removeDocs(String,String)
but is synchronized with other operations occuring in this
FileIndexinService and handles deletes accordingly.field
- The field that is searched.term
- The term that is matched for removal.saveDeletedRecords
- True to save the removed documents in the index and mark them deleted, else
they will be removed from the index.docWriter
- The FileIndexingServiceWriter to usepublic final void removeDocs(java.lang.String field, java.lang.String[] terms, FileIndexingServiceWriter docWriter, boolean saveDeletes)
SimpleLuceneIndex.removeDocs(String,String[])
but is synchronized with other operations occuring in this
FileIndexinService and handles deletes accordingly.field
- The field that is searched.terms
- The terms that are matched for removal.saveDeletes
- True to save the removed documents in the index and mark them deleted, else they will
be removed from the index.docWriter
- Writer used to perform the delete.public int reindexDocs(java.lang.String field, java.lang.String term, boolean reindexAll)
field
- The field that is searched.term
- The term that is matched for updates.reindexAll
- True to reindex all matching results, false to reindex only those matches whoes files
have been modified since the last update.public int reindexDocs(java.lang.String field, java.lang.String[] terms, boolean reindexAll)
field
- The field that is searched.terms
- The terms that are matched for updates.reindexAll
- True to reindex all matching results, false to reindex only those matches whoes files
have been modified since the last update.public int reindexDocs(java.lang.String query, boolean reindexAll)
query
- A Lucene search query.reindexAll
- True to reindex all matching results, false to reindex only those matches whoes files
have been modified since the last update.public void reindexDocs(org.apache.lucene.document.Document[] docs, boolean reindexAll)
docs
- Lucene Documents from the same index that is managed by this FileIndexingService.reindexAll
- True to reindex all matching results, false to reindex only those matches whoes files
have been modified since the last update.public void reindexDocs(ResultDocList docs, boolean reindexAll)
docs
- Lucene ResultDocs from the same index that is managed by this FileIndexingService.reindexAll
- True to reindex all matching results, false to reindex only those matches whoes files
have been modified since the last update.public java.util.ArrayList getIndexingMessages()
public void startTester(java.lang.String docRoot, java.lang.String sourceFileDirectory)
docRoot
- The context document root as obtainied by calling
getServletContext().getRealPath("/");sourceFileDirectory
- DESCRIPTIONpublic void stopTester()
public static java.lang.String getSimpleDateStamp()
public static java.lang.String getDateStamp()
public static void setDebug(boolean db)
db
- The new debug value