Exemplo n.º 1
0
  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;
  }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
  /* (non-Javadoc)
   * @see org.exist.xquery.Expression#eval(org.exist.dom.DocumentSet, org.exist.xquery.value.Sequence, org.exist.xquery.value.Item)
   */
  public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
    logger.error(
        "Use of deprecated function fn:doctype(). "
            + "It will be removed soon. Please "
            + "use util:doctype() instead.");
    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());
    }

    MutableDocumentSet docs = new DefaultDocumentSet();
    for (int i = 0; i < getArgumentCount(); i++) {
      Sequence seq = getArgument(i).eval(contextSequence, contextItem);
      for (SequenceIterator j = seq.iterate(); j.hasNext(); ) {
        String next = j.nextItem().getStringValue();
        context.getBroker().getXMLResourcesByDoctype(next, docs);
      }
    }

    NodeSet result = new ExtArrayNodeSet(1);
    for (Iterator i = docs.getDocumentIterator(); i.hasNext(); ) {
      result.add(new NodeProxy((DocumentImpl) i.next(), NodeId.DOCUMENT_NODE));
    }

    if (context.getProfiler().isEnabled()) context.getProfiler().end(this, "", result);

    return result;
  }
Exemplo n.º 4
0
 /* (non-Javadoc)
  * @see org.exist.xquery.value.Sequence#toNodeSet()
  */
 public NodeSet toNodeSet() throws XPathException {
   // for this method to work, all items have to be nodes
   if (itemType != Type.ANY_TYPE && Type.subTypeOf(itemType, Type.NODE)) {
     final NodeSet set = new ExtArrayNodeSet();
     // We can't make it from an ExtArrayNodeSet (probably because it is sorted ?)
     // NodeSet set = new ArraySet(100);
     for (int i = 0; i < this.count; i++) {
       NodeValue v = null;
       final Entry temp = items[i];
       v = (NodeValue) temp.item;
       if (v.getImplementationType() != NodeValue.PERSISTENT_NODE) {
         set.add((NodeProxy) v);
       } else {
         set.add((NodeProxy) v);
       }
     }
     return set;
   } else {
     throw new XPathException(
         "Type error: the sequence cannot be converted into"
             + " a node set. Item type is "
             + Type.getTypeName(itemType));
   }
 }
Exemplo n.º 5
0
 public NodeProxy match(DocumentImpl doc, NodeId nodeId) {
   return parents.get(doc, nodeId);
 }
Exemplo n.º 6
0
 public ParentSelector(NodeSet contextSet, int contextId) {
   this.parents = contextSet.getParents(contextId);
 }