use of org.exist.indexing.range.RangeIndexWorker in project exist by eXist-db.
the class Lookup method preSelect.
@Override
public NodeSet preSelect(Sequence contextSequence, boolean useContext) throws XPathException {
if (!canOptimize) {
return ((Optimizable) fallback).preSelect(contextSequence, useContext);
}
if (contextSequence != null && !contextSequence.isPersistentSet())
// in-memory docs won't have an index
return NodeSet.EMPTY_SET;
// throw an exception if substring match operation is applied to collated index
final RangeIndex.Operator operator = getOperator();
if (usesCollation && !operator.supportsCollation()) {
throw new XPathException(this, RangeIndexModule.EXXQDYFT0001, "Index defines a collation which cannot be " + "used with the '" + operator + "' operation.");
}
long start = System.currentTimeMillis();
// the expression can be called multiple times, so we need to clear the previous preselectResult
preselectResult = null;
RangeIndexWorker index = (RangeIndexWorker) context.getBroker().getIndexController().getWorkerByIndexId(RangeIndex.ID);
DocumentSet docs = contextSequence.getDocumentSet();
AtomicValue[] keys = getKeys(contextSequence);
if (keys.length == 0) {
return NodeSet.EMPTY_SET;
}
List<QName> qnames = null;
if (contextQName != null) {
qnames = new ArrayList<>(1);
qnames.add(contextQName);
}
try {
preselectResult = index.query(getExpressionId(), docs, contextSequence.toNodeSet(), qnames, keys, operator, NodeSet.DESCENDANT);
} catch (XPathException | IOException e) {
throw new XPathException(this, "Error while querying full text index: " + e.getMessage(), e);
}
// " and took " + (System.currentTimeMillis() - start));
if (context.getProfiler().traceFunctions()) {
context.getProfiler().traceIndexUsage(context, "new-range", this, PerformanceStats.OPTIMIZED_INDEX, System.currentTimeMillis() - start);
}
if (preselectResult == null) {
preselectResult = NodeSet.EMPTY_SET;
}
return preselectResult;
}
Aggregations