use of org.apache.jackrabbit.oak.spi.query.Cursor in project jackrabbit-oak by apache.
the class ReferenceIndexTest method assertFilter.
private static List<String> assertFilter(Filter filter, QueryIndex queryIndex, NodeState indexed, List<String> expected) {
Cursor cursor = queryIndex.query(filter, 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;
}
use of org.apache.jackrabbit.oak.spi.query.Cursor 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.spi.query.Cursor 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.spi.query.Cursor 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;
}
use of org.apache.jackrabbit.oak.spi.query.Cursor 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;
}
Aggregations