Search in sources :

Example 1 with QueryHandlerContext

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());
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) QueryHandlerContext(org.apache.jackrabbit.core.query.QueryHandlerContext) IOException(java.io.IOException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) SAXException(org.xml.sax.SAXException) JournalException(org.apache.jackrabbit.core.journal.JournalException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) RepositoryException(javax.jcr.RepositoryException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) InvalidQueryException(javax.jcr.query.InvalidQueryException) NodeId(org.apache.jackrabbit.core.id.NodeId) File(java.io.File) HashSet(java.util.HashSet)

Example 2 with QueryHandlerContext

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>
     *   &lt;SearchIndex class="..."&gt;
     *     &lt;param name="..." value="..."&gt;
     *     ...
     *     &lt;FileSystem ...&gt;
     *   &lt;/Search&gt;
     * </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;
}
Also used : QueryHandlerFactory(org.apache.jackrabbit.core.query.QueryHandlerFactory) QueryHandler(org.apache.jackrabbit.core.query.QueryHandler) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ClusterNode(org.apache.jackrabbit.core.cluster.ClusterNode) Element(org.w3c.dom.Element) FileSystem(org.apache.jackrabbit.core.fs.FileSystem) RepositoryException(javax.jcr.RepositoryException) QueryHandlerContext(org.apache.jackrabbit.core.query.QueryHandlerContext) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 RepositoryException (javax.jcr.RepositoryException)2 QueryHandlerContext (org.apache.jackrabbit.core.query.QueryHandlerContext)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 HashSet (java.util.HashSet)1 InvalidQueryException (javax.jcr.query.InvalidQueryException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 ClusterNode (org.apache.jackrabbit.core.cluster.ClusterNode)1 FileSystem (org.apache.jackrabbit.core.fs.FileSystem)1 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)1 NodeId (org.apache.jackrabbit.core.id.NodeId)1 JournalException (org.apache.jackrabbit.core.journal.JournalException)1 QueryHandler (org.apache.jackrabbit.core.query.QueryHandler)1 QueryHandlerFactory (org.apache.jackrabbit.core.query.QueryHandlerFactory)1 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)1 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)1 Path (org.apache.jackrabbit.spi.Path)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1