use of org.apache.jackrabbit.core.query.QueryHandlerContext in project jackrabbit by apache.
the class SearchIndex method doInit.
/**
* Initializes this <code>QueryHandler</code>. This implementation requires
* that a path parameter is set in the configuration. If this condition
* is not met, a <code>IOException</code> is thrown.
*
* @throws IOException if an error occurs while initializing this handler.
*/
protected void doInit() throws IOException {
QueryHandlerContext context = getContext();
if (path == null) {
throw new IOException("SearchIndex requires 'path' parameter in configuration!");
}
Set<NodeId> excludedIDs = new HashSet<NodeId>();
if (context.getExcludedNodeId() != null) {
excludedIDs.add(context.getExcludedNodeId());
}
synProvider = createSynonymProvider();
directoryManager = createDirectoryManager();
redoLogFactory = createRedoLogFactory();
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(new File(path), 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(), context.getHierarchyManager(), nsMappings);
indexingConfig = createIndexingConfiguration(nsMappings);
analyzer.setIndexingConfig(indexingConfig);
// initialize the Tika parser
parser = createParser();
index = new MultiIndex(this, excludedIDs);
if (index.numDocs() == 0) {
Path rootPath;
if (excludedIDs.isEmpty()) {
// this is the index for jcr:system
rootPath = JCR_SYSTEM_PATH;
} else {
rootPath = ROOT_PATH;
}
index.createInitialIndex(context.getItemStateManager(), context.getRootId(), rootPath);
checkPendingJournalChanges(context);
}
if (consistencyCheckEnabled && (index.getRedoLogApplied() || forceConsistencyCheck)) {
log.info("Running consistency check...");
try {
ConsistencyCheck check = runConsistencyCheck();
if (autoRepair) {
check.repair(true);
} else {
List<ConsistencyCheckError> errors = check.getErrors();
if (errors.size() == 0) {
log.info("No errors detected.");
}
for (ConsistencyCheckError err : errors) {
log.info(err.toString());
}
}
} catch (Exception e) {
log.warn("Failed to run consistency check on index: " + e);
}
}
// initialize spell checker
spellChecker = createSpellChecker();
log.info("Index initialized: {} Version: {}", new Object[] { path, index.getIndexFormatVersion() });
if (!index.getIndexFormatVersion().equals(getIndexFormatVersion())) {
log.warn("Using Version {} for reading. Please re-index version " + "storage for optimal performance.", getIndexFormatVersion().getVersion());
}
}
use of org.apache.jackrabbit.core.query.QueryHandlerContext in project jackrabbit by apache.
the class RepositoryConfigurationParser method getQueryHandlerFactory.
/**
* Parses search index configuration. Search index configuration
* uses the following format:
* <pre>
* <SearchIndex class="...">
* <param name="..." value="...">
* ...
* <FileSystem ...>
* </Search>
* </pre>
* <p>
* Both the <code>SearchIndex</code> and <code>FileSystem</code>
* elements are {@link #parseBeanConfig(Element,String) bean configuration}
* elements. If the search implementation class is not given, then
* a default implementation is used.
* <p>
* The search index is an optional feature of workspace configuration.
* If the search configuration element is not found, then this method
* returns <code>null</code>.
* <p>
* The FileSystem element in a search index configuration is optional.
* However some implementations may require a FileSystem.
*
* @param parent parent of the <code>SearchIndex</code> element
* @return query handler factory
*/
protected QueryHandlerFactory getQueryHandlerFactory(final Element parent) {
NodeList children = parent.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
final Node child = children.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE && SEARCH_INDEX_ELEMENT.equals(child.getNodeName())) {
return new QueryHandlerFactory() {
public QueryHandler getQueryHandler(QueryHandlerContext context) throws RepositoryException {
Element element = (Element) child;
// Optional file system implementation
FileSystem fs = null;
if (getElement(element, FILE_SYSTEM_ELEMENT, false) != null) {
fs = getFileSystemFactory(element, FILE_SYSTEM_ELEMENT).getFileSystem();
}
// Search implementation class
String className = getAttribute(element, CLASS_ATTRIBUTE, DEFAULT_QUERY_HANDLER);
BeanConfig config = new BeanConfig(className, parseParameters(element));
QueryHandler handler = config.newInstance(QueryHandler.class);
try {
handler.init(fs, context);
return handler;
} catch (IOException e) {
throw new RepositoryException("Unable to initialize query handler: " + handler, e);
}
}
};
}
}
return null;
}
Aggregations