if (args[3].hasOne())
{max = ((IntegerValue) args[3].itemAt(0)).getInt();}
final Sequence result = new ValueSequence();
// if we have 5 arguments, query the user-specified index
if (this.getArgumentCount() == 5) {
final IndexWorker indexWorker = context.getBroker().getIndexController().getWorkerByIndexName(args[4].itemAt(0).getStringValue());
//Alternate design
//IndexWorker indexWorker = context.getBroker().getBrokerPool().getIndexManager().getIndexByName(args[4].itemAt(0).getStringValue()).getWorker();
if (indexWorker == null)
{throw new XPathException(this, "Unknown index: " + args[4].itemAt(0).getStringValue());}
final Map<String, Object> hints = new HashMap<String, Object>();
if (max != -1)
{hints.put(IndexWorker.VALUE_COUNT, new IntegerValue(max));}
if (indexWorker instanceof OrderedValuesIndex)
{hints.put(OrderedValuesIndex.START_VALUE, args[1].getStringValue());}
else
{logger.warn(indexWorker.getClass().getName() + " isn't an instance of org.exist.indexing.OrderedIndexWorker. Start value '" + args[1] + "' ignored." );}
if (qnames != null) {
final List<QName> qnameList = new ArrayList<QName>(qnames.getItemCount());
for (final SequenceIterator i = qnames.iterate(); i.hasNext();) {
final QNameValue qv = (QNameValue) i.nextItem();
qnameList.add(qv.getQName());
}
hints.put(QNamedKeysIndex.QNAMES_KEY, qnameList);
}
final Occurrences[] occur = indexWorker.scanIndex(context, docs, nodes, hints);
//TODO : add an extra argument to pass the END_VALUE ?
final int len = (max != -1 && occur.length > max ? max : occur.length);
final Sequence params[] = new Sequence[2];
ValueSequence data = new ValueSequence();
for (int j = 0; j < len; j++) {