Search in sources :

Example 31 with Node

use of javax.jcr.Node 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 32 with Node

use of javax.jcr.Node 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 33 with Node

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

Example 34 with Node

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

Example 35 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class FnNameQueryTest method testSimple.

public void testSimple() throws RepositoryException {
    Node n1 = testRootNode.addNode(nodeName1);
    n1.setProperty(propertyName1, 1);
    Node n2 = testRootNode.addNode(nodeName2);
    n2.setProperty(propertyName1, 2);
    Node n3 = testRootNode.addNode(nodeName3);
    n3.setProperty(propertyName1, 3);
    superuser.save();
    String base = testPath + "/*[@" + propertyName1;
    executeXPathQuery(base + " = 1 and fn:name() = '" + nodeName1 + "']", new Node[] { n1 });
    executeXPathQuery(base + " = 1 and fn:name() = '" + nodeName2 + "']", new Node[] {});
    executeXPathQuery(base + " > 0 and fn:name() = '" + nodeName2 + "']", new Node[] { n2 });
    executeXPathQuery(base + " > 0 and (fn:name() = '" + nodeName1 + "' or fn:name() = '" + nodeName2 + "')]", new Node[] { n1, n2 });
    executeXPathQuery(base + " > 0 and not(fn:name() = '" + nodeName1 + "')]", new Node[] { n2, n3 });
}
Also used : Node(javax.jcr.Node)

Aggregations

Node (javax.jcr.Node)2620 Session (javax.jcr.Session)645 Test (org.junit.Test)643 RepositoryException (javax.jcr.RepositoryException)317 Property (javax.jcr.Property)251 NodeIterator (javax.jcr.NodeIterator)214 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)182 Value (javax.jcr.Value)158 Version (javax.jcr.version.Version)155 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)151 Query (javax.jcr.query.Query)122 QueryResult (javax.jcr.query.QueryResult)108 Event (javax.jcr.observation.Event)103 VersionManager (javax.jcr.version.VersionManager)97 Resource (org.apache.sling.api.resource.Resource)96 ArrayList (java.util.ArrayList)93 AccessDeniedException (javax.jcr.AccessDeniedException)89 InvalidItemStateException (javax.jcr.InvalidItemStateException)82 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)82 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)81