use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.
the class QueryTest method propertyIndexWithDeclaringNodeTypeAndRelativQuery.
@Test
public void propertyIndexWithDeclaringNodeTypeAndRelativQuery() throws RepositoryException {
Session session = getAdminSession();
RowIterator rit;
QueryResult r;
String query;
query = "//element(*, rep:Authorizable)[@rep:principalName = 'admin']";
r = session.getWorkspace().getQueryManager().createQuery("explain " + query, "xpath").execute();
rit = r.getRows();
assertEquals("[rep:Authorizable] as [a] /* property principalName = admin " + "where [a].[rep:principalName] = 'admin' */", rit.nextRow().getValue("plan").getString());
query = "//element(*, rep:Authorizable)[admin/@rep:principalName = 'admin']";
r = session.getWorkspace().getQueryManager().createQuery("explain " + query, "xpath").execute();
rit = r.getRows();
assertEquals("[rep:Authorizable] as [a] /* nodeType " + "Filter(query=explain select [jcr:path], [jcr:score], * " + "from [rep:Authorizable] as a " + "where [admin/rep:principalName] = 'admin' " + "/* xpath: //element(*, rep:Authorizable)[" + "admin/@rep:principalName = 'admin'] */, path=*, " + "property=[admin/rep:principalName=[admin]]) " + "where [a].[admin/rep:principalName] = 'admin' */", rit.nextRow().getValue("plan").getString());
}
use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.
the class QueryPlanTest method uuidIndex.
@Test
public void uuidIndex() throws Exception {
Session session = getAdminSession();
QueryManager qm = session.getWorkspace().getQueryManager();
Node testRootNode = session.getRootNode().addNode("testroot");
Node n = testRootNode.addNode("node");
n.addMixin("mix:referenceable");
session.save();
// this matches just one node (exact path),
// so it should use the TraversintIndex
String xpath = "/jcr:root/testroot/node[@jcr:uuid]";
Query q;
QueryResult result;
RowIterator it;
q = qm.createQuery("explain " + xpath, "xpath");
result = q.execute();
it = result.getRows();
assertTrue(it.hasNext());
String plan = it.nextRow().getValue("plan").getString();
assertEquals("[nt:base] as [a] /* traverse \"/testroot/node\" where " + "([a].[jcr:uuid] is not null) " + "and (issamenode([a], [/testroot/node])) */", plan);
// verify the result
q = qm.createQuery(xpath, "xpath");
result = q.execute();
it = result.getRows();
assertTrue(it.hasNext());
String path = it.nextRow().getPath();
assertEquals("/testroot/node", path);
assertFalse(it.hasNext());
// this potentially matches many nodes,
// so it should use the index on the UUID property
xpath = "/jcr:root/testroot/*[@jcr:uuid]";
q = qm.createQuery("explain " + xpath, "xpath");
result = q.execute();
it = result.getRows();
assertTrue(it.hasNext());
plan = it.nextRow().getValue("plan").getString();
assertEquals("[nt:base] as [a] /* property uuid IS NOT NULL " + "where ([a].[jcr:uuid] is not null) " + "and (ischildnode([a], [/testroot])) */", plan);
}
use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.
the class QueryPlanTest method nodeType.
@Test
public void nodeType() throws Exception {
Session session = getAdminSession();
QueryManager qm = session.getWorkspace().getQueryManager();
Node nodetype = session.getRootNode().getNode("oak:index").getNode("nodetype");
nodetype.setProperty("entryCount", 10000000);
Node testRootNode = session.getRootNode().addNode("testroot");
Node n1 = testRootNode.addNode("node1");
Node n2 = n1.addNode("node2");
n2.addNode("node3");
session.save();
String sql2 = "select [jcr:path] as [path] from [nt:base] " + "where [node2/node3/jcr:primaryType] is not null " + "and isdescendantnode('/testroot')";
Query q;
QueryResult result;
RowIterator it;
q = qm.createQuery("explain " + sql2, Query.JCR_SQL2);
result = q.execute();
it = result.getRows();
assertTrue(it.hasNext());
String plan = it.nextRow().getValue("plan").getString();
// should not use the index on "jcr:primaryType"
assertEquals("[nt:base] as [nt:base] /* traverse \"/testroot//*\" " + "where ([nt:base].[node2/node3/jcr:primaryType] is not null) " + "and (isdescendantnode([nt:base], [/testroot])) " + "*/", plan);
// verify the result
q = qm.createQuery(sql2, Query.JCR_SQL2);
result = q.execute();
it = result.getRows();
assertTrue(it.hasNext());
String path = it.nextRow().getValue("path").getString();
assertEquals("/testroot/node1", path);
}
use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.
the class LuceneIndexDescendantSpellcheckTest method getSpellchecks.
private Set<String> getSpellchecks(String query) throws Exception {
QueryManager queryManager = session.getWorkspace().getQueryManager();
QueryResult result = queryManager.createQuery(query, Query.JCR_SQL2).execute();
RowIterator rows = result.getRows();
Set<String> suggestions = newHashSet();
while (rows.hasNext()) {
suggestions.add(rows.nextRow().getValue("spellcheck").getString());
}
return suggestions;
}
use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.
the class SpellcheckTest method getResult.
static List<String> getResult(QueryResult result, String propertyName) throws RepositoryException {
List<String> results = Lists.newArrayList();
RowIterator it = result.getRows();
while (it.hasNext()) {
Row row = it.nextRow();
results.add(row.getValue(propertyName).getString());
}
return results;
}
Aggregations