Search in sources :

Example 11 with Cursor

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

the class LuceneIndexTest method testLucene2.

@Test
public void testLucene2() throws Exception {
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    newLucenePropertyIndexDefinition(index, "lucene", ImmutableSet.of("foo"), null);
    NodeState before = builder.getNodeState();
    builder.setProperty("foo", "bar");
    builder.child("a").setProperty("foo", "bar");
    builder.child("a").child("b").setProperty("foo", "bar");
    builder.child("a").child("b").child("c").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.restrictPath("/", Filter.PathRestriction.EXACT);
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
    List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed);
    Cursor cursor = queryIndex.query(plans.get(0), indexed);
    assertTrue(cursor.hasNext());
    assertEquals("/a/b/c", cursor.next().getPath());
    assertEquals("/a/b", cursor.next().getPath());
    assertEquals("/a", cursor.next().getPath());
    assertEquals("/", cursor.next().getPath());
    assertFalse(cursor.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 12 with Cursor

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

the class LuceneIndexTest method testLucene.

@Test
public void testLucene() throws Exception {
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    newLucenePropertyIndexDefinition(index, "lucene", ImmutableSet.of("foo"), null);
    NodeState before = builder.getNodeState();
    builder.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.restrictPath("/", Filter.PathRestriction.EXACT);
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
    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());
}
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 13 with Cursor

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

the class SolrQueryIndexTest method testSize.

@Test
public void testSize() 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')";
    SolrServerProvider solrServerProvider = mock(SolrServerProvider.class);
    OakSolrConfigurationProvider configurationProvider = mock(OakSolrConfigurationProvider.class);
    OakSolrConfiguration configuration = new DefaultSolrConfiguration() {

        @Override
        public boolean useForPropertyRestrictions() {
            return true;
        }
    };
    when(configurationProvider.getConfiguration()).thenReturn(configuration);
    SolrQueryIndex solrQueryIndex = new SolrQueryIndex(null, configurationProvider, solrServerProvider);
    FilterImpl filter = new FilterImpl(selector, sqlQuery, new QueryEngineSettings());
    List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, null, root);
    for (QueryIndex.IndexPlan p : plans) {
        Cursor cursor = solrQueryIndex.query(p, root);
        assertNotNull(cursor);
        long sizeExact = cursor.getSize(Result.SizePrecision.EXACT, 100000);
        long sizeApprox = cursor.getSize(Result.SizePrecision.APPROXIMATION, 100000);
        long sizeFastApprox = cursor.getSize(Result.SizePrecision.FAST_APPROXIMATION, 100000);
        assertTrue(Math.abs(sizeExact - sizeApprox) < 10);
        assertTrue(Math.abs(sizeExact - sizeFastApprox) > 10000);
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) 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) 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) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) Test(org.junit.Test)

Example 14 with Cursor

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

Example 15 with Cursor

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

the class TraversingIndexTest method traverse.

@Test
public void traverse() throws Exception {
    NodeBuilder builder = EMPTY_NODE.builder();
    NodeBuilder parents = builder.child("parents");
    parents.child("p0").setProperty("id", 0);
    parents.child("p1").setProperty("id", 1);
    parents.child("p2").setProperty("id", 2);
    NodeBuilder children = builder.child("children");
    children.child("c1").setProperty("p", "1");
    children.child("c2").setProperty("p", "1");
    children.child("c3").setProperty("p", "2");
    children.child("c4").setProperty("p", "3");
    NodeState root = builder.getNodeState();
    TraversingIndex t = new TraversingIndex();
    FilterImpl f = FilterImpl.newTestInstance();
    f.setPath("/");
    Cursor c = t.query(f, root);
    List<String> paths = new ArrayList<String>();
    while (c.hasNext()) {
        paths.add(c.next().getPath());
    }
    Collections.sort(paths);
    assertEquals(Arrays.asList("/", "/children", "/children/c1", "/children/c2", "/children/c3", "/children/c4", "/parents", "/parents/p0", "/parents/p1", "/parents/p2"), paths);
    assertFalse(c.hasNext());
    // endure it stays false
    assertFalse(c.hasNext());
    f.setPath("/nowhere");
    c = t.query(f, root);
    assertFalse(c.hasNext());
    // endure it stays false
    assertFalse(c.hasNext());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ArrayList(java.util.ArrayList) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor) Test(org.junit.Test)

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