Search in sources :

Example 6 with RangeIndexWorker

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;
}
Also used : QName(org.exist.dom.QName) IOException(java.io.IOException) RangeIndexWorker(org.exist.indexing.range.RangeIndexWorker) DocumentSet(org.exist.dom.persistent.DocumentSet) RangeIndex(org.exist.indexing.range.RangeIndex)

Aggregations

RangeIndexWorker (org.exist.indexing.range.RangeIndexWorker)6 IOException (java.io.IOException)4 DocumentSet (org.exist.dom.persistent.DocumentSet)4 RangeIndex (org.exist.indexing.range.RangeIndex)4 QName (org.exist.dom.QName)2 NodeSet (org.exist.dom.persistent.NodeSet)2 VirtualNodeSet (org.exist.dom.persistent.VirtualNodeSet)1 Occurrences (org.exist.util.Occurrences)1