Search in sources :

Example 6 with QueryResult

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

the class ExcerptTest method testMatchMultipleNonMatchingTokens.

/**
     * <p>
     * Test when there are multiple tokens that match the fulltext search (which
     * will generate multiple lucene terms for the highlighter to use) in the
     * repository but not all of them are present in the current property.
     * </p>
     * 
     */
public void testMatchMultipleNonMatchingTokens() throws RepositoryException {
    String text = "lorem ipsum";
    String fragmentText = "lorem <strong>ipsum</strong>";
    String terms = "ipsu*";
    String excerpt = createExcerpt(fragmentText);
    // here we'll add more matching garbage data so we have more tokens
    // passed to the highlighter
    Node parent = testRootNode.addNode(nodeName1);
    Node n = parent.addNode("test");
    n.setProperty("text", text);
    testRootNode.addNode(nodeName2).setProperty("foo", "ipsuFoo");
    testRootNode.addNode(nodeName3).setProperty("bar", "ipsuBar");
    superuser.save();
    // --
    String stmt = testPath + "/" + nodeName1 + "//*[jcr:contains(., '" + terms + "')]/rep:excerpt(.)";
    QueryResult result = executeQuery(stmt);
    RowIterator rows = result.getRows();
    assertEquals(1, rows.getSize());
    assertEquals(excerpt, getExcerpt(rows.nextRow()));
}
Also used : QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator)

Example 7 with QueryResult

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

the class LimitAndOffsetTest method testOffsetAndLimit.

public void testOffsetAndLimit() throws Exception {
    query.setOffset(0);
    query.setLimit(1);
    QueryResult result = query.execute();
    checkResult(result, new Node[] { node1 });
    query.setOffset(1);
    query.setLimit(1);
    result = query.execute();
    checkResult(result, new Node[] { node2 });
    query.setOffset(1);
    query.setLimit(2);
    result = query.execute();
    checkResult(result, new Node[] { node2, node3 });
    query.setOffset(0);
    query.setLimit(2);
    result = query.execute();
    checkResult(result, new Node[] { node1, node2 });
    // Added for JCR-1323
    query.setOffset(0);
    query.setLimit(4);
    result = query.execute();
    checkResult(result, new Node[] { node1, node2, node3 });
}
Also used : QueryResult(javax.jcr.query.QueryResult) JackrabbitQueryResult(org.apache.jackrabbit.api.query.JackrabbitQueryResult)

Example 8 with QueryResult

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

the class LimitAndOffsetTest method testOffsetAndLimitWithGetSize.

public void testOffsetAndLimitWithGetSize() throws Exception {
    query.setOffset(1);
    QueryResult result = query.execute();
    NodeIterator nodes = result.getNodes();
    assertEquals(2, nodes.getSize());
    if (result instanceof JackrabbitQueryResult) {
        assertEquals(3, ((JackrabbitQueryResult) result).getTotalSize());
    }
    // JCR-2684: offset higher than total result => size == 0
    query.setOffset(10);
    result = query.execute();
    nodes = result.getNodes();
    assertFalse(nodes.hasNext());
    assertEquals(0, nodes.getSize());
    if (result instanceof JackrabbitQueryResult) {
        assertEquals(3, ((JackrabbitQueryResult) result).getTotalSize());
    }
    query.setOffset(1);
    query.setLimit(1);
    result = query.execute();
    nodes = result.getNodes();
    assertEquals(1, nodes.getSize());
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) JackrabbitQueryResult(org.apache.jackrabbit.api.query.JackrabbitQueryResult) JackrabbitQueryResult(org.apache.jackrabbit.api.query.JackrabbitQueryResult)

Example 9 with QueryResult

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

the class LimitAndOffsetTest method testOffsetAndSkip.

public void testOffsetAndSkip() throws Exception {
    query.setOffset(1);
    QueryResult result = query.execute();
    NodeIterator nodes = result.getNodes();
    nodes.skip(1);
    assertTrue(node3.isSame(nodes.nextNode()));
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) JackrabbitQueryResult(org.apache.jackrabbit.api.query.JackrabbitQueryResult)

Example 10 with QueryResult

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

the class LimitAndOffsetTest method testOffset.

public void testOffset() throws Exception {
    query.setOffset(0);
    QueryResult result = query.execute();
    checkResult(result, new Node[] { node1, node2, node3 });
    query.setOffset(1);
    result = query.execute();
    checkResult(result, new Node[] { node2, node3 });
    query.setOffset(2);
    result = query.execute();
    checkResult(result, new Node[] { node3 });
}
Also used : QueryResult(javax.jcr.query.QueryResult) JackrabbitQueryResult(org.apache.jackrabbit.api.query.JackrabbitQueryResult)

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