Search in sources :

Example 6 with Cursor

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

the class AggregateIndex method flatten.

private Cursor flatten(FullTextExpression constraint, final AggregateIndexPlan plan, final Filter filter, final NodeState state, final String path) {
    if (constraint == null) {
        return null;
    }
    final AtomicReference<Cursor> result = new AtomicReference<Cursor>();
    constraint.accept(new FullTextVisitor() {

        @Override
        public boolean visit(FullTextContains contains) {
            return contains.getBase().accept(this);
        }

        @Override
        public boolean visit(FullTextTerm term) {
            IndexPlan p = plan.getPlan(path);
            result.set(newAggregationCursor(p, state));
            return true;
        }

        @Override
        public boolean visit(FullTextAnd and) {
            Iterator<FullTextExpression> iterator = and.list.iterator();
            int index = 0;
            Cursor c = flatten(iterator.next(), plan, filter, state, path + " and(" + index + ")");
            while (iterator.hasNext()) {
                index++;
                FullTextExpression input = iterator.next();
                Cursor newC = flatten(input, plan, filter, state, path + " and(" + index + ")");
                c = Cursors.newIntersectionCursor(c, newC, filter.getQueryLimits());
            }
            result.set(c);
            return true;
        }

        @Override
        public boolean visit(FullTextOr or) {
            final int[] index = new int[1];
            List<Cursor> cursors = Lists.transform(or.list, new Function<FullTextExpression, Cursor>() {

                @Override
                public Cursor apply(FullTextExpression input) {
                    return flatten(input, plan, filter, state, path + " or(" + index[0]++ + ")");
                }
            });
            result.set(Cursors.newConcatCursor(cursors, filter.getQueryLimits()));
            return true;
        }
    });
    return result.get();
}
Also used : FullTextOr(org.apache.jackrabbit.oak.spi.query.fulltext.FullTextOr) FullTextContains(org.apache.jackrabbit.oak.spi.query.fulltext.FullTextContains) AtomicReference(java.util.concurrent.atomic.AtomicReference) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor) Function(com.google.common.base.Function) FullTextVisitor(org.apache.jackrabbit.oak.spi.query.fulltext.FullTextVisitor) FullTextTerm(org.apache.jackrabbit.oak.spi.query.fulltext.FullTextTerm) FullTextAnd(org.apache.jackrabbit.oak.spi.query.fulltext.FullTextAnd) Iterator(java.util.Iterator) FullTextExpression(org.apache.jackrabbit.oak.spi.query.fulltext.FullTextExpression) List(java.util.List)

Example 7 with Cursor

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

the class PropertyIndexPlan method execute.

Cursor execute() {
    QueryLimits settings = filter.getQueryLimits();
    List<Iterable<String>> iterables = Lists.newArrayList();
    for (IndexStoreStrategy s : strategies) {
        iterables.add(s.query(filter, name, definition, values));
    }
    Cursor cursor = Cursors.newPathCursor(Iterables.concat(iterables), settings);
    if (depth > 1) {
        cursor = Cursors.newAncestorCursor(cursor, depth - 1, settings);
    }
    return cursor;
}
Also used : QueryLimits(org.apache.jackrabbit.oak.spi.query.QueryLimits) IndexStoreStrategy(org.apache.jackrabbit.oak.plugins.index.property.strategy.IndexStoreStrategy) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor)

Example 8 with Cursor

use of org.apache.jackrabbit.oak.spi.query.Cursor 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 9 with Cursor

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

the class LuceneIndexTest method testLuceneV1NonExistentProperty.

@Test
public void testLuceneV1NonExistentProperty() throws Exception {
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    NodeBuilder defn = newLuceneIndexDefinition(index, "lucene", ImmutableSet.of("String"));
    defn.setProperty(LuceneIndexConstants.COMPAT_MODE, IndexFormatVersion.V1.getVersion());
    NodeState before = builder.getNodeState();
    builder.setProperty("foo", "value-with-dash");
    NodeState after = builder.getNodeState();
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    tracker = new IndexTracker();
    tracker.update(indexed);
    AdvancedQueryIndex queryIndex = new LuceneIndex(tracker, null);
    FilterImpl filter = createFilter(NT_BASE);
    filter.restrictPath("/", Filter.PathRestriction.EXACT);
    filter.setFullTextConstraint(FullTextParser.parse("foo", "value-with*"));
    List<IndexPlan> plans = queryIndex.getPlans(filter, null, builder.getNodeState());
    Cursor cursor = queryIndex.query(plans.get(0), indexed);
    assertTrue(cursor.hasNext());
    assertEquals("/", cursor.next().getPath());
    assertFalse(cursor.hasNext());
    // Now perform a query against a field which does not exist
    FilterImpl filter2 = createFilter(NT_BASE);
    filter2.restrictPath("/", Filter.PathRestriction.EXACT);
    filter2.setFullTextConstraint(FullTextParser.parse("baz", "value-with*"));
    List<IndexPlan> plans2 = queryIndex.getPlans(filter2, null, builder.getNodeState());
    Cursor cursor2 = queryIndex.query(plans2.get(0), indexed);
    assertFalse(cursor2.hasNext());
}
Also used : AdvancedQueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) IndexPlan(org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor) Test(org.junit.Test)

Example 10 with Cursor

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

the class SolrQueryIndex method query.

@Override
public Cursor query(final IndexPlan plan, final NodeState root) {
    Cursor cursor;
    try {
        Filter filter = plan.getFilter();
        final Set<String> relPaths = filter.getFullTextConstraint() != null ? getRelativePaths(filter.getFullTextConstraint()) : Collections.<String>emptySet();
        final String parent = relPaths.size() == 0 ? "" : relPaths.iterator().next();
        final int parentDepth = getDepth(parent);
        String path = plan.getPlanName();
        OakSolrConfiguration configuration = getConfiguration(path, root);
        SolrClient solrServer = getServer(path, root);
        LMSEstimator estimator = getEstimator(path);
        AbstractIterator<SolrResultRow> iterator = getIterator(filter, plan, parent, parentDepth, configuration, solrServer, estimator);
        cursor = new SolrRowCursor(iterator, plan, filter.getQueryLimits(), estimator, solrServer, configuration);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return cursor;
}
Also used : OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) Filter(org.apache.jackrabbit.oak.spi.query.Filter) SolrClient(org.apache.solr.client.solrj.SolrClient)

Aggregations

Cursor (org.apache.jackrabbit.oak.spi.query.Cursor)18 Test (org.junit.Test)11 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)9 IndexPlan (org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan)9 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)9 AdvancedQueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex)7 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)7 QueryEngineSettings (org.apache.jackrabbit.oak.query.QueryEngineSettings)4 OakSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration)3 Function (com.google.common.base.Function)2 DefaultSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration)2 OakSolrConfigurationProvider (org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider)2 SolrServerProvider (org.apache.jackrabbit.oak.plugins.index.solr.server.SolrServerProvider)2 SelectorImpl (org.apache.jackrabbit.oak.query.ast.SelectorImpl)2 IndexRow (org.apache.jackrabbit.oak.spi.query.IndexRow)2 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)2 SolrClient (org.apache.solr.client.solrj.SolrClient)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1