Package org.apache.jackrabbit.oak.spi.query

Examples of org.apache.jackrabbit.oak.spi.query.QueryIndex$AdvancedQueryIndex


        child2.addChild("descendant");
        Tree someothernode = tree.addChild("someothernode");
        someothernode.addChild("someotherchild");
        root.commit();

        QueryIndex index = new SolrQueryIndex("solr", server, configuration);
        FilterImpl filter = new FilterImpl(mock(SelectorImpl.class), "", new QueryEngineSettings());
        filter.restrictPath("/somenode", Filter.PathRestriction.DIRECT_CHILDREN);
        Cursor cursor = index.query(filter, store.getRoot());
        assertCursor(cursor, "/somenode/child1", "/somenode/child2");
    }
View Full Code Here


        child2.addChild("descendant");
        Tree someothernode = tree.addChild("someothernode");
        someothernode.addChild("someotherchild");
        root.commit();

        QueryIndex index = new SolrQueryIndex("solr", server, configuration);
        FilterImpl filter = new FilterImpl(mock(SelectorImpl.class), "", new QueryEngineSettings());
        filter.restrictPath("/somenode", Filter.PathRestriction.ALL_CHILDREN);
        Cursor cursor = index.query(filter, store.getRoot());
        assertCursor(
                cursor, "/somenode", "/somenode/child1",
                "/somenode/child2", "/somenode/child2/descendant");
    }
View Full Code Here

        tree.addChild("somenode").setProperty("foo", "bar");
        tree.addChild("someothernode").setProperty("foo", "bard");
        tree.addChild("anotherone").setProperty("foo", "a fool's bar");
        root.commit();

        QueryIndex index = new SolrQueryIndex("solr", server, configuration);
        FilterImpl filter = new FilterImpl(mock(SelectorImpl.class), "", new QueryEngineSettings());
        filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
        Cursor cursor = index.query(filter, store.getRoot());
        assertCursor(cursor, "/somenode", "/anotherone");
    }
View Full Code Here

        tree.addChild("asamplenode").setProperty("jcr:primaryType", "nt:unstructured");
        tree.addChild("afoldernode").setProperty("jcr:primaryType", "nt:folder");
        tree.addChild("anothersamplenode").setProperty("jcr:primaryType", "nt:unstructured");
        root.commit();

        QueryIndex index = new SolrQueryIndex("solr", server, configuration);
        SelectorImpl selector = mock(SelectorImpl.class);
        Set<String> primaryTypes = new HashSet<String>();
        primaryTypes.add("nt:folder");
        when(selector.getPrimaryTypes()).thenReturn(primaryTypes);
        FilterImpl filter = new FilterImpl(selector, "select * from [nt:folder]", new QueryEngineSettings());
        Cursor cursor = index.query(filter, store.getRoot());
        assertCursor(cursor, "/afoldernode");
    }
View Full Code Here

        }
    }

    @Override
    public void execute(NodeState rootState) {
        QueryIndex index = plan.getIndex();
        if (index == null) {
            cursor = Cursors.newPathCursor(new ArrayList<String>(), query.getSettings());
            return;
        }
        IndexPlan p = plan.getIndexPlan();
        if (p != null) {
            p.setFilter(createFilter(false));
            AdvancedQueryIndex adv = (AdvancedQueryIndex) index;
            cursor = adv.query(p, rootState);
        } else {
            cursor = index.query(createFilter(false), rootState);
        }
    }
