* @throws RepositoryException
*/
@Override
public void doInit() throws IOException, RepositoryException
{
QueryHandlerContext context = getContext();
setPath(context.getIndexDirectory());
if (path == null)
{
throw new IOException("SearchIndex requires 'path' parameter in configuration!");
}
final File indexDirectory;
if (path != null)
{
indexDirectory = new File(path);
if (!indexDirectory.exists())
{
if (!indexDirectory.mkdirs())
{
throw new RepositoryException("fail to create index dir " + path);
}
}
}
else
{
throw new IOException("SearchIndex requires 'path' parameter in configuration!");
}
log.info("Index created: " + path);
extractor = context.getExtractor();
synProvider = createSynonymProvider();
directoryManager = createDirectoryManager();
if (context.getParentHandler() instanceof SearchIndex)
{
// use system namespace mappings
SearchIndex sysIndex = (SearchIndex)context.getParentHandler();
nsMappings = sysIndex.getNamespaceMappings();
}
else
{
// read local namespace mappings
File mapFile = new File(indexDirectory, NS_MAPPING_FILE);
if (mapFile.exists())
{
// be backward compatible and use ns_mappings.properties from
// index folder
nsMappings = new FileBasedNamespaceMappings(mapFile);
}
else
{
// otherwise use repository wide stable index prefix from
// namespace registry
nsMappings = new NSRegistryBasedNamespaceMappings(context.getNamespaceRegistry());
}
}
scs = new SharedFieldComparatorSource(FieldNames.PROPERTIES, context.getItemStateManager(), nsMappings);
sics =
new SharedFieldInsensitiveComparatorSource(FieldNames.PROPERTIES, context.getItemStateManager(), nsMappings);
npResolver = new LocationFactory(nsMappings);
indexingConfig = createIndexingConfiguration(nsMappings);
analyzer.setIndexingConfig(indexingConfig);
index = new MultiIndex(this, context.getIndexingTree(), modeHandler, getIndexInfos(), getIndexUpdateMonitor());
// if RW mode, create initial index and start check
if (modeHandler.getMode() == IndexerIoMode.READ_WRITE)
{
// set true if indexRecoveryFilters are required and some filter gives positive flag
final boolean doReindexing = (index.numDocs() == 0 && context.isCreateInitialIndex());
// if existing index should be removed
final boolean doForceReindexing = (context.isRecoveryFilterUsed() && isIndexRecoveryRequired());
final boolean doCheck = (consistencyCheckEnabled && (index.getRedoLogApplied() || forceConsistencyCheck));
final ItemDataConsumer itemStateManager = context.getItemStateManager();
if (isAsyncReindexing() && doReindexing)
{
log.info("Launching reindexing in asynchronous mode.");
new Thread(new Runnable()
{
public void run()
{
try
{
reindex(doReindexing, doForceReindexing, doCheck, itemStateManager);
}
catch (IOException e)
{
log.error(
"Error while reindexing the workspace. Please fix the problem, delete index and restart server.",
e);
}
}
}, "Reindexing-" + context.getRepositoryName() + "-" + context.getContainer().getWorkspaceName()).start();
}
else
{
reindex(doReindexing, doForceReindexing, doCheck, itemStateManager);
}