Search in sources :

Example 1 with QueryHandler

use of org.apache.jackrabbit.core.query.QueryHandler in project jackrabbit-oak by apache.

the class IndexAccessor method getReader.

public static IndexReader getReader(RepositoryContext ctx) throws RepositoryException, IOException {
    RepositoryImpl repo = ctx.getRepository();
    SearchManager searchMgr = repo.getSearchManager(ctx.getRepositoryConfig().getDefaultWorkspaceName());
    if (searchMgr == null) {
        return null;
    }
    QueryHandler handler = searchMgr.getQueryHandler();
    SearchIndex index = (SearchIndex) handler;
    return index.getIndexReader();
}
Also used : QueryHandler(org.apache.jackrabbit.core.query.QueryHandler) SearchIndex(org.apache.jackrabbit.core.query.lucene.SearchIndex)

Example 2 with QueryHandler

use of org.apache.jackrabbit.core.query.QueryHandler 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)

Example 3 with QueryHandler

use of org.apache.jackrabbit.core.query.QueryHandler in project jackrabbit by apache.

the class SearchIndex method getIndexReader.

/**
     * Returns an index reader for this search index. The caller of this method
     * is responsible for closing the index reader when he is finished using
     * it.
     *
     * @param includeSystemIndex if <code>true</code> the index reader will
     *                           cover the complete workspace. If
     *                           <code>false</code> the returned index reader
     *                           will not contains any nodes under /jcr:system.
     * @return an index reader for this search index.
     * @throws IOException the index reader cannot be obtained.
     */
protected IndexReader getIndexReader(boolean includeSystemIndex) throws IOException {
    QueryHandler parentHandler = getContext().getParentHandler();
    CachingMultiIndexReader parentReader = null;
    if (parentHandler instanceof SearchIndex && includeSystemIndex) {
        parentReader = ((SearchIndex) parentHandler).index.getIndexReader();
    }
    IndexReader reader;
    if (parentReader != null) {
        CachingMultiIndexReader[] readers = { index.getIndexReader(), parentReader };
        reader = new CombinedIndexReader(readers);
    } else {
        reader = index.getIndexReader();
    }
    return new JackrabbitIndexReader(reader);
}
Also used : AbstractQueryHandler(org.apache.jackrabbit.core.query.AbstractQueryHandler) QueryHandler(org.apache.jackrabbit.core.query.QueryHandler) IndexReader(org.apache.lucene.index.IndexReader)

Example 4 with QueryHandler

use of org.apache.jackrabbit.core.query.QueryHandler in project jackrabbit by apache.

the class TestHelper method checkIndexConsistency.

public static ConsistencyCheck checkIndexConsistency(Session session) throws RepositoryException, NotExecutableException, IOException {
    Repository r = session.getRepository();
    if (!(r instanceof RepositoryImpl)) {
        throw new NotExecutableException();
    }
    RepositoryImpl ri = (RepositoryImpl) r;
    final String workspaceName = session.getWorkspace().getName();
    QueryHandler qh = ri.getSearchManager(workspaceName).getQueryHandler();
    if (!(qh instanceof SearchIndex)) {
        throw new NotExecutableException("No search index");
    }
    SearchIndex si = (SearchIndex) qh;
    return si.runConsistencyCheck();
}
Also used : Repository(javax.jcr.Repository) QueryHandler(org.apache.jackrabbit.core.query.QueryHandler) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) SearchIndex(org.apache.jackrabbit.core.query.lucene.SearchIndex)

Aggregations

QueryHandler (org.apache.jackrabbit.core.query.QueryHandler)4 SearchIndex (org.apache.jackrabbit.core.query.lucene.SearchIndex)2 IOException (java.io.IOException)1 Repository (javax.jcr.Repository)1 RepositoryException (javax.jcr.RepositoryException)1 ClusterNode (org.apache.jackrabbit.core.cluster.ClusterNode)1 FileSystem (org.apache.jackrabbit.core.fs.FileSystem)1 AbstractQueryHandler (org.apache.jackrabbit.core.query.AbstractQueryHandler)1 QueryHandlerContext (org.apache.jackrabbit.core.query.QueryHandlerContext)1 QueryHandlerFactory (org.apache.jackrabbit.core.query.QueryHandlerFactory)1 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)1 IndexReader (org.apache.lucene.index.IndexReader)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1