Search in sources :

Example 11 with RowIterator

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

the class FacetResultTest method testResult.

@Test
public void testResult() throws Exception {
    QueryResult queryResult = mock(QueryResult.class);
    when(queryResult.getColumnNames()).thenReturn(new String[] { "rep:facet(text)", "jcr:path", "rep:facet(jcr:title)" });
    RowIterator rows = mock(RowIterator.class);
    when(rows.hasNext()).thenReturn(true);
    Row row = mock(Row.class);
    Value value = mock(Value.class);
    when(value.getString()).thenReturn("{}");
    when(row.getValue("rep:facet(text)")).thenReturn(value);
    Value value2 = mock(Value.class);
    when(value2.getString()).thenReturn("{\"a\" : 2, \"b\" : 1}");
    when(row.getValue("rep:facet(jcr:title)")).thenReturn(value2);
    when(rows.nextRow()).thenReturn(row);
    when(queryResult.getRows()).thenReturn(rows);
    FacetResult facetResult = new FacetResult(queryResult);
    assertNotNull(facetResult.getDimensions());
    assertEquals(2, facetResult.getDimensions().size());
    assertTrue(facetResult.getDimensions().contains("text"));
    assertTrue(facetResult.getDimensions().contains("jcr:title"));
    assertNotNull(facetResult.getFacets("text"));
    assertTrue(facetResult.getFacets("text").isEmpty());
    assertNotNull(facetResult.getFacets("jcr:title"));
    assertEquals(2, facetResult.getFacets("jcr:title").size());
    assertEquals("a", facetResult.getFacets("jcr:title").get(0).getLabel());
    assertEquals(2, facetResult.getFacets("jcr:title").get(0).getCount(), 0);
    assertEquals("b", facetResult.getFacets("jcr:title").get(1).getLabel());
    assertEquals(1, facetResult.getFacets("jcr:title").get(1).getCount(), 0);
}
Also used : QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator) Value(javax.jcr.Value) Row(javax.jcr.query.Row) Test(org.junit.Test)

Example 12 with RowIterator

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

the class GQLTest method testAutoPrefixType.

public void testAutoPrefixType() throws RepositoryException {
    Node file = addFile(testRootNode, "file1.txt", SAMPLE_CONTENT);
    Node node = testRootNode.addNode("node1");
    node.setProperty("text", SAMPLE_CONTENT);
    superuser.save();
    // only nt:resource
    String stmt = createStatement("quick type:resource");
    checkResultWithRetries(stmt, null, new Node[] { file.getNode("jcr:content") });
    // only nt:unstructured
    stmt = createStatement("quick type:unstructured");
    RowIterator rows = GQL.execute(stmt, superuser);
    checkResult(rows, new Node[] { node });
}
Also used : Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator)

Example 13 with RowIterator

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

the class XPathQueryLevel2Test method testPathColumn.

/**
     * Test if the jcr:path pseudo property is contained in result.
     * <p>
     * For configuration description see {@link #setUpFullTextTest()}.
     */
public void testPathColumn() throws Exception {
    setUpFullTextTest();
    QueryResult result = execute(getFullTextStatement());
    RowIterator rows = result.getRows();
    if (getSize(rows) < 1) {
        fail("Query result did not return any nodes");
    }
    // re-aquire rows
    rows = result.getRows();
    // test mere existence
    rows.nextRow().getValue(jcrPath);
}
Also used : QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator)

Example 14 with RowIterator

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

the class FullTextSearchScoreTest method testOrdering.

public void testOrdering() throws RepositoryException {
    QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.and(qf.fullTextSearch("s", null, qf.literal(vf.createValue("fox"))), qf.descendantNode("s", testRootNode.getPath())), new Ordering[] { qf.ascending(qf.fullTextSearchScore("s")) }, null);
    forQOMandSQL2(qom, new Callable() {

        public Object call(Query query) throws RepositoryException {
            RowIterator rows = query.execute().getRows();
            double previousScore = Double.NaN;
            while (rows.hasNext()) {
                double score = rows.nextRow().getScore("s");
                if (!Double.isNaN(previousScore)) {
                    assertTrue("wrong order", previousScore <= score);
                }
                previousScore = score;
            }
            return null;
        }
    });
}
Also used : Query(javax.jcr.query.Query) RowIterator(javax.jcr.query.RowIterator) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) RepositoryException(javax.jcr.RepositoryException)

Example 15 with RowIterator

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

the class QueryEngine method execute.

protected QueryResult execute(Column[] columns, Selector selector, Constraint constraint, Ordering[] orderings, long offset, long limit, int printIndentation) throws RepositoryException {
    long time = System.currentTimeMillis();
    Map<String, NodeType> selectorMap = getSelectorNames(selector);
    String[] selectorNames = selectorMap.keySet().toArray(new String[selectorMap.size()]);
    Map<String, PropertyValue> columnMap = getColumnMap(columns, selectorMap);
    String[] columnNames = columnMap.keySet().toArray(new String[columnMap.size()]);
    Sort sort = new Sort();
    if (NATIVE_SORT) {
        sort = new Sort(createSortFields(orderings, session));
    }
    // if true it means that the LuceneQueryFactory should just let the
    // QueryEngine take care of sorting and applying offset and limit
    // constraints
    boolean externalSort = !NATIVE_SORT;
    RowIterator rows = null;
    try {
        rows = new RowIteratorAdapter(lqf.execute(columnMap, selector, constraint, sort, externalSort, offset, limit));
    } catch (IOException e) {
        throw new RepositoryException("Failed to access the query index", e);
    } finally {
        log.debug("{}SQL2 SELECT took {} ms. selector: {}, columns: {}, constraint: {}, offset {}, limit {}", new Object[] { genString(printIndentation), System.currentTimeMillis() - time, selector, Arrays.toString(columnNames), constraint, offset, limit });
    }
    QueryResult result = new SimpleQueryResult(columnNames, selectorNames, rows);
    if (NATIVE_SORT) {
        return result;
    }
    long timeSort = System.currentTimeMillis();
    QueryResult sorted = sort(result, orderings, evaluator, offset, limit);
    log.debug("{}SQL2 SORT took {} ms.", genString(printIndentation), System.currentTimeMillis() - timeSort);
    return sorted;
}
Also used : PropertyValue(javax.jcr.query.qom.PropertyValue) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) QueryResult(javax.jcr.query.QueryResult) RowIteratorAdapter(org.apache.jackrabbit.commons.iterator.RowIteratorAdapter) NodeType(javax.jcr.nodetype.NodeType) RowIterator(javax.jcr.query.RowIterator) Sort(org.apache.lucene.search.Sort)

Aggregations

RowIterator (javax.jcr.query.RowIterator)86 Node (javax.jcr.Node)48 QueryResult (javax.jcr.query.QueryResult)45 QueryManager (javax.jcr.query.QueryManager)27 Row (javax.jcr.query.Row)27 Query (javax.jcr.query.Query)25 Test (org.junit.Test)20 Session (javax.jcr.Session)17 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)15 RepositoryException (javax.jcr.RepositoryException)12 Value (javax.jcr.Value)11 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)8 ValueFactory (javax.jcr.ValueFactory)7 ArrayList (java.util.ArrayList)5 NodeIterator (javax.jcr.NodeIterator)5 NoSuchElementException (java.util.NoSuchElementException)4 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)4 RowIteratorAdapter (org.apache.jackrabbit.commons.iterator.RowIteratorAdapter)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3