use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class LuceneIndexTest method testLucene2.
@Test
public void testLucene2() throws Exception {
NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
newLucenePropertyIndexDefinition(index, "lucene", ImmutableSet.of("foo"), null);
NodeState before = builder.getNodeState();
builder.setProperty("foo", "bar");
builder.child("a").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 = 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/b/c", cursor.next().getPath());
assertEquals("/a/b", cursor.next().getPath());
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 LuceneIndexTest method createFilter.
private FilterImpl createFilter(String nodeTypeName) {
NodeTypeInfoProvider nodeTypes = new NodeStateNodeTypeInfoProvider(root);
NodeTypeInfo type = nodeTypes.getNodeTypeInfo(nodeTypeName);
SelectorImpl selector = new SelectorImpl(type, nodeTypeName);
return new FilterImpl(selector, "SELECT * FROM [" + nodeTypeName + "]", new QueryEngineSettings());
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class LuceneIndexLookupTest method collectPathOnSubNode.
@Test
public void collectPathOnSubNode() throws Exception {
NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
newLuceneIndexDefinition(index, "l1", of(TYPENAME_STRING));
index = builder.child("a").child(INDEX_DEFINITIONS_NAME);
newLuceneIndexDefinition(index, "l2", of(TYPENAME_STRING));
index = builder.child("a").child("b").child(INDEX_DEFINITIONS_NAME);
newLuceneIndexDefinition(index, "l3", of(TYPENAME_STRING));
LuceneIndexLookup lookup = new LuceneIndexLookup(builder.getNodeState());
FilterImpl f = FilterImpl.newTestInstance();
f.restrictPath("/a", Filter.PathRestriction.EXACT);
assertEquals(of("/oak:index/l1", "/a/oak:index/l2"), lookup.collectIndexNodePaths(f));
f.restrictPath("/a/b", Filter.PathRestriction.EXACT);
assertEquals(of("/oak:index/l1", "/a/oak:index/l2", "/a/b/oak:index/l3"), lookup.collectIndexNodePaths(f));
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class IndexPlannerTest method noPlanForNodeTypeQueryAndOnlyAnalyzedProperties.
@Test
public void noPlanForNodeTypeQueryAndOnlyAnalyzedProperties() throws Exception {
NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo"), "async");
defn.setProperty(LuceneIndexConstants.EVALUATE_PATH_RESTRICTION, true);
defn.setProperty(IndexConstants.DECLARING_NODE_TYPES, of("nt:file"), NAMES);
defn = IndexDefinition.updateDefinition(defn.getNodeState().builder());
NodeBuilder foob = getNode(defn, "indexRules/nt:file/properties/foo");
foob.setProperty(LuceneIndexConstants.PROP_ANALYZED, true);
IndexNode node = createIndexNode(new IndexDefinition(root, defn.getNodeState(), "/foo"));
FilterImpl filter = createFilter("nt:file");
filter.restrictPath("/foo", Filter.PathRestriction.ALL_CHILDREN);
IndexPlanner planner = new IndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
QueryIndex.IndexPlan plan = planner.getPlan();
assertNull(plan);
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class IndexPlannerTest method fulltextIndexAndNodeTypeRestriction.
@Test
public void fulltextIndexAndNodeTypeRestriction() throws Exception {
NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo"), "async");
defn.setProperty(LuceneIndexConstants.EVALUATE_PATH_RESTRICTION, true);
defn.setProperty(IndexConstants.DECLARING_NODE_TYPES, of("nt:file"), NAMES);
defn = IndexDefinition.updateDefinition(defn.getNodeState().builder());
NodeBuilder foob = getNode(defn, "indexRules/nt:file/properties/foo");
foob.setProperty(LuceneIndexConstants.PROP_NODE_SCOPE_INDEX, true);
IndexNode node = createIndexNode(new IndexDefinition(root, defn.getNodeState(), "/foo"));
FilterImpl filter = createFilter("nt:file");
IndexPlanner planner = new IndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
//For case when a full text property is present then path restriction can be
//evaluated
assertNotNull(planner.getPlan());
}
Aggregations