* @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);
try
{
SecurityHelper.doPrivilegedExceptionAction((new PrivilegedExceptionAction<Object>()
{
public Object run() throws Exception
{
if (!indexDirectory.exists())
{
if (!indexDirectory.mkdirs())
{
throw new RepositoryException("fail to create index dir " + path);
}
}
return null;
}
}));
}
catch (PrivilegedActionException pae)
{
Throwable cause = pae.getCause();
if (cause instanceof RepositoryException)
{
throw (RepositoryException)cause;
}
else if (cause instanceof RuntimeException)
{
throw (RuntimeException)cause;
}
else
{
throw new RuntimeException(cause);
}
}
}
else
{
throw new IOException("SearchIndex requires 'path' parameter in configuration!");
}
log.info("path=" + path);
// Set excludedIDs = new HashSet();
// if (context.getExcludedNodeId() != null)
// {
// excludedIDs.add(context.getExcludedNodeId());
// }
extractor = context.getExtractor();
synProvider = createSynonymProvider();//queryHandlerConfig.createSynonymProvider(cfm);
directoryManager = createDirectoryManager();
if (context.getParentHandler() instanceof SearchIndex)
{
// use system namespace mappings
SearchIndex sysIndex = (SearchIndex)context.getParentHandler();
nsMappings = sysIndex.getNamespaceMappings();
}
else
{
// read local namespace mappings
final File mapFile = new File(indexDirectory, NS_MAPPING_FILE);
boolean fileExists = SecurityHelper.doPrivilegedAction(new PrivilegedAction<Boolean>()
{
public Boolean run()
{
return mapFile.exists();
}
});
if (fileExists)
{
// 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 SharedFieldSortComparator(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)
{
final boolean doReindexing = (index.numDocs() == 0 && context.isCreateInitialIndex());
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, 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, doCheck, itemStateManager);
}