Search in sources :

Example 1 with QueryResult

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

the class FulltextSQL2QueryTest method testFulltextSimpleSQL.

public void testFulltextSimpleSQL() throws Exception {
    Node foo = testRootNode.addNode("foo");
    foo.setProperty("mytext", new String[] { "the quick brown fox jumps over the lazy dog." });
    testRootNode.save();
    String sql = "SELECT * FROM [nt:unstructured]" + " WHERE ISCHILDNODE([" + testRoot + "])" + " AND CONTAINS(mytext, 'fox')";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
    QueryResult result = q.execute();
    checkResult(result, 1);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node)

Example 2 with QueryResult

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

the class JoinTest method testJoinWithOR4.

public void testJoinWithOR4() throws Exception {
    StringBuilder join = new StringBuilder("SELECT a.* FROM [nt:unstructured] AS a");
    join.append("  INNER JOIN [nt:unstructured] AS b ON b.[jcr:uuid] = a.testref ");
    join.append("  WHERE  ");
    join.append("  a.type = 'child' ");
    join.append("  AND (");
    join.append("    CONTAINS(a.*, 'testJoinWithOR4')  ");
    join.append("    OR ");
    join.append("    b.type = 'parent' ");
    join.append("    AND ");
    join.append("    CONTAINS(b.*, 'testJoinWithOR4') ");
    join.append("  )");
    Query q = qm.createQuery(join.toString(), Query.JCR_SQL2);
    QueryResult result = q.execute();
    checkResult(result, 2);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query)

Example 3 with QueryResult

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

the class DerefTest method testDerefToVersionNode.

/**
     * Checks if jcr:deref works when dereferencing into the version storage.
     */
public void testDerefToVersionNode() throws RepositoryException {
    Node referenced = testRootNode.addNode(nodeName1);
    referenced.addMixin(mixVersionable);
    testRootNode.save();
    Version version = referenced.checkin();
    Node referencedVersionNode = version.getNode(jcrFrozenNode);
    Node referencer = testRootNode.addNode(nodeName2);
    referencer.setProperty(propertyName1, referencedVersionNode);
    testRootNode.save();
    String query = "/" + testRoot + "/*[@" + propertyName1 + "]/jcr:deref(@" + propertyName1 + ",'*')";
    QueryManager qm = superuser.getWorkspace().getQueryManager();
    Query q = qm.createQuery(query, Query.XPATH);
    QueryResult qr = q.execute();
    NodeIterator ni = qr.getNodes();
    assertEquals("Must find one result in query", 1, ni.getSize());
    while (ni.hasNext()) {
        Node node = (Node) ni.next();
        assertTrue(node.getProperty("jcr:frozenUuid").getString().equals(referenced.getUUID()));
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Version(javax.jcr.version.Version) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager)

Example 4 with QueryResult

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

the class ExcerptTest method testQuotedPhraseNoMatch.

/**
     * Verifies excerpt generation on a node property that does not contain any
     * excerpt info for a quoted phrase
     */
public void testQuotedPhraseNoMatch() throws RepositoryException {
    String text = "one two three four";
    String excerpt = createExcerpt("one two three four");
    String terms = "\"five six\"";
    Node n = testRootNode.addNode(nodeName1);
    n.setProperty("text", text);
    n.setProperty("other", terms);
    superuser.save();
    String stmt = getStatement(terms);
    QueryResult result = executeQuery(stmt);
    RowIterator rows = result.getRows();
    assertEquals(1, rows.getSize());
    String ex = rows.nextRow().getValue("rep:excerpt(text)").getString();
    assertEquals("Expected " + excerpt + ", but got ", excerpt, ex);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator)

Example 5 with QueryResult

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

the class ExcerptTest method testQuotedPhraseNoMatchScrambled.

/**
     * 
     * Verifies excerpt generation on a node property that contains the exact
     * quoted phrase but with scrambled words.
     * 
     * More clearly it actually checks that the order of tokens is respected for
     * a quoted phrase.
     */
public void testQuotedPhraseNoMatchScrambled() throws RepositoryException {
    String text = "one two three four";
    String excerpt = createExcerpt("one two three four");
    String terms = "\"three two\"";
    Node n = testRootNode.addNode(nodeName1);
    n.setProperty("text", text);
    n.setProperty("other", terms);
    superuser.save();
    String stmt = getStatement(terms);
    QueryResult result = executeQuery(stmt);
    RowIterator rows = result.getRows();
    assertEquals(1, rows.getSize());
    String ex = rows.nextRow().getValue("rep:excerpt(text)").getString();
    assertEquals("Expected " + excerpt + ", but got ", excerpt, ex);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator)

Aggregations

QueryResult (javax.jcr.query.QueryResult)200 Node (javax.jcr.Node)108 Query (javax.jcr.query.Query)97 QueryManager (javax.jcr.query.QueryManager)54 NodeIterator (javax.jcr.NodeIterator)52 RowIterator (javax.jcr.query.RowIterator)46 Session (javax.jcr.Session)35 Test (org.junit.Test)32 Row (javax.jcr.query.Row)21 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)21 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)15 RepositoryException (javax.jcr.RepositoryException)14 FacetResult (org.apache.jackrabbit.oak.query.facet.FacetResult)9 Value (javax.jcr.Value)8 NoSuchElementException (java.util.NoSuchElementException)7 ArrayList (java.util.ArrayList)6 ValueFactory (javax.jcr.ValueFactory)6 InvalidItemStateException (javax.jcr.InvalidItemStateException)5 JackrabbitQueryResult (org.apache.jackrabbit.api.query.JackrabbitQueryResult)5 TreeSet (java.util.TreeSet)4