Search in sources :

Example 41 with QueryManager

use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.

the class QomTest method before.

@Before
public void before() throws RepositoryException {
    Session session = getAdminSession();
    vf = session.getValueFactory();
    QueryManager qm = session.getWorkspace().getQueryManager();
    f = qm.getQOMFactory();
}
Also used : QueryManager(javax.jcr.query.QueryManager) Session(javax.jcr.Session) Before(org.junit.Before)

Example 42 with QueryManager

use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.

the class QueryFulltextTest method testScoreWithOr.

public void testScoreWithOr() throws Exception {
    Session session = superuser;
    QueryManager qm = session.getWorkspace().getQueryManager();
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("text", "hello");
    n1.setProperty("id", "1");
    session.save();
    String xpath = "/jcr:root//*[jcr:contains(@text, 'hello') or @id = '1']";
    Query q = qm.createQuery(xpath, "xpath");
    String result = getResult(q.execute(), "jcr:path");
    assertEquals("/testroot/node1", result);
}
Also used : Query(javax.jcr.query.Query) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager) Session(javax.jcr.Session)

Example 43 with QueryManager

use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.

the class QueryFulltextTest method testSurrogateFulltext.

public void testSurrogateFulltext() throws Exception {
    String surrogateString = "壱\n" + "複数の文字\n" + "カナポ\n" + "ハンカクポ\n" + "表十ソ\n" + "𠮟\n" + "Mixあポピ表𠮟" + "";
    String[] searchStrs = new String[] { "𠮟", "Mix" };
    Session session = superuser;
    QueryManager qm = session.getWorkspace().getQueryManager();
    Node n1 = testRootNode.addNode("node");
    n1.setProperty("text", surrogateString);
    session.save();
    for (String searchTerm : searchStrs) {
        String sql2 = "select [jcr:path] as [path] from [nt:base] " + "where contains([text], '" + searchTerm + "') order by [jcr:path]";
        Query q = qm.createQuery(sql2, Query.JCR_SQL2);
        log.println("Testing" + searchTerm);
        assertEquals("Lookup failed for " + searchTerm, "/testroot/node", getResult(q.execute(), "path"));
    }
}
Also used : Query(javax.jcr.query.Query) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager) Session(javax.jcr.Session)

Example 44 with QueryManager

use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.

the class FacetTest method testFacetRetrievalNumberOfFacetsConfiguredLowerThanDefault.

public void testFacetRetrievalNumberOfFacetsConfiguredLowerThanDefault() throws RepositoryException {
    Node facetsConfig = superuser.getNode(FACET_CONFING_NODE_PATH);
    facetsConfig.setProperty(LuceneIndexConstants.PROP_FACETS_TOP_CHILDREN, 7);
    markIndexForReindex();
    superuser.save();
    superuser.refresh(true);
    Session session = superuser;
    Node n1 = testRootNode.addNode("node1");
    String pn = "jcr:title";
    n1.setProperty(pn, "hello 1");
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty(pn, "hallo 2");
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty(pn, "hallo 3");
    Node n4 = testRootNode.addNode("node4");
    n4.setProperty(pn, "hallo 4");
    Node n5 = testRootNode.addNode("node5");
    n5.setProperty(pn, "hallo 5");
    Node n6 = testRootNode.addNode("node6");
    n6.setProperty(pn, "hallo 6");
    Node n7 = testRootNode.addNode("node7");
    n7.setProperty(pn, "hallo 7");
    Node n8 = testRootNode.addNode("node8");
    n8.setProperty(pn, "hallo 8");
    Node n9 = testRootNode.addNode("node9");
    n9.setProperty(pn, "hallo 9");
    Node n10 = testRootNode.addNode("node10");
    n10.setProperty(pn, "hallo 10");
    Node n11 = testRootNode.addNode("node11");
    n11.setProperty(pn, "hallo 11");
    Node n12 = testRootNode.addNode("node12");
    n12.setProperty(pn, "hallo 12");
    session.save();
    QueryManager qm = session.getWorkspace().getQueryManager();
    String sql2 = "select [jcr:path], [rep:facet(" + pn + ")] from [nt:base] " + "where contains([" + pn + "], 'hallo') order by [jcr:path]";
    Query q = qm.createQuery(sql2, Query.JCR_SQL2);
    QueryResult result = q.execute();
    FacetResult facetResult = new FacetResult(result);
    assertNotNull(facetResult);
    assertNotNull(facetResult.getDimensions());
    assertEquals(1, facetResult.getDimensions().size());
    assertTrue(facetResult.getDimensions().contains(pn));
    List<FacetResult.Facet> facets = facetResult.getFacets(pn);
    assertNotNull(facets);
    assertEquals(7, facets.size());
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager) FacetResult(org.apache.jackrabbit.oak.query.facet.FacetResult) Session(javax.jcr.Session)

Example 45 with QueryManager

use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.

the class LuceneIndexSuggestionTest method suggestNodeName.

//OAK-3825
@Test
public void suggestNodeName() throws Exception {
    final String nodeType = "nt:unstructured";
    createSuggestIndex("lucene-suggest", nodeType, LuceneIndexConstants.PROPDEF_PROP_NODE_NAME);
    root.addNode("indexedNode", nodeType);
    session.save();
    String suggQuery = createSuggestQuery(nodeType, "indexedn");
    QueryManager queryManager = session.getWorkspace().getQueryManager();
    QueryResult result = queryManager.createQuery(suggQuery, Query.JCR_SQL2).execute();
    RowIterator rows = result.getRows();
    String value = null;
    while (rows.hasNext()) {
        Row firstRow = rows.nextRow();
        value = firstRow.getValue("suggestion").getString();
        break;
    }
    assertEquals("Node name should be suggested", "indexedNode", value);
}
Also used : QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator) QueryManager(javax.jcr.query.QueryManager) Row(javax.jcr.query.Row) Test(org.junit.Test)

Aggregations

QueryManager (javax.jcr.query.QueryManager)102 Query (javax.jcr.query.Query)68 Node (javax.jcr.Node)60 QueryResult (javax.jcr.query.QueryResult)54 Session (javax.jcr.Session)53 NodeIterator (javax.jcr.NodeIterator)34 RowIterator (javax.jcr.query.RowIterator)27 Test (org.junit.Test)27 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)22 RepositoryException (javax.jcr.RepositoryException)17 Row (javax.jcr.query.Row)14 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)14 FacetResult (org.apache.jackrabbit.oak.query.facet.FacetResult)9 ValueFactory (javax.jcr.ValueFactory)7 NoSuchElementException (java.util.NoSuchElementException)6 InvalidItemStateException (javax.jcr.InvalidItemStateException)3 Value (javax.jcr.Value)3 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2