Search in sources :

Example 11 with IndexPlan

use of org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan 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 12 with IndexPlan

use of org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan 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 13 with IndexPlan

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

the class LuceneIndexTest method indexNodeLockHandling.

@Test
public void indexNodeLockHandling() throws Exception {
    tracker = new IndexTracker();
    //Create 2 indexes. /oak:index/lucene and /test/oak:index/lucene
    //The way LuceneIndexLookup works is. It collect child first and then
    //parent
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    NodeBuilder nb = newLuceneIndexDefinitionV2(index, "lucene", of(TYPENAME_STRING));
    nb.setProperty(LuceneIndexConstants.FULL_TEXT_ENABLED, false);
    nb.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, of("foo"), STRINGS));
    index = builder.child("test").child(INDEX_DEFINITIONS_NAME);
    NodeBuilder nb2 = newLuceneIndexDefinitionV2(index, "lucene", of(TYPENAME_STRING));
    nb2.setProperty(LuceneIndexConstants.FULL_TEXT_ENABLED, false);
    nb2.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, of("foo"), STRINGS));
    NodeState before = builder.getNodeState();
    builder.child("test").setProperty("foo", "fox is jumping");
    NodeState after = builder.getNodeState();
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    tracker.update(indexed);
    QueryIndex.AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker);
    FilterImpl filter = createFilter(NT_BASE);
    filter.restrictPath("/test", Filter.PathRestriction.EXACT);
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
    builder = indexed.builder();
    NodeBuilder dir = builder.child("oak:index").child("lucene").child(":data");
    //Mutate the blob to fail on access i.e. create corrupt index
    List<Blob> blobs = new ArrayList<Blob>();
    Blob b = dir.child("segments_1").getProperty(JCR_DATA).getValue(Type.BINARY, 0);
    FailingBlob fb = new FailingBlob(IOUtils.toByteArray(b.getNewStream()));
    blobs.add(fb);
    dir.child("segments_1").setProperty(JCR_DATA, blobs, BINARIES);
    indexed = builder.getNodeState();
    tracker.update(indexed);
    List<IndexPlan> list = queryIndex.getPlans(filter, null, indexed);
    assertEquals("There must be only one plan", 1, list.size());
    IndexPlan plan = list.get(0);
    assertEquals("Didn't get the expected plan", "/test/oak:index/lucene", plan.getPlanName());
}
Also used : Blob(org.apache.jackrabbit.oak.api.Blob) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) AdvancedQueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) IndexPlan(org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) AdvancedQueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex) Test(org.junit.Test)

Example 14 with IndexPlan

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

Example 15 with IndexPlan

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

the class LuceneIndexTest method testCursorStability.

@Test
public void testCursorStability() 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);
    //1. Create 60 nodes
    NodeState before = builder.getNodeState();
    int noOfDocs = LucenePropertyIndex.LUCENE_QUERY_BATCH_SIZE + 10;
    for (int i = 0; i < noOfDocs; i++) {
        builder.child("a" + i).setProperty("foo", (long) i);
    }
    NodeState after = builder.getNodeState();
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    tracker = new IndexTracker();
    tracker.update(indexed);
    //Perform query and get hold of cursor
    AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker);
    FilterImpl filter = createFilter(NT_BASE);
    filter.restrictProperty("foo", Operator.GREATER_OR_EQUAL, PropertyValues.newLong(0L));
    List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed);
    Cursor cursor = queryIndex.query(plans.get(0), indexed);
    //Trigger loading of cursor
    assertTrue(cursor.hasNext());
    //Now before traversing further go ahead and delete all but 10 nodes
    before = indexed;
    builder = indexed.builder();
    for (int i = 0; i < noOfDocs - 10; i++) {
        builder.child("a" + i).remove();
    }
    after = builder.getNodeState();
    indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    builder = indexed.builder();
    //Ensure that Lucene actually removes deleted docs
    NodeBuilder idx = builder.child(INDEX_DEFINITIONS_NAME).child("lucene");
    purgeDeletedDocs(idx, new IndexDefinition(root, idx.getNodeState(), "/foo"));
    int numDeletes = getDeletedDocCount(idx, new IndexDefinition(root, idx.getNodeState(), "/foo"));
    Assert.assertEquals(0, numDeletes);
    //Update the IndexSearcher
    tracker.update(builder.getNodeState());
    //its hard to get correct size estimate as post deletion cursor
    // would have already picked up 50 docs which would not be considered
    //deleted by QE for the revision at which query was triggered
    //So just checking for >
    List<String> resultPaths = Lists.newArrayList();
    while (cursor.hasNext()) {
        resultPaths.add(cursor.next().getPath());
    }
    Set<String> uniquePaths = Sets.newHashSet(resultPaths);
    assertEquals(resultPaths.size(), uniquePaths.size());
    assertTrue(!uniquePaths.isEmpty());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) 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) LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) IndexPlan(org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan) Test(org.junit.Test)

Aggregations

IndexPlan (org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan)20 AdvancedQueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex)12 Test (org.junit.Test)10 Cursor (org.apache.jackrabbit.oak.spi.query.Cursor)9 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)8 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)7 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)7 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)5 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 ArrayList (java.util.ArrayList)2 OrderEntry (org.apache.jackrabbit.oak.spi.query.QueryIndex.OrderEntry)2 Function (com.google.common.base.Function)1 Blob (org.apache.jackrabbit.oak.api.Blob)1 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)1 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)1 ArrayBasedBlob (org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob)1 QueryEngineSettings (org.apache.jackrabbit.oak.query.QueryEngineSettings)1 DynamicOperandImpl (org.apache.jackrabbit.oak.query.ast.DynamicOperandImpl)1 OrderingImpl (org.apache.jackrabbit.oak.query.ast.OrderingImpl)1 PropertyValueImpl (org.apache.jackrabbit.oak.query.ast.PropertyValueImpl)1