Search in sources :

Example 31 with QueryManager

use of javax.jcr.query.QueryManager in project jackrabbit by apache.

the class MassiveRangeTest method testRangeQuery.

/**
     * Executes a range query covering 2'000 different property values.
     */
public void testRangeQuery() throws RepositoryException {
    int count = 0;
    for (int i = 0; i < 20; i++) {
        Node child = testRootNode.addNode("node" + i);
        for (int j = 0; j < 100; j++) {
            Node n = child.addNode("node" + j);
            n.setProperty("foo", count++);
        }
        // save every 100 nodes
        testRootNode.save();
    }
    QueryManager qm = superuser.getWorkspace().getQueryManager();
    String stmt = testPath + "//*[@foo >= 0]";
    QueryResult res = qm.createQuery(stmt, Query.XPATH).execute();
    checkResult(res, 2000);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager)

Example 32 with QueryManager

use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.

the class SpellcheckTest method testSpellcheckXPath.

public void testSpellcheckXPath() 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 xpath = "/jcr:root[rep:spellcheck('helo')]/(rep:spellcheck())";
    Query q = qm.createQuery(xpath, Query.XPATH);
    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 33 with QueryManager

use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.

the class SpellcheckTest method testSpellcheckMultipleWords.

public void testSpellcheckMultipleWords() throws Exception {
    Session session = superuser;
    QueryManager qm = session.getWorkspace().getQueryManager();
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("jcr:title", "it is always a good idea to go visiting ontario");
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("jcr:title", "ontario is a nice place to live in");
    Node n3 = testRootNode.addNode("node3");
    n2.setProperty("jcr:title", "I flied to ontario for voting for the major polls");
    Node n4 = testRootNode.addNode("node4");
    n2.setProperty("jcr:title", "I will go voting in ontario, I always voted since I've been allowed to");
    session.save();
    String xpath = "/jcr:root[rep:spellcheck('votin in ontari')]/(rep:spellcheck())";
    Query q = qm.createQuery(xpath, Query.XPATH);
    List<String> result = getResult(q.execute(), "rep:spellcheck()");
    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals("voting in ontario", result.get(0));
}
Also used : Query(javax.jcr.query.Query) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager) Session(javax.jcr.Session)

Example 34 with QueryManager

use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.

the class SuggestTest method testSuggestSql.

public void testSuggestSql() 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 sql = "SELECT [rep:suggest()] FROM nt:base WHERE [jcr:path] = '/' AND SUGGEST('in 201')";
    Query q = qm.createQuery(sql, Query.SQL);
    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 35 with QueryManager

use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.

the class SuggestTest method testNoSuggestions.

public void testNoSuggestions() 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 sql = "SELECT [rep:suggest()] FROM nt:base WHERE [jcr:path] = '/' AND SUGGEST('blablabla')";
    Query q = qm.createQuery(sql, Query.SQL);
    List<String> result = getResult(q.execute(), "rep:suggest()");
    assertNotNull(result);
    assertEquals("There shouldn't be any suggestions", 0, result.size());
}
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