Search in sources :

Example 6 with IndexUpdateProvider

use of org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider in project jackrabbit-oak by apache.

the class CrossMountReferenceValidatorTest method initializeHook.

@Before
public void initializeHook() {
    MountInfoProvider mip = Mounts.newBuilder().mount("foo", "/a").build();
    hook = new EditorHook(new CompositeEditorProvider(new IndexUpdateProvider(new CompositeIndexEditorProvider(new PropertyIndexEditorProvider().with(mip), new ReferenceEditorProvider().with(mip))), new CrossMountReferenceValidatorProvider().with(mip).withFailOnDetection(true)));
}
Also used : ReferenceEditorProvider(org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider) CompositeEditorProvider(org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider) IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) CompositeIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider) Before(org.junit.Before)

Example 7 with IndexUpdateProvider

use of org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider in project jackrabbit-oak by apache.

the class PropertyIndexTest method singleMount.

@Test
public void singleMount() throws Exception {
    NodeState root = INITIAL_CONTENT;
    // Add index definition
    NodeBuilder builder = root.builder();
    NodeBuilder index = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, false, ImmutableSet.of("foo"), null);
    index.setProperty("entryCount", -1);
    NodeState before = builder.getNodeState();
    // Add some content and process it through the property index hook
    builder.child("a").setProperty("foo", "abc");
    builder.child("b").child("x").setProperty("foo", "abc");
    builder.child("a").child("x").setProperty("foo", "abc");
    builder.child("m").child("n").setProperty("foo", "abc");
    builder.child("m").child("n").child("o").setProperty("foo", "abc");
    builder.child("m").setProperty("foo", "abc");
    NodeState after = builder.getNodeState();
    MountInfoProvider mip = Mounts.newBuilder().mount("foo", "/a", "/m/n").build();
    Mount fooMount = mip.getMountByName("foo");
    Mount defMount = mip.getDefaultMount();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(new PropertyIndexEditorProvider().with(mip)));
    NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
    FilterImpl f = createFilter(indexed, NT_BASE);
    // Query the index
    PropertyIndexLookup lookup = new PropertyIndexLookup(indexed, mip);
    assertEquals(ImmutableSet.of("a", "b/x", "a/x", "m", "m/n", "m/n/o"), find(lookup, "foo", "abc", f));
    assertEquals(ImmutableSet.of(), find(lookup, "foo", "ghi", f));
    assertTrue(getNode(indexed, "/oak:index/foo/:index").exists());
    // Separate node for mount
    assertTrue(getNode(indexed, "/oak:index/foo/" + getNodeForMount(fooMount)).exists());
    // Index entries for paths in foo mount should go to :oak:foo-index
    assertTrue(getNode(indexed, pathInIndex(fooMount, "/oak:index/foo", "/a", "abc")).exists());
    assertTrue(getNode(indexed, pathInIndex(fooMount, "/oak:index/foo", "/a/x", "abc")).exists());
    assertTrue(getNode(indexed, pathInIndex(fooMount, "/oak:index/foo", "/m/n", "abc")).exists());
    assertTrue(getNode(indexed, pathInIndex(fooMount, "/oak:index/foo", "/m/n/o", "abc")).exists());
    assertFalse(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/a", "abc")).exists());
    assertFalse(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/a/x", "abc")).exists());
    assertFalse(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/m/n", "abc")).exists());
    assertFalse(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/m/n/o", "abc")).exists());
    // All other index entries should go to :index
    assertTrue(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/b", "abc")).exists());
    assertTrue(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/b/x", "abc")).exists());
    assertTrue(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/m", "abc")).exists());
    assertFalse(getNode(indexed, pathInIndex(fooMount, "/oak:index/foo", "/b", "abc")).exists());
    assertFalse(getNode(indexed, pathInIndex(fooMount, "/oak:index/foo", "/b/x", "abc")).exists());
// System.out.println(NodeStateUtils.toString(getNode(indexed, "/oak:index/foo")));
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) Mount(org.apache.jackrabbit.oak.spi.mount.Mount) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) Test(org.junit.Test)

Example 8 with IndexUpdateProvider

use of org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider in project jackrabbit-oak by apache.

the class LuceneIndexEditor2Test method createHook.

private EditorHook createHook(LuceneIndexEditorContext context) {
    IndexEditorProvider provider = new IndexEditorProvider() {

        @CheckForNull
        @Override
        public Editor getIndexEditor(@Nonnull String type, @Nonnull NodeBuilder definition, @Nonnull NodeState root, @Nonnull IndexUpdateCallback callback) throws CommitFailedException {
            if ("lucene".equals(type)) {
                return new LuceneIndexEditor(context);
            }
            return null;
        }
    };
    String async = context.isAsyncIndexing() ? "async" : null;
    IndexUpdateProvider updateProvider = new IndexUpdateProvider(provider, async, false);
    return new EditorHook(updateProvider);
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Nonnull(javax.annotation.Nonnull) IndexUpdateCallback(org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) IndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 9 with IndexUpdateProvider

use of org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider in project jackrabbit-oak by apache.

the class LuceneIndexPropertyQueryTest method simplePropertyIndex.

@Test
public void simplePropertyIndex() throws Exception {
    defnb.noAsync();
    defnb.indexRule("nt:base").property("foo").propertyIndex();
    assertEquals(0, Iterables.size(query.getIndexedPaths("foo", "bar")));
    NodeState before = builder.getNodeState();
    builder.child("a").setProperty("foo", "bar");
    builder.child("b").setProperty("foo", "bar");
    NodeState after = builder.getNodeState();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(new LuceneIndexEditorProvider()));
    NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
    tracker.update(indexed);
    assertThat(query.getIndexedPaths("foo", "bar"), containsInAnyOrder("/a", "/b"));
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) LuceneIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) Test(org.junit.Test)

Example 10 with IndexUpdateProvider

use of org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider in project jackrabbit-oak by apache.

the class CompositeNodeStoreTest method propertyIndex.

@Test
public void propertyIndex() throws Exception {
    NodeBuilder globalBuilder = globalStore.getRoot().builder();
    createIndexDefinition(globalBuilder.child(INDEX_DEFINITIONS_NAME), "foo", true, false, ImmutableSet.of("foo"), null);
    EditorHook hook = new EditorHook(new IndexUpdateProvider(new PropertyIndexEditorProvider().with(mip)));
    globalStore.merge(globalBuilder, hook, CommitInfo.EMPTY);
    NodeBuilder builder = store.getRoot().builder();
    builder.child("content").setProperty("foo", "bar");
    store.merge(builder, hook, CommitInfo.EMPTY);
    builder = store.getRoot().builder();
    builder.child("content").removeProperty("foo");
    store.merge(builder, hook, CommitInfo.EMPTY);
}
Also used : IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

IndexUpdateProvider (org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider)24 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)24 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)14 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)14 Test (org.junit.Test)13 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)6 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)6 Before (org.junit.Before)6 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)4 CompositeIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider)3 IndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider)3 LuceneIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider)3 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)2 CommitHook (org.apache.jackrabbit.oak.spi.commit.CommitHook)2 CompositeHook (org.apache.jackrabbit.oak.spi.commit.CompositeHook)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayList (java.util.ArrayList)1 Executor (java.util.concurrent.Executor)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1