Search in sources :

Example 6 with Query

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

the class FulltextQueryTest method testContainsStarSQL.

public void testContainsStarSQL() throws RepositoryException {
    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[] { "The quick brown Fox jumps over the lazy dog." });
    n.setProperty("mytext", new String[] { "text text" });
    testRootNode.save();
    String sql = "SELECT * FROM nt:unstructured" + " WHERE jcr:path LIKE '" + testRoot + "/%" + "' AND CONTAINS(., 'fox jumps')";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    checkResult(q.execute(), 2);
}
Also used : Query(javax.jcr.query.Query) Node(javax.jcr.Node)

Example 7 with Query

use of javax.jcr.query.Query 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 8 with Query

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

the class FulltextQueryTest method testContainsStarXPath.

public void testContainsStarXPath() throws RepositoryException {
    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[] { "The quick brown Fox jumps over the lazy dog." });
    n.setProperty("mytext", new String[] { "text text" });
    testRootNode.save();
    String sql = "/jcr:root" + testRoot + "/element(*, nt:unstructured)" + "[jcr:contains(., 'quick fox')]";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.XPATH);
    checkResult(q.execute(), 2);
}
Also used : Query(javax.jcr.query.Query) Node(javax.jcr.Node)

Example 9 with Query

use of javax.jcr.query.Query 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 10 with Query

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

the class FulltextQueryTest method testContainsPropScopeSQL.

public void testContainsPropScopeSQL() throws RepositoryException {
    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[] { "The quick brown Fox jumps over the lazy dog." });
    n.setProperty("mytext", new String[] { "text text" });
    testRootNode.save();
    String sql = "SELECT * FROM nt:unstructured" + " WHERE jcr:path LIKE '" + testRoot + "/%" + "' AND CONTAINS(title, 'fox jumps')";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    checkResult(q.execute(), 1);
}
Also used : Query(javax.jcr.query.Query) Node(javax.jcr.Node)

Aggregations

Query (javax.jcr.query.Query)198 Node (javax.jcr.Node)122 QueryResult (javax.jcr.query.QueryResult)97 QueryManager (javax.jcr.query.QueryManager)68 Session (javax.jcr.Session)58 NodeIterator (javax.jcr.NodeIterator)40 Test (org.junit.Test)35 RowIterator (javax.jcr.query.RowIterator)26 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)24 RepositoryException (javax.jcr.RepositoryException)20 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)15 InvalidQueryException (javax.jcr.query.InvalidQueryException)13 ArrayList (java.util.ArrayList)11 Row (javax.jcr.query.Row)9 FacetResult (org.apache.jackrabbit.oak.query.facet.FacetResult)9 ValueFactory (javax.jcr.ValueFactory)8 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)7 Value (javax.jcr.Value)6 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)5 Name (org.apache.jackrabbit.spi.Name)4