use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class QueryFulltextTest method testScore.
public void testScore() throws Exception {
Session session = superuser;
QueryManager qm = session.getWorkspace().getQueryManager();
Node n1 = testRootNode.addNode("node1");
n1.setProperty("text", "hello hello hello");
Node n2 = testRootNode.addNode("node2");
n2.setProperty("text", "hello");
session.save();
String xpath = "/jcr:root//*[jcr:contains(@text, 'hello')] order by jcr:score()";
Query q = qm.createQuery(xpath, "xpath");
String result = getResult(q.execute(), "jcr:score");
// expect two numbers (any value)
result = result.replaceAll("[0-9\\.]+", "n");
assertEquals("n, n", result);
}
use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class SpellcheckTest method testSpellcheckSql.
public void testSpellcheckSql() throws Exception {
Session session = superuser;
QueryManager qm = session.getWorkspace().getQueryManager();
Node n1 = testRootNode.addNode("node1");
n1.setProperty("jcr:title", "hello hello hello alt");
Node n2 = testRootNode.addNode("node2");
n2.setProperty("jcr:title", "hold");
session.save();
String sql = "SELECT [rep:spellcheck()] FROM nt:base WHERE [jcr:path] = '/' AND SPELLCHECK('helo')";
Query q = qm.createQuery(sql, Query.SQL);
List<String> result = getResult(q.execute(), "rep:spellcheck()");
assertNotNull(result);
assertEquals(2, result.size());
assertEquals("[hello, hold]", result.toString());
}
use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class SuggestTest method testSuggestXPath.
public void testSuggestXPath() throws Exception {
Session session = superuser;
QueryManager qm = session.getWorkspace().getQueryManager();
Node n1 = testRootNode.addNode("node1");
n1.setProperty("jcr:title", "in 2015 my fox is red, like mike's fox and john's fox");
Node n2 = testRootNode.addNode("node2");
n2.setProperty("jcr:title", "in 2015 a red fox is still a fox");
session.save();
String xpath = "/jcr:root[rep:suggest('in 201')]/(rep:suggest())";
Query q = qm.createQuery(xpath, Query.XPATH);
List<String> result = getResult(q.execute(), "rep:suggest()");
assertNotNull(result);
assertEquals(2, result.size());
assertTrue(result.contains("in 2015 a red fox is still a fox"));
assertTrue(result.contains("in 2015 my fox is red, like mike's fox and john's fox"));
}
use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class FacetTest method testFacetRetrievalDefaultNumberOfFacets.
public void testFacetRetrievalDefaultNumberOfFacets() throws RepositoryException {
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(10, facets.size());
}
use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class SuggestTest method testSuggestInfix.
public void testSuggestInfix() throws Exception {
Session session = superuser;
QueryManager qm = session.getWorkspace().getQueryManager();
Node n1 = testRootNode.addNode("node1");
n1.setProperty("jcr:title", "in 2015 my fox is red, like mike's fox and john's fox");
Node n2 = testRootNode.addNode("node2");
n2.setProperty("jcr:title", "in 2015 a red fox is still a fox");
session.save();
String xpath = "/jcr:root[rep:suggest('like mike')]/(rep:suggest())";
Query q = qm.createQuery(xpath, Query.XPATH);
List<String> result = getResult(q.execute(), "rep:suggest()");
assertNotNull(result);
assertTrue(result.contains("in 2015 my fox is red, like mike's fox and john's fox"));
}
Aggregations