use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class PropertyIndexTest method testPathAwarePropertyLookup.
@Test
public void testPathAwarePropertyLookup() throws Exception {
NodeState root = INITIAL_CONTENT;
// Add index definition
NodeBuilder builder = root.builder();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, false, ImmutableSet.of("foo"), null);
NodeState before = builder.getNodeState();
// Add some content and process it through the property index hook
builder.child("a").setProperty("foo", "abc");
builder.child("b").setProperty("foo", "abc");
NodeState after = builder.getNodeState();
NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
FilterImpl f = createFilter(indexed, NT_BASE);
f.restrictPath("/a", Filter.PathRestriction.ALL_CHILDREN);
// Query the index
PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
assertEquals(ImmutableSet.of("a"), find(lookup, "foo", "abc", f));
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class PropertyIndexTest method testPathInclude.
@Test
public void testPathInclude() 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(createProperty(PROP_INCLUDED_PATHS, of("/test/a"), Type.STRINGS));
NodeState before = builder.getNodeState();
// Add some content and process it through the property index hook
builder.child("test").child("a").setProperty("foo", "abc");
builder.child("test").child("b").setProperty("foo", "abc");
NodeState after = builder.getNodeState();
NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
FilterImpl f = createFilter(indexed, NT_BASE);
// Query the index
PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
assertEquals(ImmutableSet.of("test/a"), find(lookup, "foo", "abc", f));
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class PropertyIndexTest method getResultSize.
private int getResultSize(NodeState indexed, String name, String value) {
FilterImpl f = createFilter(indexed, NT_BASE);
// Query the index
PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
Iterable<String> result = lookup.query(f, name, PropertyValues.newString(value));
return Iterables.size(result);
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class PropertyIndexTest method testCustomConfigNodeTypeFallback.
/**
* @see <a href="https://issues.apache.org/jira/browse/OAK-666">OAK-666:
* Property2Index: node type is used when indexing, but ignored when
* querying</a>
*/
@Test
public void testCustomConfigNodeTypeFallback() throws Exception {
NodeState root = EMPTY_NODE;
// Add index definitions
NodeBuilder builder = root.builder();
NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
createIndexDefinition(index, "fooIndex", true, false, ImmutableSet.of("foo", "extrafoo"), null);
createIndexDefinition(index, "fooIndexFile", true, false, ImmutableSet.of("foo"), ImmutableSet.of(NT_FILE));
NodeState before = builder.getNodeState();
// Add some content and process it through the property index hook
builder.child("a").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "abc");
builder.child("b").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", Arrays.asList("abc", "def"), Type.STRINGS);
NodeState after = builder.getNodeState();
// Add an index
NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
FilterImpl f = createFilter(after, NT_UNSTRUCTURED);
// Query the index
PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
assertEquals(ImmutableSet.of("a", "b"), find(lookup, "foo", "abc", f));
assertEquals(ImmutableSet.of("b"), find(lookup, "foo", "def", f));
assertEquals(ImmutableSet.of(), find(lookup, "foo", "ghi", f));
try {
assertEquals(ImmutableSet.of(), find(lookup, "pqr", "foo", f));
fail();
} catch (IllegalArgumentException e) {
// expected: no index for "pqr"
}
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl 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")));
}
Aggregations