View Full Code Here

    }

    private SelectorExecutionPlan getBestSelectorExecutionPlan(
            NodeState rootState, FilterImpl filter,
            QueryIndexProvider indexProvider, boolean traversalEnabled) {
        QueryIndex bestIndex = null;
        if (LOG.isDebugEnabled()) {
            LOG.debug("cost using filter " + filter);
        }

        double bestCost = Double.POSITIVE_INFINITY;
        IndexPlan bestPlan = null;
        for (QueryIndex index : indexProvider.getQueryIndexes(rootState)) {
            double cost;
            IndexPlan indexPlan = null;
            if (index instanceof AdvancedQueryIndex) {
                AdvancedQueryIndex advIndex = (AdvancedQueryIndex) index;
                List<OrderEntry> sortOrder = null;
                if (orderings != null) {
                    sortOrder = new ArrayList<OrderEntry>();
                    for (OrderingImpl o : orderings) {
                        DynamicOperandImpl op = o.getOperand();
                        if (!(op instanceof PropertyValueImpl)) {
                            // ordered by a function: currently not supported
                            break;
                        }
                        PropertyValueImpl p = (PropertyValueImpl) op;
                        SelectorImpl s = p.getSelectors().iterator().next();
                        if (!s.equals(filter.getSelector())) {
                            // ordered by a different selector
                            continue;
                        }
                        OrderEntry e = new OrderEntry(
                                p.getPropertyName(),
                                Type.UNDEFINED,
                                o.isDescending() ?
                                OrderEntry.Order.DESCENDING : OrderEntry.Order.ASCENDING);
                        sortOrder.add(e);
                    }
                    if (sortOrder.size() == 0) {
                        sortOrder = null;
                    }
                }
                long maxEntryCount = limit;
                if (offset > 0) {
                    if (offset + limit < 0) {
                        // long overflow
                        maxEntryCount = Long.MAX_VALUE;
                    } else {
                        maxEntryCount = offset + limit;
                    }
                }
                List<IndexPlan> ipList = advIndex.getPlans(
                        filter, sortOrder, rootState);
                cost = Double.POSITIVE_INFINITY;
                for (IndexPlan p : ipList) {
                    long entryCount = Math.min(maxEntryCount, p.getEstimatedEntryCount());
                    double c = p.getCostPerExecution() + entryCount * p.getCostPerEntry();
                    if (c < cost) {
                        cost = c;
                        indexPlan = p;
                    }
                }
            } else {
                cost = index.getCost(filter, rootState);
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("cost for " + index.getIndexName() + " is " + cost);
            }
            if (cost < 0) {
                LOG.error("cost below 0 for " + index.getIndexName() + " is " + cost);
            }
            if (cost < bestCost) {
                bestCost = cost;
                bestIndex = index;
                bestPlan = indexPlan;
            }
        }

        if (traversalEnabled) {
            QueryIndex traversal = new TraversingIndex();
            double cost = traversal.getCost(filter, rootState);
            if (LOG.isDebugEnabled()) {
                LOG.debug("cost for " + traversal.getIndexName() + " is " + cost);
            }
            if (cost < bestCost || bestCost == Double.POSITIVE_INFINITY) {
                bestCost = cost;
                bestPlan = null;
                bestIndex = traversal;
View Full Code Here

        builder.child("newnode").setProperty("prop", "val");
        NodeState after = builder.getNodeState();

        NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);

        QueryIndex queryIndex = new SolrQueryIndex("solr", server, configuration);
        FilterImpl filter = new FilterImpl(mock(SelectorImpl.class), "", new QueryEngineSettings());
        filter.restrictPath("/newnode", Filter.PathRestriction.EXACT);
        filter.restrictProperty("prop", Operator.EQUAL,
                PropertyValues.newString("val"));
        Cursor cursor = queryIndex.query(filter, indexed);
        assertNotNull(cursor);
        assertTrue("no results found", cursor.hasNext());
        IndexRow next = cursor.next();
        assertNotNull("first returned item should not be null", next);
        assertEquals("/newnode", next.getPath());
View Full Code Here

        builder.child("test").setProperty("foo", "bar");
        NodeState after = builder.getNodeState();

        NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);

        QueryIndex queryIndex = new SolrQueryIndex("solr", server, configuration);
        FilterImpl filter = new FilterImpl(mock(SelectorImpl.class), "", new QueryEngineSettings());
        filter.restrictProperty("foo", Operator.EQUAL,
                PropertyValues.newString("bar"));
        Cursor cursor = queryIndex.query(filter, indexed);
        assertNotNull(cursor);
        assertTrue("no results found", cursor.hasNext());
        IndexRow next = cursor.next();
        assertNotNull("first returned item should not be null", next);
        assertEquals("/test", next.getPath());
View Full Code Here

        NodeState after = builder.getNodeState();

        NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);

        QueryIndex queryIndex = new SolrQueryIndex("solr", server, configuration);
        FilterImpl filter = new FilterImpl(mock(SelectorImpl.class), "", new QueryEngineSettings());
        filter.restrictProperty("foo", Operator.EQUAL,
                PropertyValues.newString("bar"));
        filter.restrictFulltextCondition("bar");
        Cursor cursor = queryIndex.query(filter, indexed);

        Set<String> paths = newHashSet();
        while (cursor.hasNext()) {
            paths.add(cursor.next().getPath());
        }
