Search in sources :

Example 1 with IndexRow

use of org.apache.jackrabbit.oak.spi.query.IndexRow in project jackrabbit-oak by apache.

the class IndexPathServiceImpl method getIndexPaths.

@Override
public Iterable<String> getIndexPaths() {
    NodeState nodeType = NodeStateUtils.getNode(nodeStore.getRoot(), "/oak:index/nodetype");
    checkState("property".equals(nodeType.getString("type")), "nodetype index at " + "/oak:index/nodetype is found to be disabled. Cannot determine the paths of all indexes");
    // Check if oak:QueryIndexDefinition is indexed as part of nodetype index
    boolean indxDefnTypeIndexed = Iterables.contains(nodeType.getNames(DECLARING_NODE_TYPES), INDEX_DEFINITIONS_NODE_TYPE);
    if (!indxDefnTypeIndexed) {
        log.warn("{} is not found to be indexed as part of nodetype index. Non root indexes would " + "not be listed", INDEX_DEFINITIONS_NODE_TYPE);
        NodeState oakIndex = nodeStore.getRoot().getChildNode("oak:index");
        return transform(filter(oakIndex.getChildNodeEntries(), cne -> INDEX_DEFINITIONS_NODE_TYPE.equals(cne.getNodeState().getName(JCR_PRIMARYTYPE))), cne -> PathUtils.concat("/oak:index", cne.getName()));
    }
    return () -> {
        Iterator<IndexRow> itr = getIndex().query(createFilter(INDEX_DEFINITIONS_NODE_TYPE), nodeStore.getRoot());
        return transform(itr, input -> input.getPath());
    };
}
Also used : Iterables(com.google.common.collect.Iterables) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) Iterables.transform(com.google.common.collect.Iterables.transform) PathUtils(org.apache.jackrabbit.oak.commons.PathUtils) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) DECLARING_NODE_TYPES(org.apache.jackrabbit.oak.plugins.index.IndexConstants.DECLARING_NODE_TYPES) JCR_PRIMARYTYPE(org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE) Mounts(org.apache.jackrabbit.oak.spi.mount.Mounts) LoggerFactory(org.slf4j.LoggerFactory) Iterators(com.google.common.collect.Iterators) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) Component(org.osgi.service.component.annotations.Component) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeTypeInfoProvider(org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) INDEX_DEFINITIONS_NODE_TYPE(org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NODE_TYPE) NodeTypeIndexProvider(org.apache.jackrabbit.oak.plugins.index.nodetype.NodeTypeIndexProvider) Iterators.transform(com.google.common.collect.Iterators.transform) Preconditions.checkState(com.google.common.base.Preconditions.checkState) NodeTypeInfo(org.apache.jackrabbit.oak.query.ast.NodeTypeInfo) IndexRow(org.apache.jackrabbit.oak.spi.query.IndexRow) Iterables.filter(com.google.common.collect.Iterables.filter) Reference(org.osgi.service.component.annotations.Reference) NodeStateUtils(org.apache.jackrabbit.oak.spi.state.NodeStateUtils) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Iterator(java.util.Iterator)

Example 2 with IndexRow

use of org.apache.jackrabbit.oak.spi.query.IndexRow in project jackrabbit-oak by apache.

the class SolrQueryIndexTest method testNoMoreThanThreeSolrRequests.

