Search in sources :

Example 11 with FacetResult

use of org.apache.jackrabbit.oak.query.facet.FacetResult 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 12 with FacetResult

use of org.apache.jackrabbit.oak.query.facet.FacetResult in project jackrabbit-oak by apache.

the class FacetTest method testFacetRetrievalRelativeProperty.

public void testFacetRetrievalRelativeProperty() throws Exception {
    Session session = superuser;
    Node n1 = testRootNode.addNode("node1");
    n1.addNode("jc").setProperty("text", "hello");
    Node n2 = testRootNode.addNode("node2");
    n2.addNode("jc").setProperty("text", "hallo");
    Node n3 = testRootNode.addNode("node3");
    n3.addNode("jc").setProperty("text", "oh hallo");
    session.save();
    QueryManager qm = session.getWorkspace().getQueryManager();
    String sql2 = "select [jcr:path], [rep:facet(jc/text)] from [nt:base] " + "where contains([jc/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("jc/text"));
    List<FacetResult.Facet> facets = facetResult.getFacets("jc/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 13 with FacetResult

use of org.apache.jackrabbit.oak.query.facet.FacetResult in project jackrabbit-oak by apache.

the class FacetTest method testFacetsOfResultSetThatDoesntContainDim.

// OAK-7078
public void testFacetsOfResultSetThatDoesntContainDim() throws Exception {
    Node content = testRootNode.addNode("absentDimFacets");
    // create a document with a simple/tags property
    Node foo = content.addNode("foo");
    Node fooSimple = foo.addNode("jc");
    foo.setProperty("text", "lorem lorem");
    fooSimple.setProperty("text", new String[] { "tag1", "tag2" });
    // now create a document without simple/tags property
    Node bar = content.addNode("bar");
    bar.setProperty("text", "lorem ipsum");
    superuser.save();
    String query = "select [rep:facet(jc/text)] from [nt:base] where contains(*, 'ipsum')";
    Query q = qm.createQuery(query, Query.JCR_SQL2);
    QueryResult result = q.execute();
    FacetResult facetResult = new FacetResult(result);
    assertNotNull(facetResult);
    assertTrue(facetResult.getDimensions().isEmpty());
    RowIterator rows = result.getRows();
    assertTrue(rows.hasNext());
    assertEquals(bar.getPath(), rows.nextRow().getPath());
    assertFalse(rows.hasNext());
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator) FacetResult(org.apache.jackrabbit.oak.query.facet.FacetResult)

Aggregations

Node (javax.jcr.Node)13 Query (javax.jcr.query.Query)13 QueryResult (javax.jcr.query.QueryResult)13 FacetResult (org.apache.jackrabbit.oak.query.facet.FacetResult)13 Session (javax.jcr.Session)12 QueryManager (javax.jcr.query.QueryManager)12 NodeIterator (javax.jcr.NodeIterator)8 RowIterator (javax.jcr.query.RowIterator)1