View Full Code Here

    }

    private SelectorExecutionPlan getBestSelectorExecutionPlan(
            NodeState rootState, FilterImpl filter,
            QueryIndexProvider indexProvider, boolean traversalEnabled) {
        QueryIndex bestIndex = null;
        if (LOG.isDebugEnabled()) {
            LOG.debug("cost using filter " + filter);
        }

        double bestCost = Double.POSITIVE_INFINITY;
        IndexPlan bestPlan = null;
        for (QueryIndex index : indexProvider.getQueryIndexes(rootState)) {
            double cost;
            IndexPlan indexPlan = null;
            if (index instanceof AdvancedQueryIndex) {
                AdvancedQueryIndex advIndex = (AdvancedQueryIndex) index;
                List<OrderEntry> sortOrder = null;
                if (orderings != null) {
                    sortOrder = new ArrayList<OrderEntry>();
                    for (OrderingImpl o : orderings) {
                        DynamicOperandImpl op = o.getOperand();
                        if (!(op instanceof PropertyValueImpl)) {
                            // ordered by a function: currently not supported
                            break;
                        }
                        PropertyValueImpl p = (PropertyValueImpl) op;
                        SelectorImpl s = p.getSelectors().iterator().next();
                        if (!s.equals(filter.getSelector())) {
                            // ordered by a different selector
                            continue;
                        }
                        OrderEntry e = new OrderEntry(
                                p.getPropertyName(),
                                Type.UNDEFINED,
                                o.isDescending() ?
                                OrderEntry.Order.DESCENDING : OrderEntry.Order.ASCENDING);
                        sortOrder.add(e);
                    }
                    if (sortOrder.size() == 0) {
                        sortOrder = null;
                    }
                }
                long maxEntryCount = limit;
                if (offset > 0) {
                    if (offset + limit < 0) {
                        // long overflow
                        maxEntryCount = Long.MAX_VALUE;
                    } else {
                        maxEntryCount = offset + limit;
                    }
                }
                List<IndexPlan> ipList = advIndex.getPlans(
                        filter, sortOrder, rootState);
                cost = Double.POSITIVE_INFINITY;
                for (IndexPlan p : ipList) {
                    // TODO limit is after all conditions
                    long entryCount = Math.min(maxEntryCount, p.getEstimatedEntryCount());
                    double c = p.getCostPerExecution() + entryCount * p.getCostPerEntry();
                    if (c < cost) {
                        cost = c;
                        indexPlan = p;
                    }
                }
            } else {
                cost = index.getCost(filter, rootState);
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("cost for " + index.getIndexName() + " is " + cost);
            }
            if (cost < 0) {
                LOG.error("cost below 0 for " + index.getIndexName() + " is " + cost);
            }
            if (cost < bestCost) {
                bestCost = cost;
                bestIndex = index;
                bestPlan = indexPlan;
            }
        }

        if (traversalEnabled) {
            QueryIndex traversal = new TraversingIndex();
            double cost = traversal.getCost(filter, rootState);
            if (LOG.isDebugEnabled()) {
                LOG.debug("cost for " + traversal.getIndexName() + " is " + cost);
            }
            if (cost < bestCost || bestCost == Double.POSITIVE_INFINITY) {
                bestCost = cost;
                bestPlan = null;
                bestIndex = traversal;
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.oak.spi.query.QueryIndex$AdvancedQueryIndex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.