Search in sources :

Example 86 with QueryResult

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

the class FullTextSearchTest method runTest.

@SuppressWarnings("deprecation")
@Override
protected void runTest(TestContext ec) throws Exception {
    QueryManager qm = ec.session.getWorkspace().getQueryManager();
    // like > 20% of the perf lost in Collections.sort
    for (String word : ec.words) {
        Query q = qm.createQuery("//*[jcr:contains(@text, '" + word + "')] ", Query.XPATH);
        QueryResult r = q.execute();
        RowIterator it = r.getRows();
        for (int rows = 0; it.hasNext() && rows < maxRowsToFetch; rows++) {
            Node n = it.nextRow().getNode();
            ec.hash += n.getProperty("text").getString().hashCode();
            ec.hash += n.getProperty("title").getString().hashCode();
        }
    }
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) RowIterator(javax.jcr.query.RowIterator) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager)

Example 87 with QueryResult

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

the class MassiveRangeTest method testRangeQuery.

/**
     * Executes a range query covering 2'000 different property values.
     */
public void testRangeQuery() throws RepositoryException {
    int count = 0;
    for (int i = 0; i < 20; i++) {
        Node child = testRootNode.addNode("node" + i);
        for (int j = 0; j < 100; j++) {
            Node n = child.addNode("node" + j);
            n.setProperty("foo", count++);
        }
        // save every 100 nodes
        testRootNode.save();
    }
    QueryManager qm = superuser.getWorkspace().getQueryManager();
    String stmt = testPath + "//*[@foo >= 0]";
    QueryResult res = qm.createQuery(stmt, Query.XPATH).execute();
    checkResult(res, 2000);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager)

Example 88 with QueryResult

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

the class FacetTest method testFacetRetrieval.

public void testFacetRetrieval() throws Exception {
    Session session = superuser;
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("text", "hello");
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("text", "hallo");
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty("text", "oh hallo");
    session.save();
    QueryManager qm = session.getWorkspace().getQueryManager();
    String sql2 = "select [jcr:path], [rep:facet(text)] from [nt:base] " + "where contains([text], 'hello OR 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("text"));
    List<FacetResult.Facet> facets = facetResult.getFacets("text");
    assertNotNull(facets);
    assertEquals("hallo", facets.get(0).getLabel());
    assertEquals(1, facets.get(0).getCount(), 0);
    assertEquals("hello", facets.get(1).getLabel());
    assertEquals(1, facets.get(1).getCount(), 0);
    assertEquals("oh hallo", facets.get(2).getLabel());
    assertEquals(1, facets.get(2).getCount(), 0);
    NodeIterator nodes = result.getNodes();
    assertTrue(nodes.hasNext());
    assertNotNull(nodes.nextNode());
    assertTrue(nodes.hasNext());
    assertNotNull(nodes.nextNode());
    assertTrue(nodes.hasNext());
    assertNotNull(nodes.nextNode());
    assertFalse(nodes.hasNext());
}
Also used : NodeIterator(javax.jcr.NodeIterator) 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 89 with QueryResult

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

the class FacetTest method testFacetRetrievalMV.

public void testFacetRetrievalMV() throws Exception {
    Session session = superuser;
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("jcr:title", "apache jackrabbit oak");
    n1.setProperty("tags", new String[] { "software", "repository", "apache" });
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("jcr:title", "oak furniture");
    n2.setProperty("tags", "furniture");
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty("jcr:title", "oak cosmetics");
    n3.setProperty("tags", "cosmetics");
    Node n4 = testRootNode.addNode("node4");
    n4.setProperty("jcr:title", "oak and aem");
    n4.setProperty("tags", new String[] { "software", "repository", "aem" });
    session.save();
    QueryManager qm = session.getWorkspace().getQueryManager();
    String sql2 = "select [jcr:path], [rep:facet(tags)] from [nt:base] " + "where contains([jcr:title], 'oak') 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("tags"));
    List<FacetResult.Facet> facets = facetResult.getFacets("tags");
    assertNotNull(facets);
    assertEquals("repository", facets.get(0).getLabel());
    assertEquals(2, facets.get(0).getCount(), 0);
    assertEquals("software", facets.get(1).getLabel());
    assertEquals(2, facets.get(1).getCount(), 0);
    assertEquals("aem", facets.get(2).getLabel());
    assertEquals(1, facets.get(2).getCount(), 0);
    assertEquals("apache", facets.get(3).getLabel());
    assertEquals(1, facets.get(3).getCount(), 0);
    assertEquals("cosmetics", facets.get(4).getLabel());
    assertEquals(1, facets.get(4).getCount(), 0);
    assertEquals("furniture", facets.get(5).getLabel());
    assertEquals(1, facets.get(5).getCount(), 0);
    NodeIterator nodes = result.getNodes();
    assertTrue(nodes.hasNext());
    assertNotNull(nodes.nextNode());
    assertTrue(nodes.hasNext());
    assertNotNull(nodes.nextNode());
    assertTrue(nodes.hasNext());
    assertNotNull(nodes.nextNode());
    assertTrue(nodes.hasNext());
    assertNotNull(nodes.nextNode());
    assertFalse(nodes.hasNext());
}
Also used : NodeIterator(javax.jcr.NodeIterator) 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 90 with QueryResult

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

the class LuceneIndexDescendantSpellcheckTest method getSpellchecks.

private Set<String> getSpellchecks(String query) throws Exception {
    QueryManager queryManager = session.getWorkspace().getQueryManager();
    QueryResult result = queryManager.createQuery(query, Query.JCR_SQL2).execute();
    RowIterator rows = result.getRows();
    Set<String> suggestions = newHashSet();
    while (rows.hasNext()) {
        suggestions.add(rows.nextRow().getValue("spellcheck").getString());
    }
    return suggestions;
}
Also used : QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator) QueryManager(javax.jcr.query.QueryManager)

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