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)));
}
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")));
}
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);
}
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"));
}
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);
}
Aggregations