use of org.exist.dom.persistent.DocumentSet in project exist by eXist-db.
the class NGramSearch method preSelect.
@Override
public NodeSet preSelect(Sequence contextSequence, boolean useContext) throws XPathException {
// the expression can be called multiple times, so we need to clear the previous preselectResult
preselectResult = null;
long start = System.currentTimeMillis();
NGramIndexWorker index = (NGramIndexWorker) context.getBroker().getIndexController().getWorkerByIndexId(NGramIndex.ID);
DocumentSet docs = contextSequence.getDocumentSet();
String key = getArgument(1).eval(contextSequence).getStringValue();
List<QName> qnames = new ArrayList<>(1);
qnames.add(contextQName);
preselectResult = processMatches(index, docs, qnames, key, useContext ? contextSequence.toNodeSet() : null, NodeSet.DESCENDANT);
if (context.getProfiler().traceFunctions()) {
// report index use
context.getProfiler().traceIndexUsage(context, "ngram", this, PerformanceStats.OPTIMIZED_INDEX, System.currentTimeMillis() - start);
}
return preselectResult;
}
use of org.exist.dom.persistent.DocumentSet in project exist by eXist-db.
the class FieldLookup method preSelect.
@Override
public NodeSet preSelect(Sequence contextSequence, boolean useContext) throws XPathException {
if (contextSequence != null && !contextSequence.isPersistentSet())
// in-memory docs won't have an index
return NodeSet.EMPTY_SET;
long start = System.currentTimeMillis();
// the expression can be called multiple times, so we need to clear the previous preselectResult
preselectResult = null;
Sequence fieldSeq = getArgument(0).eval(contextSequence);
RangeIndex.Operator[] operators = null;
int j = 1;
if (isCalledAs("field")) {
Sequence operatorSeq = getArgument(1).eval(contextSequence);
operators = new RangeIndex.Operator[operatorSeq.getItemCount()];
int i = 0;
for (SequenceIterator si = operatorSeq.iterate(); si.hasNext(); i++) {
operators[i] = RangeIndexModule.OPERATOR_MAP.get(si.nextItem().getStringValue());
}
j++;
} else {
RangeIndex.Operator operator = getOperator();
operators = new RangeIndex.Operator[fieldSeq.getItemCount()];
Arrays.fill(operators, operator);
}
Sequence[] keys = new Sequence[getArgumentCount() - j];
for (int i = j; i < getArgumentCount(); i++) {
keys[i - j] = Atomize.atomize(getArgument(i).eval(contextSequence));
}
DocumentSet docs = contextSequence.getDocumentSet();
RangeIndexWorker index = (RangeIndexWorker) context.getBroker().getIndexController().getWorkerByIndexId(RangeIndex.ID);
try {
preselectResult = index.queryField(getExpressionId(), docs, useContext ? contextSequence.toNodeSet() : null, fieldSeq, keys, operators, NodeSet.DESCENDANT);
} catch (IOException e) {
throw new XPathException(this, "Error while querying full text index: " + e.getMessage(), e);
}
LOG.info("preselect for {} on {}returned {} and took {}", Arrays.toString(keys), contextSequence.getItemCount(), preselectResult.getItemCount(), System.currentTimeMillis() - start);
if (context.getProfiler().traceFunctions()) {
context.getProfiler().traceIndexUsage(context, "new-range", this, PerformanceStats.OPTIMIZED_INDEX, System.currentTimeMillis() - start);
}
// preselectResult.setSelfAsContext(getContextId());
return preselectResult;
}
use of org.exist.dom.persistent.DocumentSet in project exist by eXist-db.
the class NativeStructuralIndexWorkerTest method getDocIdRanges_singleId_followed_by_continguousIds.
@Test
public void getDocIdRanges_singleId_followed_by_continguousIds() {
final NativeStructuralIndexWorker indexWorker = new NativeStructuralIndexWorker(null);
final DocumentSet docs = documentIdSet(Arrays.asList(6574, 11, 12, 13, 14, 15));
final List<NativeStructuralIndexWorker.Range> ranges = indexWorker.getDocIdRanges(docs);
assertEquals(2, ranges.size());
assertEquals(6574, ranges.get(0).start);
assertEquals(6574, ranges.get(0).end);
assertEquals(11, ranges.get(1).start);
assertEquals(15, ranges.get(1).end);
}
use of org.exist.dom.persistent.DocumentSet in project exist by eXist-db.
the class NativeStructuralIndexWorkerTest method getDocIdRanges_multiple_singleIds.
@Test
public void getDocIdRanges_multiple_singleIds() {
final NativeStructuralIndexWorker indexWorker = new NativeStructuralIndexWorker(null);
final DocumentSet docs = documentIdSet(Arrays.asList(6574, 200, 12, 24));
final List<NativeStructuralIndexWorker.Range> ranges = indexWorker.getDocIdRanges(docs);
assertEquals(4, ranges.size());
assertEquals(6574, ranges.get(0).start);
assertEquals(6574, ranges.get(0).end);
assertEquals(200, ranges.get(1).start);
assertEquals(200, ranges.get(1).end);
assertEquals(12, ranges.get(2).start);
assertEquals(12, ranges.get(2).end);
assertEquals(24, ranges.get(3).start);
assertEquals(24, ranges.get(3).end);
}
use of org.exist.dom.persistent.DocumentSet in project exist by eXist-db.
the class NativeStructuralIndexWorkerTest method getDocIdRanges_singleContiguous.
@Test
public void getDocIdRanges_singleContiguous() {
final NativeStructuralIndexWorker indexWorker = new NativeStructuralIndexWorker(null);
final DocumentSet docs = documentIdSet(Arrays.asList(1, 2, 3, 4, 5, 6));
final List<NativeStructuralIndexWorker.Range> ranges = indexWorker.getDocIdRanges(docs);
assertEquals(1, ranges.size());
assertEquals(1, ranges.get(0).start);
assertEquals(6, ranges.get(0).end);
}
Aggregations