Search in sources :

Example 1 with SearchIndex

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

use of org.apache.jackrabbit.core.query.lucene.SearchIndex in project jackrabbit by apache.

the class QueryObjectModelImpl method init.

/**
 * Initializes a query instance from a query object model.
 *
 * @param sessionContext component context of the current session
 * @param handler  the query handler of the search index.
 * @param qomTree  the query object model tree.
 * @param language the original query syntax from where the JQOM was
 *                 created.
 * @param node     a nt:query node where the query was read from or
 *                 <code>null</code> if it is not a stored query.
 * @throws InvalidQueryException if the qom tree cannot be serialized
 *                               according to the given language.
 * @throws RepositoryException   if another error occurs
 */
public void init(SessionContext sessionContext, QueryHandler handler, QueryObjectModelTree qomTree, String language, Node node) throws InvalidQueryException, RepositoryException {
    checkNotInitialized();
    this.sessionContext = sessionContext;
    this.language = language;
    this.handler = handler;
    this.qomTree = qomTree;
    this.node = node;
    this.statement = QueryObjectModelBuilderRegistry.getQueryObjectModelBuilder(language).toString(this);
    try {
        qomTree.accept(new DefaultTraversingQOMTreeVisitor() {

            @Override
            public Object visit(BindVariableValueImpl node, Object data) {
                variables.put(node.getBindVariableName(), null);
                return data;
            }
        }, null);
    } catch (Exception ignore) {
    }
    this.lqf = new LuceneQueryFactory(sessionContext.getSessionImpl(), (SearchIndex) handler, variables);
    setInitialized();
}
Also used : DefaultTraversingQOMTreeVisitor(org.apache.jackrabbit.spi.commons.query.qom.DefaultTraversingQOMTreeVisitor) BindVariableValueImpl(org.apache.jackrabbit.spi.commons.query.qom.BindVariableValueImpl) SearchIndex(org.apache.jackrabbit.core.query.lucene.SearchIndex) LuceneQueryFactory(org.apache.jackrabbit.core.query.lucene.LuceneQueryFactory) RepositoryException(javax.jcr.RepositoryException) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Example 3 with SearchIndex

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

SearchIndex (org.apache.jackrabbit.core.query.lucene.SearchIndex)3 QueryHandler (org.apache.jackrabbit.core.query.QueryHandler)2 Repository (javax.jcr.Repository)1 RepositoryException (javax.jcr.RepositoryException)1 InvalidQueryException (javax.jcr.query.InvalidQueryException)1 LuceneQueryFactory (org.apache.jackrabbit.core.query.lucene.LuceneQueryFactory)1 BindVariableValueImpl (org.apache.jackrabbit.spi.commons.query.qom.BindVariableValueImpl)1 DefaultTraversingQOMTreeVisitor (org.apache.jackrabbit.spi.commons.query.qom.DefaultTraversingQOMTreeVisitor)1 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)1