@Test
public void testNoMoreThanThreeSolrRequests() throws Exception {
    NodeState root = InitialContent.INITIAL_CONTENT;
    SelectorImpl selector = newSelector(root, "a");
    String sqlQuery = "select [jcr:path], [jcr:score] from [nt:base] as a where" + " contains([jcr:content/*], 'founded')";
    SolrClient solrServer = mock(SolrClient.class);
    SolrServerProvider solrServerProvider = mock(SolrServerProvider.class);
    when(solrServerProvider.getSearchingSolrServer()).thenReturn(solrServer);
    OakSolrConfigurationProvider configurationProvider = mock(OakSolrConfigurationProvider.class);
    OakSolrConfiguration configuration = new DefaultSolrConfiguration() {

        @Override
        public boolean useForPropertyRestrictions() {
            return true;
        }

        @Override
        public int getRows() {
            return 10;
        }
    };
    when(configurationProvider.getConfiguration()).thenReturn(configuration);
    SolrQueryIndex solrQueryIndex = new SolrQueryIndex(null, configurationProvider, solrServerProvider);
    FilterImpl filter = new FilterImpl(selector, sqlQuery, new QueryEngineSettings());
    CountingResponse response = new CountingResponse(0);
    when(solrServer.query(any(SolrParams.class))).thenReturn(response);
    List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, null, root);
    for (QueryIndex.IndexPlan p : plans) {
        Cursor cursor = solrQueryIndex.query(p, root);
        assertNotNull(cursor);
        while (cursor.hasNext()) {
            IndexRow row = cursor.next();
            assertNotNull(row);
        }
        assertEquals(3, response.getCounter());
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) IndexRow(org.apache.jackrabbit.oak.spi.query.IndexRow) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor) OakSolrConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider) SolrClient(org.apache.solr.client.solrj.SolrClient) SolrServerProvider(org.apache.jackrabbit.oak.plugins.index.solr.server.SolrServerProvider) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) DefaultSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration) SolrParams(org.apache.solr.common.params.SolrParams) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) Test(org.junit.Test)

Example 3 with IndexRow

use of org.apache.jackrabbit.oak.spi.query.IndexRow in project jackrabbit-oak by apache.

the class LuceneIndexTest method testLuceneLazyCursor.

@Test
public void testLuceneLazyCursor() throws Exception {
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    newLucenePropertyIndexDefinition(index, "lucene", ImmutableSet.of("foo"), null);
    NodeState before = builder.getNodeState();
    builder.setProperty("foo", "bar");
    for (int i = 0; i < LuceneIndex.LUCENE_QUERY_BATCH_SIZE; i++) {
        builder.child("parent").child("child" + i).setProperty("foo", "bar");
    }
    NodeState after = builder.getNodeState();
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    tracker = new IndexTracker();
    tracker.update(indexed);
    AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker);
    FilterImpl filter = createFilter(NT_BASE);
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
    List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed);
    Cursor cursor = queryIndex.query(plans.get(0), indexed);
    List<String> paths = copyOf(transform(cursor, new Function<IndexRow, String>() {

        public String apply(IndexRow input) {
            return input.getPath();
        }
    }));
    assertTrue(!paths.isEmpty());
    assertEquals(LuceneIndex.LUCENE_QUERY_BATCH_SIZE + 1, paths.size());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) IndexRow(org.apache.jackrabbit.oak.spi.query.IndexRow) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor) AdvancedQueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex) Function(com.google.common.base.Function) IndexPlan(org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan) Test(org.junit.Test)

Aggregations

FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)3 IndexRow (org.apache.jackrabbit.oak.spi.query.IndexRow)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 QueryEngineSettings (org.apache.jackrabbit.oak.query.QueryEngineSettings)2 SelectorImpl (org.apache.jackrabbit.oak.query.ast.SelectorImpl)2 Cursor (org.apache.jackrabbit.oak.spi.query.Cursor)2 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)2 Test (org.junit.Test)2 Function (com.google.common.base.Function)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Iterables (com.google.common.collect.Iterables)1 Iterables.filter (com.google.common.collect.Iterables.filter)1 Iterables.transform (com.google.common.collect.Iterables.transform)1 Iterators (com.google.common.collect.Iterators)1 Iterators.transform (com.google.common.collect.Iterators.transform)1 Iterator (java.util.Iterator)1 JCR_PRIMARYTYPE (org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE)1 PathUtils (org.apache.jackrabbit.oak.commons.PathUtils)1 DECLARING_NODE_TYPES (org.apache.jackrabbit.oak.plugins.index.IndexConstants.DECLARING_NODE_TYPES)1 INDEX_DEFINITIONS_NODE_TYPE (org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NODE_TYPE)1