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);
}
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 });
}
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);
}
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;
}
});
}
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;
}
Aggregations