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);
}
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;
}
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);
}
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"));
}
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);
}
Aggregations