Search in sources :

Example 1 with FacetResult

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

the class FacetTest method testFacetRetrievalNumberOfFacetsConfiguredLowerThanDefault.

public void testFacetRetrievalNumberOfFacetsConfiguredLowerThanDefault() throws RepositoryException {
    Node facetsConfig = superuser.getNode(FACET_CONFING_NODE_PATH);
    facetsConfig.setProperty(LuceneIndexConstants.PROP_FACETS_TOP_CHILDREN, 7);
    markIndexForReindex();
    superuser.save();
    superuser.refresh(true);
    Session session = superuser;
    Node n1 = testRootNode.addNode("node1");
    String pn = "jcr:title";
    n1.setProperty(pn, "hello 1");
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty(pn, "hallo 2");
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty(pn, "hallo 3");
    Node n4 = testRootNode.addNode("node4");
    n4.setProperty(pn, "hallo 4");
    Node n5 = testRootNode.addNode("node5");
    n5.setProperty(pn, "hallo 5");
    Node n6 = testRootNode.addNode("node6");
    n6.setProperty(pn, "hallo 6");
    Node n7 = testRootNode.addNode("node7");
    n7.setProperty(pn, "hallo 7");
    Node n8 = testRootNode.addNode("node8");
    n8.setProperty(pn, "hallo 8");
    Node n9 = testRootNode.addNode("node9");
    n9.setProperty(pn, "hallo 9");
    Node n10 = testRootNode.addNode("node10");
    n10.setProperty(pn, "hallo 10");
    Node n11 = testRootNode.addNode("node11");
    n11.setProperty(pn, "hallo 11");
    Node n12 = testRootNode.addNode("node12");
    n12.setProperty(pn, "hallo 12");
    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(7, facets.size());
}
Also used : 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 2 with FacetResult

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

the class FacetTest method testFacetRetrievalXPath.

public void testFacetRetrievalXPath() 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();
    QueryManager qm = session.getWorkspace().getQueryManager();
    String xpath = "//*[jcr:contains(@text, 'hello OR hallo')]/(rep:facet(text)) order by jcr:path";
    Query q = qm.createQuery(xpath, Query.XPATH);
    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 3 with FacetResult

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

the class FacetTest method testFacetRetrievalRelativePropertyXPath.

public void testFacetRetrievalRelativePropertyXPath() 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 xpath = "//*[jcr:contains(jc/@text, 'hello OR hallo')]/(rep:facet(jc/text)) order by jcr:path";
    Query q = qm.createQuery(xpath, Query.XPATH);
    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 4 with FacetResult

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

the class FacetTest method testFacetRetrievalMV.

public void testFacetRetrievalMV() throws Exception {
    Session session = superuser;
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("jcr:title", "apache jackrabbit oak");
    n1.setProperty("tags", new String[] { "software", "repository", "apache" });
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("jcr:title", "oak furniture");
    n2.setProperty("tags", "furniture");
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty("jcr:title", "oak cosmetics");
    n3.setProperty("tags", "cosmetics");
    Node n4 = testRootNode.addNode("node4");
    n4.setProperty("jcr:title", "oak and aem");
    n4.setProperty("tags", new String[] { "software", "repository", "aem" });
    session.save();
    QueryManager qm = session.getWorkspace().getQueryManager();
    String sql2 = "select [jcr:path], [rep:facet(tags)] from [nt:base] " + "where contains([jcr:title], 'oak') 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("tags"));
    List<FacetResult.Facet> facets = facetResult.getFacets("tags");
    assertNotNull(facets);
    assertEquals("repository", facets.get(0).getLabel());
    assertEquals(2, facets.get(0).getCount(), 0);
    assertEquals("software", facets.get(1).getLabel());
    assertEquals(2, facets.get(1).getCount(), 0);
    assertEquals("aem", facets.get(2).getLabel());
    assertEquals(1, facets.get(2).getCount(), 0);
    assertEquals("apache", facets.get(3).getLabel());
    assertEquals(1, facets.get(3).getCount(), 0);
    assertEquals("cosmetics", facets.get(4).getLabel());
    assertEquals(1, facets.get(4).getCount(), 0);
    assertEquals("furniture", facets.get(5).getLabel());
    assertEquals(1, facets.get(5).getCount(), 0);
    NodeIterator nodes = result.getNodes();
    assertTrue(nodes.hasNext());
    assertNotNull(nodes.nextNode());
    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 5 with FacetResult

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

the class FacetTest method testFacetRetrieval.

public void testFacetRetrieval() 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();
    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)

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