Search in sources :

Example 1 with Cursor

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

the class ReferenceIndexTest method assertFilter.

private static List<String> assertFilter(Filter filter, QueryIndex queryIndex, NodeState indexed, List<String> expected) {
    Cursor cursor = queryIndex.query(filter, indexed);
    List<String> paths = newArrayList();
    while (cursor.hasNext()) {
        paths.add(cursor.next().getPath());
    }
    Collections.sort(paths);
    for (String p : expected) {
        assertTrue("Expected path " + p + " not found", paths.contains(p));
    }
    assertEquals("Result set size is different \nExpected: " + expected + "\nActual: " + paths, expected.size(), paths.size());
    return paths;
}
Also used : Cursor(org.apache.jackrabbit.oak.spi.query.Cursor)

Example 2 with Cursor

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

the class LuceneIndexTest method assertQuery.

private void assertQuery(IndexTracker tracker, NodeState indexed, String key, String value) {
    AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker);
    FilterImpl filter = createFilter(NT_BASE);
    filter.restrictPath("/", Filter.PathRestriction.EXACT);
    filter.restrictProperty(key, Operator.EQUAL, PropertyValues.newString(value));
    List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed);
    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) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) IndexPlan(org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor)

Example 3 with Cursor

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

the class LuceneIndexTest method testLucene3.

@Test
public void testLucene3() throws Exception {
    NodeBuilder index = newLucenePropertyIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "lucene", ImmutableSet.of("foo"), null);
    NodeBuilder rules = index.child(INDEX_RULES);
    NodeBuilder fooProp = rules.child("nt:base").child(LuceneIndexConstants.PROP_NODE).child("foo");
    fooProp.setProperty(LuceneIndexConstants.PROP_PROPERTY_INDEX, true);
    fooProp.setProperty(LuceneIndexConstants.PROP_INCLUDED_TYPE, PropertyType.TYPENAME_STRING);
    NodeState before = builder.getNodeState();
    builder.setProperty("foo", "bar");
    builder.child("a").setProperty("foo", "bar");
    builder.child("a").child("b").setProperty("foo", "bar", Type.NAME);
    builder.child("a").child("b").child("c").setProperty("foo", "bar", Type.NAME);
    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", 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 4 with Cursor

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

the class LuceneIndexTest method assertFilter.

private static List<String> assertFilter(Filter filter, AdvancedQueryIndex queryIndex, NodeState indexed, List<String> expected) {
    List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed);
    Cursor cursor = queryIndex.query(plans.get(0), indexed);
    List<String> paths = newArrayList();
    while (cursor.hasNext()) {
        paths.add(cursor.next().getPath());
    }
    Collections.sort(paths);
    for (String p : expected) {
        assertTrue("Expected path " + p + " not found", paths.contains(p));
    }
    assertEquals("Result set size is different \nExpected: " + expected + "\nActual: " + paths, expected.size(), paths.size());
    return paths;
}
Also used : IndexPlan(org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor)

Example 5 with Cursor

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

the class LuceneIndexTest method assertFilter.

private static List<String> assertFilter(Filter filter, AdvancedQueryIndex queryIndex, NodeState indexed, List<String> expected, boolean ordered) {
    if (!ordered) {
        return assertFilter(filter, queryIndex, indexed, expected);
    }
    List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed);
    Cursor cursor = queryIndex.query(plans.get(0), indexed);
    List<String> paths = newArrayList();
    while (cursor.hasNext()) {
        paths.add(cursor.next().getPath());
    }
    for (String p : expected) {
        assertTrue("Expected path " + p + " not found", paths.contains(p));
    }
    assertEquals("Result set size is different", expected.size(), paths.size());
    return paths;
}
Also used : IndexPlan(org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor)

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