Search in sources :

Example 1 with Tree

use of org.apache.jackrabbit.oak.api.Tree in project jackrabbit-oak by apache.

the class QueryImpl method currentRow.

ResultRowImpl currentRow() {
    int selectorCount = selectors.size();
    Tree[] trees = new Tree[selectorCount];
    for (int i = 0; i < selectorCount; i++) {
        SelectorImpl s = selectors.get(i);
        trees[i] = s.currentTree();
    }
    int columnCount = columns.length;
    PropertyValue[] values = new PropertyValue[columnCount];
    for (int i = 0; i < columnCount; i++) {
        ColumnImpl c = columns[i];
        values[i] = c.currentProperty();
    }
    PropertyValue[] orderValues;
    if (orderings == null) {
        orderValues = null;
    } else {
        int size = orderings.length;
        orderValues = new PropertyValue[size];
        for (int i = 0; i < size; i++) {
            orderValues[i] = orderings[i].getOperand().currentProperty();
        }
    }
    return new ResultRowImpl(this, trees, values, distinctColumns, orderValues);
}
Also used : SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) Tree(org.apache.jackrabbit.oak.api.Tree) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) ColumnImpl(org.apache.jackrabbit.oak.query.ast.ColumnImpl)

Example 2 with Tree

use of org.apache.jackrabbit.oak.api.Tree in project jackrabbit-oak by apache.

the class SelectorImpl method evaluateTypeMatch.

