Search in sources :

Example 11 with FilterImpl

use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.

the class ReferenceIndexTest method createFilter.

@SuppressWarnings("Duplicates")
private static FilterImpl createFilter(NodeState root, 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());
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeTypeInfo(org.apache.jackrabbit.oak.query.ast.NodeTypeInfo) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider) NodeTypeInfoProvider(org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)

Example 12 with FilterImpl

use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.

the class PropertyIndexTest method testPathMismatch.

@Test
public void testPathMismatch() 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));
    index.setProperty(createProperty(PROP_EXCLUDED_PATHS, of("/test/a/b"), 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("a").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("/test2", Filter.PathRestriction.ALL_CHILDREN);
    PropertyIndexPlan plan = new PropertyIndexPlan("plan", root, index.getNodeState(), f);
    assertTrue(Double.POSITIVE_INFINITY == plan.getCost());
}
Also used : EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 13 with FilterImpl

use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.

the class IndexPlannerTest method pureNodeTypeWithEvaluatePathRestrictionEnabled.

@Test
public void pureNodeTypeWithEvaluatePathRestrictionEnabled() throws Exception {
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    NodeBuilder defn = newLuceneIndexDefinition(index, "lucene", of(TYPENAME_STRING));
    defn.setProperty(LuceneIndexConstants.EVALUATE_PATH_RESTRICTION, true);
    TestUtil.useV2(defn);
    FilterImpl filter = createFilter("nt:file");
    filter.restrictPath("/", Filter.PathRestriction.ALL_CHILDREN);
    IndexNode node = createIndexNode(new IndexDefinition(root, defn.getNodeState(), "/foo"));
    IndexPlanner planner = new IndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
    // /jcr:root//element(*, nt:file)
    //For queries like above Fulltext index should not return a plan
    assertNull(planner.getPlan());
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 14 with FilterImpl

use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.

the class IndexPlannerTest method nullPropertyCheck2.

@Test
public void nullPropertyCheck2() throws Exception {
    root = registerTestNodeType(builder).getNodeState();
    NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo"), "async");
    NodeBuilder rules = defn.child(INDEX_RULES);
    TestUtil.child(rules, "oak:TestNode/properties/prop2").setProperty(LuceneIndexConstants.PROP_NAME, "foo").setProperty(LuceneIndexConstants.PROP_NULL_CHECK_ENABLED, true).setProperty(LuceneIndexConstants.PROP_PROPERTY_INDEX, true);
    IndexDefinition idxDefn = new IndexDefinition(root, builder.getNodeState().getChildNode("test"), "/foo");
    IndexNode node = createIndexNode(idxDefn);
    FilterImpl filter = createFilter(NT_TEST);
    filter.restrictProperty("foo", Operator.EQUAL, null);
    IndexPlanner planner = new IndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
    QueryIndex.IndexPlan plan = planner.getPlan();
    assertNotNull("For null checks plan should be returned with nullCheckEnabled", plan);
    IndexPlanner.PlanResult pr = (IndexPlanner.PlanResult) plan.getAttribute(LucenePropertyIndex.ATTR_PLAN_RESULT);
    assertNotNull(pr.getPropDefn(filter.getPropertyRestriction("foo")));
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 15 with FilterImpl

use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.

the class IndexPlannerTest method propertyIndexCost.

@Test
public void propertyIndexCost() throws Exception {
    NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo"), "async");
    long numofDocs = IndexDefinition.DEFAULT_ENTRY_COUNT + 1000;
    IndexDefinition idxDefn = new IndexDefinition(root, defn.getNodeState(), "/foo");
    IndexNode node = createIndexNode(idxDefn, numofDocs);
    FilterImpl filter = createFilter("nt:base");
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
    IndexPlanner planner = new IndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
    QueryIndex.IndexPlan plan = planner.getPlan();
    //For propertyIndex if entry count (default to IndexDefinition.DEFAULT_ENTRY_COUNT) is
    //less than numOfDoc then that would be preferred
    assertEquals(idxDefn.getEntryCount(), plan.getEstimatedEntryCount());
    assertEquals(1.0, plan.getCostPerExecution(), 0);
    assertEquals(1.0, plan.getCostPerEntry(), 0);
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)98 Test (org.junit.Test)81 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)74 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)39 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)28 SelectorImpl (org.apache.jackrabbit.oak.query.ast.SelectorImpl)27 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)26 QueryEngineSettings (org.apache.jackrabbit.oak.query.QueryEngineSettings)26 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)25 AdvancedQueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex)15 LinkedList (java.util.LinkedList)14 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)14 NodeStateNodeTypeInfoProvider (org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)10 NodeTypeInfo (org.apache.jackrabbit.oak.query.ast.NodeTypeInfo)10 NodeTypeInfoProvider (org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider)10 Cursor (org.apache.jackrabbit.oak.spi.query.Cursor)9 IndexPlan (org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan)8 IndexUpdateProvider (org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider)4 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)4 DefaultSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration)3