use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class FacetTest method testFacetRetrieval2.
public void testFacetRetrieval2() throws Exception {
Session session = superuser;
Node n1 = testRootNode.addNode("node1");
String pn = "jcr:title";
n1.setProperty(pn, "hello");
Node n2 = testRootNode.addNode("node2");
n2.setProperty(pn, "hallo");
Node n3 = testRootNode.addNode("node3");
n3.setProperty(pn, "oh hallo");
session.save();
QueryManager qm = session.getWorkspace().getQueryManager();
String sql2 = "select [jcr:path], [rep:facet(" + pn + ")] from [nt:base] " + "where contains([" + pn + "], 'hallo') order by [jcr:path]";
Query q = qm.createQuery(sql2, Query.JCR_SQL2);
QueryResult result = q.execute();
FacetResult facetResult = new FacetResult(result);
assertNotNull(facetResult);
assertNotNull(facetResult.getDimensions());
assertEquals(1, facetResult.getDimensions().size());
assertTrue(facetResult.getDimensions().contains(pn));
List<FacetResult.Facet> facets = facetResult.getFacets(pn);
assertNotNull(facets);
assertEquals("hallo", facets.get(0).getLabel());
assertEquals(1, facets.get(0).getCount(), 0);
assertEquals("oh hallo", facets.get(1).getLabel());
assertEquals(1, facets.get(1).getCount(), 0);
NodeIterator nodes = result.getNodes();
assertTrue(nodes.hasNext());
assertNotNull(nodes.nextNode());
assertTrue(nodes.hasNext());
assertNotNull(nodes.nextNode());
assertFalse(nodes.hasNext());
}
use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class FacetTest method testFacetRetrievalWithAnonymousUser.
public void testFacetRetrievalWithAnonymousUser() throws Exception {
Session session = superuser;
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", "oh hallo");
session.save();
session = getHelper().getReadOnlySession();
QueryManager qm = session.getWorkspace().getQueryManager();
String sql2 = "select [jcr:path], [rep:facet(text)] from [nt:base] " + "where contains([text], 'hello OR hallo') order by [jcr:path]";
Query q = qm.createQuery(sql2, Query.JCR_SQL2);
QueryResult result = q.execute();
FacetResult facetResult = new FacetResult(result);
assertNotNull(facetResult);
assertNotNull(facetResult.getDimensions());
assertEquals(1, facetResult.getDimensions().size());
assertTrue(facetResult.getDimensions().contains("text"));
List<FacetResult.Facet> facets = facetResult.getFacets("text");
assertNotNull(facets);
assertEquals("hallo", facets.get(0).getLabel());
assertEquals(1, facets.get(0).getCount(), 0);
assertEquals("hello", facets.get(1).getLabel());
assertEquals(1, facets.get(1).getCount(), 0);
assertEquals("oh hallo", facets.get(2).getLabel());
assertEquals(1, facets.get(2).getCount(), 0);
NodeIterator nodes = result.getNodes();
assertTrue(nodes.hasNext());
assertNotNull(nodes.nextNode());
assertTrue(nodes.hasNext());
assertNotNull(nodes.nextNode());
assertTrue(nodes.hasNext());
assertNotNull(nodes.nextNode());
assertFalse(nodes.hasNext());
}
use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class QueryFulltextTest method testFulltextRelativeProperty.
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(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(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(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(sql2, Query.JCR_SQL2);
assertEquals("/testroot", getResult(q.execute(), "path"));
}
use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class QueryFulltextTest method testInValues.
public void testInValues() 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();
String sql2 = "select [jcr:path] as [path], [jcr:score], * from [nt:base] as a " + "where [text] in('hello', 'hallo')";
Query q = qm.createQuery(sql2, Query.JCR_SQL2);
String path = getResult(q.execute(), "path");
assertEquals("/testroot/node1, /testroot/node2", path);
}
use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class QueryFulltextTest method testNativeMatchAll.
public void testNativeMatchAll() throws Exception {
Session session = superuser;
QueryManager qm = session.getWorkspace().getQueryManager();
String sql2 = "select [jcr:path] as [path] from [nt:base] " + "where native('solr', '*:*')";
Query q = qm.createQuery(sql2, Query.JCR_SQL2);
QueryResult result = q.execute();
NodeIterator nodes = result.getNodes();
while (nodes.hasNext()) {
Node node = nodes.nextNode();
assertNotNull(node);
}
}
Aggregations