use of org.exist.dom.persistent.EmptyNodeSet in project exist by eXist-db.
the class NGramSearch method fixedStringSearch.
public NodeSet fixedStringSearch(final NGramIndexWorker index, final DocumentSet docs, final List<QName> qnames, final String query, final NodeSet nodeSet, final int axis) throws XPathException {
String[] ngrams = NGramSearch.getDistinctNGrams(query, index.getN());
// Nothing to search for? The find nothing.
if (ngrams.length == 0)
return new EmptyNodeSet();
String firstNgramm = ngrams[0];
LOG.trace("First NGRAM: {}", firstNgramm);
NodeSet result = index.search(getExpressionId(), docs, qnames, firstNgramm, firstNgramm, context, nodeSet, axis);
for (int i = 1; i < ngrams.length; i++) {
String ngram = ngrams[i];
int len = ngram.codePointCount(0, ngram.length());
int fillSize = index.getN() - len;
String filledNgram = ngram;
// ngrams lead to a considerable performance loss.
if (fillSize > 0) {
String filler = ngrams[i - 1];
StringBuilder buf = new StringBuilder();
int pos = filler.offsetByCodePoints(0, len);
for (int j = 0; j < fillSize; j++) {
int codepoint = filler.codePointAt(pos);
pos += Character.charCount(codepoint);
buf.appendCodePoint(codepoint);
}
buf.append(ngram);
filledNgram = buf.toString();
LOG.debug("Filled: {}", filledNgram);
}
NodeSet nodes = index.search(getExpressionId(), docs, qnames, filledNgram, ngram, context, nodeSet, axis);
final NodeSet nodesContainingFirstINgrams = result;
result = NodeSets.transformNodes(nodes, proxy -> Optional.ofNullable(nodesContainingFirstINgrams.get(proxy)).map(before -> getContinuousMatches(before, proxy)).orElse(null));
}
return result;
}
use of org.exist.dom.persistent.EmptyNodeSet in project exist by eXist-db.
the class WildcardedExpressionSequence method eval.
@Override
public NodeSet eval(final NGramIndexWorker index, final DocumentSet docs, final List<QName> qnames, final NodeSet nodeSet, final int axis, final int expressionId) throws XPathException {
boolean startAnchorPresent = false;
if (!expressions.isEmpty() && expressions.get(0) instanceof StartAnchor) {
startAnchorPresent = true;
expressions.remove(0);
}
Wildcard leadingWildcard = null;
if (!expressions.isEmpty() && expressions.get(0) instanceof Wildcard)
leadingWildcard = (Wildcard) expressions.remove(0);
boolean endAnchorPresent = false;
if (!expressions.isEmpty() && expressions.get(expressions.size() - 1) instanceof EndAnchor) {
endAnchorPresent = true;
expressions.remove(expressions.size() - 1);
}
Wildcard trailingWildcard = null;
if (!expressions.isEmpty() && expressions.get(expressions.size() - 1) instanceof Wildcard)
trailingWildcard = (Wildcard) expressions.remove(expressions.size() - 1);
while (expressions.size() >= 3) {
formEvaluatableTriples(expressionId);
}
if (expressions.isEmpty())
return new EmptyNodeSet();
if (expressions.size() != 1 || !(expressions.get(0) instanceof EvaluatableExpression)) {
// Should not happen.
LOG.error("Expression {} could not be evaluated", toString());
throw new XPathException("Could not evaluate wildcarded query.");
}
LOG.trace("Evaluating expression {}", toString());
NodeSet result = ((EvaluatableExpression) expressions.get(0)).eval(index, docs, qnames, nodeSet, axis, expressionId);
if (leadingWildcard != null)
result = expandMatchesBackward(leadingWildcard, result, expressionId);
if (startAnchorPresent)
result = NodeSets.getNodesMatchingAtStart(result, expressionId);
if (trailingWildcard != null)
result = expandMatchesForward(trailingWildcard, result, expressionId);
if (endAnchorPresent)
result = NodeSets.getNodesMatchingAtEnd(result, expressionId);
return result;
}
Aggregations