use of org.exist.dom.persistent.DocumentSet in project exist by eXist-db.
the class FunDoc method eval.
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
if (contextItem != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
}
}
Sequence result;
final Sequence arg = getArgument(0).eval(contextSequence, contextItem);
if (arg.isEmpty()) {
result = Sequence.EMPTY_SEQUENCE;
} else {
final String path = arg.itemAt(0).getStringValue();
// }
try {
result = DocUtils.getDocument(this.context, path);
if (result.isEmpty() && context.isRaiseErrorOnFailedRetrieval()) {
throw new XPathException(this, ErrorCodes.FODC0002, "Can not access '" + path + "'", arg);
}
// TODO: we still need a final decision about this. Also check base-uri.
// if (result == Sequence.EMPTY_SEQUENCE)
// throw new XPathException(this, path + " is not an XML document");
final DocumentSet docs = result.getDocumentSet();
if (docs != null && DocumentSet.EMPTY_DOCUMENT_SET != docs) {
// only cache node sets (which have a non-empty document set)
registerUpdateListener();
}
} catch (final Exception e) {
throw new XPathException(this, ErrorCodes.FODC0005, e.getMessage(), arg, e);
}
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
use of org.exist.dom.persistent.DocumentSet in project exist by eXist-db.
the class IndexKeyDocuments method eval.
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
}
Sequence result;
if (args[0].isEmpty()) {
result = Sequence.EMPTY_SEQUENCE;
} else {
final NodeSet nodes = args[0].toNodeSet();
final DocumentSet docs = nodes.getDocumentSet();
if (this.getArgumentCount() == 3) {
final IndexWorker indexWorker = context.getBroker().getIndexController().getWorkerByIndexName(args[2].itemAt(0).getStringValue());
// IndexWorker indexWorker = context.getBroker().getBrokerPool().getIndexManager().getIndexByName(args[2].itemAt(0).getStringValue()).getWorker();
if (indexWorker == null) {
throw new XPathException(this, "Unknown index: " + args[2].itemAt(0).getStringValue());
}
final Map<String, Object> hints = new HashMap<>();
if (indexWorker instanceof OrderedValuesIndex) {
hints.put(OrderedValuesIndex.START_VALUE, args[1]);
} else {
logger.warn("{} isn't an instance of org.exist.indexing.OrderedIndexWorker. Start value '{}' ignored.", indexWorker.getClass().getName(), args[1]);
}
final Occurrences[] occur = indexWorker.scanIndex(context, docs, nodes, hints);
if (occur.length == 0) {
result = Sequence.EMPTY_SEQUENCE;
} else {
result = new IntegerValue(occur[0].getDocuments());
}
} else {
final ValueOccurrences[] occur = context.getBroker().getValueIndex().scanIndexKeys(docs, nodes, (Indexable) args[1]);
if (occur.length == 0) {
result = Sequence.EMPTY_SEQUENCE;
} else {
result = new IntegerValue(occur[0].getDocuments());
}
}
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
use of org.exist.dom.persistent.DocumentSet in project exist by eXist-db.
the class IndexKeyOccurrences method eval.
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
}
Sequence result;
if (args[0].isEmpty()) {
result = Sequence.EMPTY_SEQUENCE;
} else {
final NodeSet nodes = args[0].toNodeSet();
final DocumentSet docs = nodes.getDocumentSet();
if (this.getArgumentCount() == 3) {
final IndexWorker indexWorker = context.getBroker().getIndexController().getWorkerByIndexName(args[2].itemAt(0).getStringValue());
// IndexWorker indexWorker = context.getBroker().getBrokerPool().getIndexManager().getIndexByName(args[2].itemAt(0).getStringValue()).getWorker();
if (indexWorker == null) {
throw new XPathException(this, "Unknown index: " + args[2].itemAt(0).getStringValue());
}
final Map<String, Object> hints = new HashMap<>();
if (indexWorker instanceof OrderedValuesIndex) {
hints.put(OrderedValuesIndex.START_VALUE, args[1]);
} else {
logger.warn("{} isn't an instance of org.exist.indexing.OrderedIndexWorker. Start value '{}' ignored.", indexWorker.getClass().getName(), args[1]);
}
final Occurrences[] occur = indexWorker.scanIndex(context, docs, nodes, hints);
if (occur.length == 0) {
result = Sequence.EMPTY_SEQUENCE;
} else {
result = new IntegerValue(occur[0].getOccurrences());
}
} else {
ValueOccurrences[] occur = context.getBroker().getValueIndex().scanIndexKeys(docs, nodes, (Indexable) (args[1].itemAt(0)));
if (occur.length == 0) {
occur = context.getBroker().getValueIndex().scanIndexKeys(docs, nodes, null, (Indexable) (args[1].itemAt(0)));
}
if (occur.length == 0) {
result = Sequence.EMPTY_SEQUENCE;
} else {
result = new IntegerValue(occur[0].getOccurrences());
}
}
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
use of org.exist.dom.persistent.DocumentSet in project exist by eXist-db.
the class LuceneIndexKeys method eval.
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
final String fieldName = args[0].getStringValue();
final DocumentSet docs = contextSequence == null ? context.getStaticallyKnownDocuments() : contextSequence.getDocumentSet();
final Map<String, Object> hints = new HashMap<>();
if (!args[1].isEmpty()) {
hints.put(OrderedValuesIndex.START_VALUE, args[1].getStringValue());
}
IntegerValue max = null;
if (args[3].hasOne()) {
max = ((IntegerValue) args[3].itemAt(0));
}
if (max != null && max.getInt() > -1) {
hints.put(IndexWorker.VALUE_COUNT, max);
}
final Sequence result = new ValueSequence();
try (final FunctionReference ref = (FunctionReference) args[2].itemAt(0)) {
final LuceneIndexWorker index = (LuceneIndexWorker) context.getBroker().getIndexController().getWorkerByIndexId(LuceneIndex.ID);
final Occurrences[] occur = index.scanIndexByField(fieldName, docs, hints);
final Sequence[] params = new Sequence[2];
final ValueSequence data = new ValueSequence();
for (int j = 0; j < occur.length; j++) {
params[0] = new StringValue(occur[j].getTerm().toString());
data.add(new IntegerValue(occur[j].getOccurrences(), Type.UNSIGNED_INT));
data.add(new IntegerValue(occur[j].getDocuments(), Type.UNSIGNED_INT));
data.add(new IntegerValue(j + 1, Type.UNSIGNED_INT));
params[1] = data;
result.addAll(ref.evalFunction(Sequence.EMPTY_SEQUENCE, null, params));
data.clear();
}
}
return result;
}
use of org.exist.dom.persistent.DocumentSet in project exist by eXist-db.
the class QueryField method eval.
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
if (contextItem != null)
contextSequence = contextItem.toSequence();
NodeSet result;
if (preselectResult == null) {
long start = System.currentTimeMillis();
String field = getArgument(0).eval(contextSequence).getStringValue();
Item query = getKey(contextSequence, null);
DocumentSet docs = null;
if (contextSequence == null)
docs = context.getStaticallyKnownDocuments();
else
docs = contextSequence.getDocumentSet();
NodeSet contextSet = null;
if (contextSequence != null)
contextSet = contextSequence.toNodeSet();
LuceneIndexWorker index = (LuceneIndexWorker) context.getBroker().getIndexController().getWorkerByIndexId(LuceneIndex.ID);
QueryOptions options = parseOptions(this, contextSequence, contextItem, 3);
try {
if (Type.subTypeOf(query.getType(), Type.ELEMENT))
result = index.queryField(getExpressionId(), docs, contextSet, field, (Element) ((NodeValue) query).getNode(), NodeSet.ANCESTOR, options);
else
result = index.queryField(context, getExpressionId(), docs, contextSet, field, query.getStringValue(), NodeSet.ANCESTOR, options);
} catch (IOException e) {
throw new XPathException(this, e.getMessage());
}
if (context.getProfiler().traceFunctions()) {
context.getProfiler().traceIndexUsage(context, "lucene", this, PerformanceStats.BASIC_INDEX, System.currentTimeMillis() - start);
}
} else {
result = preselectResult.selectAncestorDescendant(contextSequence.toNodeSet(), NodeSet.DESCENDANT, true, getContextId(), true);
}
return result;
}
Aggregations