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;
}
use of javax.jcr.query.RowIterator in project jackrabbit by apache.
the class SimpleQueryResult method getRows.
/**
* Returns the query result rows.
*
* @return query result rows
* @throws RepositoryException if the query results have already
* been iterated through
*/
public synchronized RowIterator getRows() throws RepositoryException {
if (rowIterator != null) {
RowIterator iterator = rowIterator;
rowIterator = null;
return iterator;
} else {
throw new RepositoryException("This query result has already been iterated through");
}
}
use of javax.jcr.query.RowIterator in project jackrabbit by apache.
the class SQL2OrderByTest method testOrderByScore.
public void testOrderByScore() throws RepositoryException {
Node n1 = testRootNode.addNode("node1");
Node n2 = testRootNode.addNode("node2");
Node n3 = testRootNode.addNode("node3");
n1.setProperty("text", "aaa");
n1.setProperty("value", 3);
testRootNode.getSession().save();
n2.setProperty("text", "bbb");
n2.setProperty("value", 2);
testRootNode.getSession().save();
n3.setProperty("text", "ccc");
n3.setProperty("value", 2);
testRootNode.getSession().save();
QueryResult qr = executeSQL2Query("SELECT * FROM [nt:base] WHERE ISCHILDNODE([" + testRoot + "]) ORDER BY SCORE()");
RowIterator rows = qr.getRows();
long size = rows.getSize();
assertTrue(size == 3 || size == -1);
size = 0;
double score = Double.MIN_VALUE;
while (rows.hasNext()) {
double nextScore = rows.nextRow().getScore();
assertTrue(nextScore >= score);
score = nextScore;
size++;
}
assertEquals(3, size);
}
Aggregations