Search in sources :

Example 1 with RowIterator

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

the class LazyResultSetQueryTest method readResult.

private void readResult(QueryResult result, int count) throws RepositoryException {
    for (RowIterator rows = result.getRows(); rows.hasNext(); ) {
        rows.nextRow();
        count--;
    }
    assertEquals(0, count);
}
Also used : RowIterator(javax.jcr.query.RowIterator)

Example 2 with RowIterator

use of javax.jcr.query.RowIterator 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 3 with RowIterator

use of javax.jcr.query.RowIterator 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)

Example 4 with RowIterator

use of javax.jcr.query.RowIterator 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 5 with RowIterator

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

the class ExcerptTest method testEncodeIllegalCharsNoHighlights.

/**
     * Verifies character encoding on a node property that does not contain any
     * excerpt info
     */
public void testEncodeIllegalCharsNoHighlights() throws RepositoryException {
    String text = "bla <strong>bla</strong> bla";
    String excerpt = createExcerpt("bla &lt;strong&gt;bla&lt;/strong&gt; bla");
    Node n = testRootNode.addNode(nodeName1);
    n.setProperty("text", text);
    n.setProperty("other", "foo");
    superuser.save();
    String stmt = getStatement("foo");
    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