use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class LuceneIndexTest method testRelativePropertyNonExistence.
@Test
public void testRelativePropertyNonExistence() throws Exception {
root = TestUtil.registerTestNodeType(builder).getNodeState();
NodeBuilder index = newLucenePropertyIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "lucene", ImmutableSet.of("foo"), null);
NodeBuilder rules = index.child(INDEX_RULES);
NodeBuilder propNode = rules.child(NT_TEST).child(LuceneIndexConstants.PROP_NODE);
propNode.child("bar").setProperty(LuceneIndexConstants.PROP_NAME, "jcr:content/bar").setProperty(LuceneIndexConstants.PROP_PROPERTY_INDEX, true).setProperty(LuceneIndexConstants.PROP_NULL_CHECK_ENABLED, true);
NodeState before = builder.getNodeState();
NodeBuilder a1 = createNodeWithType(builder, "a1", NT_TEST);
a1.child("jcr:content").setProperty("bar", "foo");
NodeBuilder b1 = createNodeWithType(builder, "b1", NT_TEST);
b1.child("jcr:content");
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_TEST);
filter.restrictProperty("jcr:content/bar", Operator.EQUAL, null);
assertFilter(filter, queryIndex, indexed, ImmutableList.of("/b1"));
builder.child("b1").child("jcr:content").setProperty("bar", "foo");
after = builder.getNodeState();
indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
tracker.update(indexed);
filter = createFilter(NT_TEST);
filter.restrictProperty("jcr:content/bar", Operator.EQUAL, null);
assertFilter(filter, queryIndex, indexed, Collections.<String>emptyList());
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl 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());
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class LuceneIndexTest method testPathRestrictions.
@Test
public void testPathRestrictions() throws Exception {
NodeBuilder idx = newLucenePropertyIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "lucene", ImmutableSet.of("foo"), null);
idx.setProperty(LuceneIndexConstants.EVALUATE_PATH_RESTRICTION, true);
NodeState before = builder.getNodeState();
builder.setProperty("foo", "bar");
builder.child("a").setProperty("foo", "bar");
builder.child("a1").setProperty("foo", "bar");
builder.child("a").child("b").setProperty("foo", "bar");
builder.child("a").child("b").child("c").setProperty("foo", "bar");
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 = createTestFilter();
filter.restrictPath("/", Filter.PathRestriction.EXACT);
assertFilter(filter, queryIndex, indexed, ImmutableList.of("/"));
filter = createTestFilter();
filter.restrictPath("/", Filter.PathRestriction.DIRECT_CHILDREN);
assertFilter(filter, queryIndex, indexed, ImmutableList.of("/a", "/a1"));
filter = createTestFilter();
filter.restrictPath("/a", Filter.PathRestriction.DIRECT_CHILDREN);
assertFilter(filter, queryIndex, indexed, ImmutableList.of("/a/b"));
filter = createTestFilter();
filter.restrictPath("/a", Filter.PathRestriction.ALL_CHILDREN);
assertFilter(filter, queryIndex, indexed, ImmutableList.of("/a/b", "/a/b/c"));
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl 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());
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class LuceneIndexLookupTest method collectPathOnRootNode.
@Test
public void collectPathOnRootNode() throws Exception {
NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
newLuceneIndexDefinition(index, "l1", of(TYPENAME_STRING));
newLuceneIndexDefinition(index, "l2", of(TYPENAME_STRING));
LuceneIndexLookup lookup = new LuceneIndexLookup(builder.getNodeState());
FilterImpl f = FilterImpl.newTestInstance();
f.restrictPath("/", Filter.PathRestriction.EXACT);
assertEquals(of("/oak:index/l1", "/oak:index/l2"), lookup.collectIndexNodePaths(f));
}
Aggregations