Search in sources :

Example 61 with QueryManager

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());
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager) FacetResult(org.apache.jackrabbit.oak.query.facet.FacetResult) Session(javax.jcr.Session)

Example 62 with QueryManager

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());
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager) FacetResult(org.apache.jackrabbit.oak.query.facet.FacetResult) Session(javax.jcr.Session)

Example 63 with QueryManager

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"));
}
Also used : Query(javax.jcr.query.Query) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager) Session(javax.jcr.Session)

Example 64 with QueryManager

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);
}
Also used : Query(javax.jcr.query.Query) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager) Session(javax.jcr.Session)

Example 65 with QueryManager

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);
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager) Session(javax.jcr.Session)

Aggregations

QueryManager (javax.jcr.query.QueryManager)103 Query (javax.jcr.query.Query)69 Node (javax.jcr.Node)61 QueryResult (javax.jcr.query.QueryResult)55 Session (javax.jcr.Session)54 NodeIterator (javax.jcr.NodeIterator)34 RowIterator (javax.jcr.query.RowIterator)27 Test (org.junit.Test)27 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)22 RepositoryException (javax.jcr.RepositoryException)18 Row (javax.jcr.query.Row)14 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)14 FacetResult (org.apache.jackrabbit.oak.query.facet.FacetResult)9 ValueFactory (javax.jcr.ValueFactory)7 NoSuchElementException (java.util.NoSuchElementException)6 InvalidItemStateException (javax.jcr.InvalidItemStateException)3 Value (javax.jcr.Value)3 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2