Search in sources :

Example 76 with QueryResult

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

the class AbstractQueryTest method executeSQLQuery.

/**
     * Executes the <code>sql</code> query and checks the results against
     * the specified <code>nodes</code>.
     * @param sql the sql query.
     * @param nodes the expected result nodes.
     * @throws RepositoryException if an error occurs while executing the query
     *                             or checking the result.
     */
protected void executeSQLQuery(String sql, Node[] nodes) throws RepositoryException {
    QueryResult res = qm.createQuery(sql, Query.SQL).execute();
    checkResult(res, nodes);
}
Also used : QueryResult(javax.jcr.query.QueryResult)

Example 77 with QueryResult

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

the class FulltextQueryTest method testFulltextOrSQL.

public void testFulltextOrSQL() throws Exception {
    Node n = testRootNode.addNode("node1");
    n.setProperty("title", new String[] { "test text" });
    n.setProperty("mytext", new String[] { "the quick brown fox jumps over the lazy dog." });
    n = testRootNode.addNode("node2");
    n.setProperty("title", new String[] { "other text" });
    n.setProperty("mytext", new String[] { "the quick brown fox jumps over the lazy dog." });
    testRootNode.save();
    String sql = "SELECT * FROM nt:unstructured" + " WHERE \"jcr:path\" LIKE '" + testRoot + "/%" + "' AND CONTAINS(., '''fox jumps'' test OR other')";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    QueryResult result = q.execute();
    checkResult(result, 2);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node)

Example 78 with QueryResult

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

the class FulltextQueryTest method testFulltextPhraseSQL.

public void testFulltextPhraseSQL() throws Exception {
    Node n = testRootNode.addNode("node1");
    n.setProperty("title", new String[] { "test text" });
    n.setProperty("mytext", new String[] { "the quick brown jumps fox over the lazy dog." });
    n = testRootNode.addNode("node2");
    n.setProperty("title", new String[] { "other text" });
    n.setProperty("mytext", new String[] { "the quick brown fox jumps over the lazy dog." });
    testRootNode.save();
    String sql = "SELECT * FROM nt:unstructured" + " WHERE \"jcr:path\" LIKE '" + testRoot + "/%" + "' AND CONTAINS(., 'text \"fox jumps\"')";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    QueryResult result = q.execute();
    checkResult(result, 1);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node)

Example 79 with QueryResult

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

the class FulltextQueryTest method testFulltextIntercapSQL.

public void testFulltextIntercapSQL() throws Exception {
    Node n = testRootNode.addNode("node1");
    n.setProperty("title", new String[] { "tEst text" });
    n.setProperty("mytext", new String[] { "The quick brown Fox jumps over the lazy dog." });
    n = testRootNode.addNode("node2");
    n.setProperty("title", new String[] { "Other text" });
    n.setProperty("mytext", new String[] { "the quick brown FOX jumPs over the lazy dog." });
    testRootNode.save();
    String sql = "SELECT * FROM nt:unstructured" + " WHERE \"jcr:path\" LIKE '" + testRoot + "/%" + "' AND CONTAINS(., '''fox juMps'' Test OR otheR')";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    QueryResult result = q.execute();
    checkResult(result, 2);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node)

Example 80 with QueryResult

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

QueryResult (javax.jcr.query.QueryResult)202 Node (javax.jcr.Node)109 Query (javax.jcr.query.Query)98 QueryManager (javax.jcr.query.QueryManager)55 NodeIterator (javax.jcr.NodeIterator)52 RowIterator (javax.jcr.query.RowIterator)46 Session (javax.jcr.Session)36 Test (org.junit.Test)32 Row (javax.jcr.query.Row)21 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)21 RepositoryException (javax.jcr.RepositoryException)15 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)15 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