Search in sources :

Example 31 with DocumentSet

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;
}
Also used : QName(org.exist.dom.QName) NGramIndexWorker(org.exist.indexing.ngram.NGramIndexWorker) DocumentSet(org.exist.dom.persistent.DocumentSet) FixedString(org.exist.xquery.modules.ngram.query.FixedString)

Example 32 with DocumentSet

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

Example 33 with DocumentSet

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);
}
Also used : DocumentSet(org.exist.dom.persistent.DocumentSet) Test(org.junit.Test)

Example 34 with DocumentSet

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);
}
Also used : DocumentSet(org.exist.dom.persistent.DocumentSet) Test(org.junit.Test)

Example 35 with DocumentSet

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);
}
Also used : DocumentSet(org.exist.dom.persistent.DocumentSet) Test(org.junit.Test)

Aggregations

DocumentSet (org.exist.dom.persistent.DocumentSet)50 QName (org.exist.dom.QName)20 DefaultDocumentSet (org.exist.dom.persistent.DefaultDocumentSet)18 Sequence (org.exist.xquery.value.Sequence)18 MutableDocumentSet (org.exist.dom.persistent.MutableDocumentSet)16 NodeSet (org.exist.dom.persistent.NodeSet)14 DBBroker (org.exist.storage.DBBroker)14 BrokerPool (org.exist.storage.BrokerPool)13 CompiledXQuery (org.exist.xquery.CompiledXQuery)12 XQuery (org.exist.xquery.XQuery)12 IOException (java.io.IOException)9 Txn (org.exist.storage.txn.Txn)9 TransactionManager (org.exist.storage.txn.TransactionManager)8 Test (org.junit.Test)7 DocumentImpl (org.exist.dom.persistent.DocumentImpl)6 InputSource (org.xml.sax.InputSource)6 StringReader (java.io.StringReader)5 LuceneIndexWorker (org.exist.indexing.lucene.LuceneIndexWorker)5 XPathException (org.exist.xquery.XPathException)5 VirtualNodeSet (org.exist.dom.persistent.VirtualNodeSet)4