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());
}
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());
}
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());
}
Aggregations