private boolean evaluateTypeMatch() {
    Tree tree = getTree(currentRow.getPath());
    if (tree == null || !tree.exists()) {
        return false;
    }
    PropertyState primary = tree.getProperty(JCR_PRIMARYTYPE);
    if (primary != null && primary.getType() == NAME) {
        String name = primary.getValue(NAME);
        if (primaryTypes.contains(name)) {
            return true;
        }
    }
    PropertyState mixins = tree.getProperty(JCR_MIXINTYPES);
    if (mixins != null && mixins.getType() == NAMES) {
        for (String name : mixins.getValue(NAMES)) {
            if (mixinTypes.contains(name)) {
                return true;
            }
        }
    }
    // no matches found
    return false;
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 3 with Tree

use of org.apache.jackrabbit.oak.api.Tree in project jackrabbit-oak by apache.

the class SimpleExcerptProvider method getExcerpt.

public static String getExcerpt(String path, String columnName, Query query, boolean highlight) {
    if (path == null) {
        return null;
    }
    Tree t = query.getTree(path);
    if (t == null || !t.exists()) {
        return null;
    }
    columnName = extractExcerptProperty(columnName);
    if (columnName != null && columnName.contains("/")) {
        for (String p : PathUtils.elements(PathUtils.getParentPath(columnName))) {
            if (t.hasChild(p)) {
                t = t.getChild(p);
            } else {
                return null;
            }
        }
        columnName = PathUtils.getName(columnName);
    }
    StringBuilder text = new StringBuilder();
    String separator = "";
    for (PropertyState p : t.getProperties()) {
        if (p.getType().tag() == Type.STRING.tag() && (columnName == null || columnName.equalsIgnoreCase(p.getName()))) {
            text.append(separator);
            separator = " ";
            for (String v : p.getValue(Type.STRINGS)) {
                text.append(v);
            }
        }
    }
    Set<String> searchToken = extractFulltext(query);
    if (highlight && searchToken != null) {
        return highlight(text, searchToken);
    }
    return noHighlight(text);
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 4 with Tree

use of org.apache.jackrabbit.oak.api.Tree in project jackrabbit-oak by apache.

the class MultiPropertyOrTest method unionSortResultCount.

@Test
public void unionSortResultCount() throws Exception {
    // create test data
    Tree test = root.getTree("/").addChild("test");
    root.commit();
    List<Integer> nodes = Lists.newArrayList();
    Random r = new Random();
    int seed = -2;
    for (int i = 0; i < 1000; i++) {
        Tree a = test.addChild("a" + i);
        a.setProperty("x", "fooa");
        seed += 2;
        int num = r.nextInt(100);
        a.setProperty("z", num);
        nodes.add(num);
    }
    seed = -1;
    for (int i = 0; i < 1000; i++) {
        Tree a = test.addChild("b" + i);
        a.setProperty("y", "foob");
        seed += 2;
        int num = 100 + r.nextInt(100);
        a.setProperty("z", num);
        nodes.add(num);
    }
    root.commit();
    // scan count scans the whole result set
    String query = "measure /jcr:root//element(*, nt:base)[(@x = 'fooa' or @y = 'foob')] order by @z";
    assertThat(measureWithLimit(query, XPATH, 100), containsString("scanCount: 2000"));
}
Also used : Random(java.util.Random) Tree(org.apache.jackrabbit.oak.api.Tree) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) Test(org.junit.Test) AbstractQueryTest(org.apache.jackrabbit.oak.query.AbstractQueryTest)

Example 5 with Tree

use of org.apache.jackrabbit.oak.api.Tree in project jackrabbit-oak by apache.

the class MultiPropertyOrTest method query.

@Test
public void query() throws Exception {
    Tree t = root.getTree("/");
    t.addChild("a").setProperty("x", "foo");
    t.addChild("b").setProperty("y", "bar");
    t.addChild("c").setProperty("z", "foo");
    root.commit();
    setTraversalEnabled(false);
    assertQuery("select [jcr:path] from [nt:base] where [x] is not null", ImmutableList.of("/a"));
    List<String> lines = executeQuery("explain select [jcr:path] from [nt:base] where [x] is not null", Query.JCR_SQL2);
    assertEquals(1, lines.size());
    // make sure it used the property index
    assertTrue(lines.get(0).contains("property xyz IS NOT NULL"));
    lines = executeQuery("explain select [jcr:path] from [nt:base] where [x] = 'foo' OR [y] = 'foo'", Query.JCR_SQL2);
    assertEquals(1, lines.size());
    // make sure it used the property index
    assertTrue(lines.get(0).contains("property xyz = foo"));
    lines = executeQuery("explain select [jcr:path] from [nt:base] where [x] = 'foo' OR [y] = 'bar'", Query.JCR_SQL2);
    assertEquals(1, lines.size());
    // make sure it used the property index
    assertTrue(lines.get(0), lines.get(0).contains("property xyz = foo"));
    assertTrue(lines.get(0), lines.get(0).contains("property xyz = bar"));
    assertQuery("select [jcr:path] from [nt:base] where [x] = 'foo' OR [y] = 'foo'", ImmutableList.of("/a"));
    assertQuery("select [jcr:path] from [nt:base] where [x] = 'foo' OR [z] = 'foo'", ImmutableList.of("/a", "/c"));
    assertQuery("select [jcr:path] from [nt:base] where [x] = 'foo' OR [y] = 'bar'", ImmutableList.of("/a", "/b"));
    setTraversalEnabled(false);
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) Test(org.junit.Test) AbstractQueryTest(org.apache.jackrabbit.oak.query.AbstractQueryTest)

Aggregations

Tree (org.apache.jackrabbit.oak.api.Tree)1248 Test (org.junit.Test)915 AbstractQueryTest (org.apache.jackrabbit.oak.query.AbstractQueryTest)219 Root (org.apache.jackrabbit.oak.api.Root)192 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)160 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)153 OakBaseTest (org.apache.jackrabbit.oak.OakBaseTest)78 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)77 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)69 TreePermission (org.apache.jackrabbit.oak.spi.security.authorization.permission.TreePermission)67 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)59 ImmutableTree (org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree)55 Nonnull (javax.annotation.Nonnull)54 InputStream (java.io.InputStream)46 ByteArrayInputStream (java.io.ByteArrayInputStream)41 RemoteTree (org.apache.jackrabbit.oak.remote.RemoteTree)41 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)32 PermissionProvider (org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider)32 JsonNode (com.fasterxml.jackson.databind.JsonNode)30 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)29