Search in sources :

Example 66 with QueryManager

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

Example 67 with QueryManager

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

Example 68 with QueryManager

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

Example 69 with QueryManager

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());
}
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 70 with QueryManager

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"));
}
Also used : 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