}
public void testFulltextRelativeProperty() throws Exception {
Session session = superuser;
QueryManager qm = session.getWorkspace().getQueryManager();
Node n1 = testRootNode.addNode("node1");
n1.setProperty("text", "hello");
Node n2 = testRootNode.addNode("node2");
n2.setProperty("text", "hallo");
Node n3 = testRootNode.addNode("node3");
n3.setProperty("text", "hello hallo");
session.save();
Query q;
String sql2 = "select [jcr:path] as [path] from [nt:base] " +
"where ISCHILDNODE([/testroot])" +
" AND CONTAINS(text, 'hallo')";
q = qm.createQuery("explain " + sql2, Query.JCR_SQL2);
// TODO the plan should actually be:
// assertEquals("[nt:base] as [nt:base] /* " +
// "+text:hallo +:path:/testroot/* +text:{* TO *} " +
// "ft:(text:\"hallo\") " +
// "where (ischildnode([nt:base], [/testroot])) " +
// "and (contains([nt:base].[text], cast('hallo' as string))) */",
// getResult(q.execute(), "plan"));
assertEquals("[nt:base] as [nt:base] /* " +
"aggregate +:fulltext:hallo* +:path:/testroot/* +text:{* TO *}" +
"ft:(text:\"hallo\") " +
"where (ischildnode([nt:base], [/testroot])) " +
"and (contains([nt:base].[text], cast('hallo' as string))) */",
getResult(q.execute(), "plan"));
q = qm.createQuery(sql2, Query.JCR_SQL2);
assertEquals("/testroot/node2, /testroot/node3", getResult(q.execute(), "path"));
sql2 = "select [jcr:path] as [path] from [nt:base] " +
"where contains([node1/text], 'hello') order by [jcr:path]";
// q = qm.createQuery("explain " + sql2, Query.JCR_SQL2);
// assertEquals("[nt:base] as [nt:base] /* " +
// "+text:hallo +:path:/testroot/* +text:{* TO *} " +
// "ft:(text:\"hallo\") " +
// "where (ischildnode([nt:base], [/testroot])) " +
// "and (contains([nt:base].[text], cast('hallo' as string))) */",
// getResult(q.execute(), "plan"));
q = qm.createQuery(sql2, Query.JCR_SQL2);
assertEquals("/testroot", getResult(q.execute(), "path"));
sql2 = "select [jcr:path] as [path] from [nt:base] " +
"where contains([node2/text], 'hello OR hallo') order by [jcr:path]";
q = qm.createQuery("explain " + sql2, Query.JCR_SQL2);
// TODO the plan should actually be:
// assertEquals("[nt:base] as [nt:base] /* " +
// "(text:hallo text:hello)~1 " +
// "ft:(node2/text:\"hallo\" OR node2/text:\"hello\") " +
// "parent:node2 " +
// "where contains([nt:base].[node2/text], cast('hello OR hallo' as string)) */",
// getResult(q.execute(), "plan"));
assertEquals("[nt:base] as [nt:base] /* " +
"aggregate :fulltext:hallo* :fulltext:hello* " +
"ft:(node2/text:\"hallo\" OR node2/text:\"hello\") " +
"parent:node2 " +
"where contains([nt:base].[node2/text], cast('hello OR hallo' as string)) */",
getResult(q.execute(), "plan"));
q = qm.createQuery(sql2, Query.JCR_SQL2);
assertEquals("/testroot",
getResult(q.execute(), "path"));
sql2 = "select [jcr:path] as [path] from [nt:base] " +
"where contains([node1/text], 'hello') " +
"and contains([node2/text], 'hallo') " +
"order by [jcr:path]";
q = qm.createQuery("explain " + sql2, Query.JCR_SQL2);
// TODO OAK-890
assertEquals("[nt:base] as [nt:base] /* " +
"aggregate Not yet implemented " +
"where (contains([nt:base].[node1/text], cast('hello' as string))) " +
"and (contains([nt:base].[node2/text], cast('hallo' as string))) */",
getResult(q.execute(), "plan"));
q = qm.createQuery(sql2, Query.JCR_SQL2);
// assertEquals("/testroot",
// getResult(q.execute(), "path"));
}