try {
JackrabbitIndexSearcher searcher = new JackrabbitIndexSearcher(
session, reader, index.getContext().getItemStateManager());
searcher.setSimilarity(index.getSimilarity());
Predicate filter = Predicate.TRUE;
BooleanQuery query = new BooleanQuery();
QueryPair qp = new QueryPair(query);
query.add(create(selector), MUST);
if (constraint != null) {
String name = selector.getSelectorName();
NodeType type =
ntManager.getNodeType(selector.getNodeTypeName());
filter = mapConstraintToQueryAndFilter(qp,
constraint, Collections.singletonMap(name, type),
searcher, reader);
}
List<Row> rows = new ArrayList<Row>();
// TODO depending on the filters, we could push the offset info
// into the searcher
hits = searcher.evaluate(qp.mainQuery, sort, offset + limit);
int currentNode = 0;
int addedNodes = 0;
ScoreNode node = hits.nextScoreNode();
while (node != null) {
Row row = null;
try {
row = new SelectorRow(columns, evaluator,
selector.getSelectorName(),
session.getNodeById(node.getNodeId()),
node.getScore());
} catch (ItemNotFoundException e) {
// skip the node
}
if (row != null && filter.evaluate(row)) {
if (externalSort) {
// return everything and not worry about sort
rows.add(row);
} else {
// apply limit and offset rules locally