public Sequence evalQuery(NodeSet nodes, List terms) throws XPathException { if (terms == null || terms.size() == 0) return Sequence.EMPTY_SEQUENCE; // no search terms double threshold = 0.65; if (getArgumentCount() == 3) { Sequence thresOpt = getArgument(2).eval(nodes); // TODO : get rid of getLength() if (!thresOpt.hasOne()) throw new XPathException( getASTNode(), "third argument to " + getName() + "should be a single double value"); threshold = ((DoubleValue) thresOpt.convertTo(Type.DOUBLE)).getDouble(); } NodeSet hits[] = new NodeSet[terms.size()]; String term; TermMatcher matcher; for (int k = 0; k < terms.size(); k++) { term = (String) terms.get(k); if (term.length() == 0) hits[k] = null; else { matcher = new FuzzyMatcher(term, threshold); hits[k] = context .getBroker() .getTextEngine() .getNodes( context, nodes.getDocumentSet(), nodes, NodeSet.ANCESTOR, null, matcher, term.substring(0, 1)); } } return mergeResults(hits); }
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException { Sequence querySeq = getArgument(1).eval(contextSequence); if (querySeq.isEmpty()) { return Sequence.EMPTY_SEQUENCE; } String query = querySeq.itemAt(0).getStringValue(); String[] terms = getSearchTerms(query); NodeSet hits[] = new NodeSet[terms.length]; NodeSet contextSet = contextSequence.toNodeSet(); for (int k = 0; k < terms.length; k++) { hits[k] = context .getBroker() .getTextEngine() .getNodesContaining( context, contextSet.getDocumentSet(), null, NodeSet.DESCENDANT, null, terms[k], DBBroker.MATCH_EXACT); hits[k] = getArgument(0).eval(hits[k]).toNodeSet(); } NodeSet result = hits[0]; for (int k = 1; k < hits.length; k++) { if (hits[k] != null) result = result.deepIntersection(hits[k]); } if (LOG.isDebugEnabled()) LOG.debug("FOUND: " + result.getLength()); return result; }