Search in sources :

Example 46 with RowIterator

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

the class GQLTest method testExcerpt.

public void testExcerpt() throws RepositoryException {
    Node file = addFile(testRootNode, "file1.txt", SAMPLE_CONTENT);
    superuser.save();
    String stmt = createStatement("quick");
    checkResultWithRetries(stmt, "jcr:content", new Node[] { file });
    RowIterator rows = GQL.execute(stmt, superuser, "jcr:content");
    assertTrue("Expected result", rows.hasNext());
    String excerpt = rows.nextRow().getValue("rep:excerpt()").getString();
    assertTrue("No excerpt returned", excerpt.startsWith("<div><span>"));
    stmt = createStatement("type:resource quick");
    rows = GQL.execute(stmt, superuser);
    assertTrue("Expected result", rows.hasNext());
    excerpt = rows.nextRow().getValue("rep:excerpt()").getString();
    assertTrue("No excerpt returned", excerpt.startsWith("<div><span>"));
}
Also used : Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator)

Example 47 with RowIterator

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

the class GQLTest method testApostrophe.

/**
     * Test for JCR-3157
     */
public void testApostrophe() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("text", "let's go");
    superuser.save();
    String stmt = createStatement("\"let's go\"");
    RowIterator rows = GQL.execute(stmt, superuser);
    checkResult(rows, new Node[] { n1 });
}
Also used : Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator)

Example 48 with RowIterator

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

the class GQLTest method testLimit.

public void testLimit() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("p", 1);
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("p", 2);
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty("p", 3);
    superuser.save();
    // only 2 results
    String stmt = createStatement("order:p limit:2");
    RowIterator rows = GQL.execute(stmt, superuser);
    checkResultSequence(rows, new Node[] { n1, n2 });
    // range with open start
    stmt = createStatement("order:p limit:..2");
    rows = GQL.execute(stmt, superuser);
    checkResultSequence(rows, new Node[] { n1, n2 });
    // range with open end
    stmt = createStatement("order:p limit:1..");
    rows = GQL.execute(stmt, superuser);
    checkResultSequence(rows, new Node[] { n2, n3 });
    // range
    stmt = createStatement("order:p limit:1..2");
    rows = GQL.execute(stmt, superuser);
    checkResultSequence(rows, new Node[] { n2 });
    // range with end larger than max results
    stmt = createStatement("order:p limit:1..7");
    rows = GQL.execute(stmt, superuser);
    checkResultSequence(rows, new Node[] { n2, n3 });
    // range start larger than end
    // end is ignored in that case
    stmt = createStatement("order:p limit:2..1");
    rows = GQL.execute(stmt, superuser);
    checkResultSequence(rows, new Node[] { n3 });
    // range with start larger than max results
    stmt = createStatement("order:p limit:6..10");
    rows = GQL.execute(stmt, superuser);
    checkResultSequence(rows, new Node[] {});
}
Also used : Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator)

Example 49 with RowIterator

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

the class GQLTest method testOrderDeep.

public void testOrderDeep() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("prop", "value");
    n1.addNode("sub").setProperty("p", 1);
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("prop", "value");
    n2.addNode("sub").setProperty("p", 2);
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty("prop", "value");
    n3.addNode("sub").setProperty("p", 3);
    superuser.save();
    // default: ascending
    String stmt = createStatement("prop:value order:sub/p");
    RowIterator rows = GQL.execute(stmt, superuser);
    checkResultSequence(rows, new Node[] { n1, n2, n3 });
    // explicit ascending
    stmt = createStatement("prop:value order:+sub/p");
    rows = GQL.execute(stmt, superuser);
    checkResultSequence(rows, new Node[] { n1, n2, n3 });
    // explicit descending
    stmt = createStatement("prop:value order:-sub/p");
    rows = GQL.execute(stmt, superuser);
    checkResultSequence(rows, new Node[] { n3, n2, n1 });
}
Also used : Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator)

Example 50 with RowIterator

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

the class ExcerptTest method testQuotedPhraseNoMatchGap.

/**
     * Verifies excerpt generation on a node property that does not contain the
     * exact quoted phrase, but contains fragments of it.
     * 
     */
public void testQuotedPhraseNoMatchGap() throws RepositoryException {
    String text = "one two three four";
    String excerpt = createExcerpt("one two three four");
    String terms = "\"two four\"";
    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

RowIterator (javax.jcr.query.RowIterator)86 Node (javax.jcr.Node)48 QueryResult (javax.jcr.query.QueryResult)45 QueryManager (javax.jcr.query.QueryManager)27 Row (javax.jcr.query.Row)27 Query (javax.jcr.query.Query)25 Test (org.junit.Test)20 Session (javax.jcr.Session)17 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)15 RepositoryException (javax.jcr.RepositoryException)12 Value (javax.jcr.Value)11 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)8 ValueFactory (javax.jcr.ValueFactory)7 ArrayList (java.util.ArrayList)5 NodeIterator (javax.jcr.NodeIterator)5 NoSuchElementException (java.util.NoSuchElementException)4 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)4 RowIteratorAdapter (org.apache.jackrabbit.commons.iterator.RowIteratorAdapter)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3