public NodeSet search(int contextId, DocumentSet docs, List<QName> qnames, String query, String ngram, XQueryContext context, NodeSet contextSet, int axis)
throws XPathException {
if (qnames == null || qnames.isEmpty())
qnames = getDefinedIndexes(context.getBroker(), docs);
final NodeSet result = new ExtArrayNodeSet(docs.getDocumentCount(), 250);
for (Iterator<org.exist.collections.Collection> iter = docs.getCollectionIterator(); iter.hasNext();) {
final int collectionId = iter.next().getId();
for (int i = 0; i < qnames.size(); i++) {
QName qname = qnames.get(i);
NGramQNameKey key = new NGramQNameKey(collectionId, qname, index.getBrokerPool().getSymbols(), query);
final Lock lock = index.db.getLock();
try {
lock.acquire(Lock.READ_LOCK);
SearchCallback cb = new SearchCallback(contextId, query, ngram, docs, contextSet, context, result, axis == NodeSet.ANCESTOR);
int op = query.codePointCount(0, query.length()) < getN() ? IndexQuery.TRUNC_RIGHT : IndexQuery.EQ;
index.db.query(new IndexQuery(op, key), cb);
} catch (LockException e) {
LOG.warn("Failed to acquire lock for '" + index.db.getFile().getName() + "'", e);
} catch (IOException e) {
LOG.error(e.getMessage() + " in '" + index.db.getFile().getName() + "'", e);
} catch (BTreeException e) {
LOG.error(e.getMessage() + " in '" + index.db.getFile().getName() + "'", e);
} finally {
lock.release(Lock.READ_LOCK);
}
}
}
result.iterate(); // ensure result is ready to use
return result;
}