Package org.exist.dom

Examples of org.exist.dom.ExtArrayNodeSet$ExtDocIterator


     * @param context
     * @param result
     */
    private Sequence exactMatch(XQueryContext context, String[] terms, NodeSet result) {
        TextToken token;
        final NodeSet r = new ExtArrayNodeSet();
        final Tokenizer tok = context.getBroker().getTextEngine().getTokenizer();
        //Define search phrase for matches
        String matchTerm = "";
        for (int k = 0; k < terms.length ; k++) {
            matchTerm = matchTerm + terms[k];
            if (k != terms.length - 1)
                {matchTerm = matchTerm + "\\W*";}
        }
        //Iterate on results
        for (final NodeProxy current : result) {
            final Vector<NodeId> matchNodeIDs = new Vector<NodeId>();
            //Get first match
            Match nextMatch = current.getMatches();
            //Remove previously found matches on current
            current.setMatches(null);
            //Iterate on attach matches, with unicity of related nodeproxy gid
            String term;
            while(nextMatch != null) {
                final NodeId nodeId= nextMatch.getNodeId();
                //If current node id has not been previously processed
                if (!matchNodeIDs.contains(nodeId)) {
                    final NodeProxy mcurrent = new NodeProxy(current.getDocument(), nodeId);
                    Match match = null;
                    int firstOffset = -1;
                    matchNodeIDs.add(nodeId);
                    final String value = mcurrent.getNodeValue();
                    tok.setText(value);
                    int j = 0;
                    if (j < terms.length)
                        {term = terms[j];}
                    else
                        {break;}
                    int frequency = 0;
                    while ((token = tok.nextToken()) != null) {
                        final String word = token.getText().toLowerCase();
                        if (word.equalsIgnoreCase(term)) {
                            j++;
                            if (j == terms.length) {
                                //All terms found
                                if (match == null)
                                    {match = nextMatch.createInstance(getExpressionId(),
                                        nodeId, matchTerm);}
                                if (firstOffset < 0)
                                    {firstOffset = token.startOffset();}
                                match.addOffset(firstOffset, token.endOffset() - firstOffset);
                                frequency++;
                                //Start again on fist term
                                j = 0;
                                term = terms[j];
                                continue;
                            } else {
                                term = terms[j];
                                if (firstOffset < 0)
                                    {firstOffset = token.startOffset();}
                            }
                        } else if (j > 0 && word.equalsIgnoreCase(terms[0])) {
                            //First search term found: start again
                            j = 1;
                            term = terms[j];
                            firstOffset = token.startOffset();
                            continue;
                        } else {
                            //Reset
                            j = 0;
                            firstOffset = -1;
                            term = terms[j];
                        }
                    }
                    //If phrase found
                    if (frequency != 0) {
                        //Add new match to current
                        current.addMatch(match);
                        //Add current to result
                        r.add(current);
                        //Reset frequency
                        frequency=0;
                    }
                }
                //Process next match
View Full Code Here


                logger.error("malformed pattern" + e.getMessage());
                return Sequence.EMPTY_SEQUENCE;
            }
        }
        //Walk through hits
        final ExtArrayNodeSet r = new ExtArrayNodeSet();
        final Tokenizer tok = context.getBroker().getTextEngine().getTokenizer();
        Matcher matcher;
        for (final NodeProxy current : result) {
            Match nextMatch;
            final Vector<NodeId> matchGid = new Vector<NodeId>();
            //Get first match
            nextMatch = current.getMatches();
            //Remove previously found matches on current
            current.setMatches(null);
            //Iterate on attach matches, with unicity of related nodeproxy gid
            while (nextMatch != null) {
                final Hashtable<String, Match> matchTable = new Hashtable<String, Match>();
                final NodeId nodeId = nextMatch.getNodeId();
                //If current node id has not been previously processed
                if (!matchGid.contains(nodeId)) {
                    final NodeProxy mcurrent = new NodeProxy(current.getDocument(), nodeId);
                    //Add it in node id array
                    matchGid.add(nodeId);
                    final String value = mcurrent.getNodeValue();
                    tok.setText(value);
                    int j = 0;
                    if (j < patterns.length) {
                        matcher = matchers[j];
                    } else
                        {break;}
                    String matchTerm = null;
                    TextToken token;
                    while ((token = tok.nextToken()) != null) {
                        String word = token.getText().toLowerCase();
                        matcher.reset(word);
                        matchers[0].reset(word);
                        if (matcher.matches()) {
                            j++;
                            if (matchTerm == null)
                                {matchTerm=word;}
                            else
                                {matchTerm = matchTerm + "\\W*" + word;}
                            if (j == patterns.length) {
                                //All terms found
                                if (matchTable.containsKey(matchTerm)) {
                                    //Previously found matchTerm
                                    final Match match = matchTable.get(matchTerm);
                                    match.addOffset(token.startOffset(), matchTerm.length());
                                } else {
                                    final Match match = nextMatch.createInstance(getExpressionId(),
                                        nodeId, matchTerm);
                                    match.addOffset(token.startOffset(), matchTerm.length());
                                    matchTable.put(matchTerm,match);
                                }
                                //Start again on fist term
                                j = 0;
                                matcher = matchers[j];
                                matchTerm = null;
                                continue;
                            } else {
                                matcher = matchers[j];
                            }
                        } else if (j > 0 && matchers[0].matches()) {
                            //First search term found: start again
                            j = 1;
                            //Pattern term = patterns[j];
                            matcher = matchers[j];
                            matchTerm = word;
                            continue;
                        } else {
                            //Reset
                            j = 0;
                            matcher = matchers[j];
                            matchTerm = null;
                            continue;
                        }
                    }
                    //One or more match found
                    if (matchTable.size() != 0) {
                        final Enumeration<Match> eMatch = matchTable.elements();
                        while (eMatch.hasMoreElements()){
                            final Match match = eMatch.nextElement();
                            current.addMatch(match);
                        }
                        //Add current to result
                        r.add(current);
                    }
                }
                //Process next match
                nextMatch = nextMatch.getNextMatch();
            }
View Full Code Here

            if(!cacheIsValid)
                // wait for pending updates
                {docs.lock(context.getBroker(), lockOnLoad, true);}
      // wait for pending updates
      if(result == null) {
    result = new ExtArrayNodeSet(docs.getDocumentCount(), 1);
                DocumentImpl doc;
    for (final Iterator<DocumentImpl> i = docs.getDocumentIterator(); i.hasNext();) {
                    doc = i.next();
        result.add(new NodeProxy(doc)); //, -1, Node.DOCUMENT_NODE));
                    if(lockOnLoad) {
View Full Code Here

    }

    public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
        if (args[0].isEmpty())
            {return Sequence.EMPTY_SEQUENCE;}
        final ExtArrayNodeSet inSet = (ExtArrayNodeSet) args[0].toNodeSet();
        final NodeSet filtered = new ExtArrayNodeSet();
        for (final NodeProxy p : inSet) {
            if (inSet.hasDescendantsInSet(p.getDocument(), p.getNodeId(), false, -1) == null)
                {filtered.add(p);}
        }
        return filtered;
    }
View Full Code Here

    // otherwise we have to walk through each item in the context
    } else {
      Item current;
//      String arg;
      NodeSet nodes;
      result = new ExtArrayNodeSet();
      Sequence temp;
      for (final SequenceIterator i = contextSequence.iterate(); i.hasNext();) {
        current = i.nextItem();
        final List<String> terms = getSearchTerms(termsExpr, contextSequence);
        nodes =
View Full Code Here

        final NodeSet nodes = seq.toNodeSet();
        // if the where expression returns a node set, check the context
        // node of each node in the set          
        final NodeSet contextSet = contextSequence.toNodeSet();
        final boolean contextIsVirtual = contextSet instanceof VirtualNodeSet;           
        final NodeSet result = new ExtArrayNodeSet();
        DocumentImpl lastDoc = null;

        for (final NodeProxy current : nodes) {
          int sizeHint = Constants.NO_SIZE_HINT;
          if(lastDoc == null || current.getDocument() != lastDoc) {
            lastDoc = current.getDocument();
            sizeHint = nodes.getSizeHint(lastDoc);
          }
          ContextItem  context = current.getContext();               
          if (context == null) {              
            throw new XPathException(this, "Internal evaluation error: context node is missing for node " +
                current.getNodeId() + "!");
          }
  //        LOG.debug(current.debugContext());
          while (context != null) {
                      //TODO : Is this the context we want ? Not sure... would have prefered the LetExpr.
            if (context.getContextId() == whereExpr.getContextId()) {
              final NodeProxy contextNode = context.getNode();                   
              if(contextIsVirtual || contextSet.contains(contextNode)) {
                              contextNode.addMatches(current);
                result.add(contextNode, sizeHint);
              }
            }
                      context = context.getNextDirect();
          }
        }
        return result;
      }
    }
   
    if (contextSequence == null) {
      final Sequence innerSeq = whereExpr.eval(null);
      return innerSeq.effectiveBooleanValue() ? BooleanValue.TRUE : BooleanValue.FALSE;
    } else {
      // general where clause: just check the effective boolean value
      final ValueSequence result = new ValueSequence();
      int p = 0;     
      for (final SequenceIterator i = contextSequence.iterate(); i.hasNext(); p++) {
        final Item item = i.nextItem();
        context.setContextSequencePosition(p, contextSequence);
                final Sequence innerSeq = whereExpr.eval(contextSequence, item);               
        if (innerSeq.effectiveBooleanValue())
          {result.add(item);}                   
      }
      return result;
    }
  }
View Full Code Here

      // resource is a document
            //TODO : use dedicated function in XmldbURI
      final XmldbURI[] docs = new XmldbURI[] { XmldbURI.create(res.getParentCollection().getName()).append(res.getDocumentId()) };
      return doQuery(query, docs, null, sortBy);
    } else {
      final NodeSet set = new ExtArrayNodeSet(1);
      set.add(node);
      final XmldbURI[] docs = new XmldbURI[] { node.getDocument().getURI() };
      return doQuery(query, docs, set, sortBy);
    }
  }
View Full Code Here

    if (node == null) {
      // resource is a document
      final XmldbURI[] docs = new XmldbURI[] { XmldbURI.create(res.getParentCollection().getName()).append(res.getDocumentId()) };
      return execute(docs, null, expression, null);
    } else {
      final NodeSet set = new ExtArrayNodeSet(1);
      set.add(node);
      final XmldbURI[] docs = new XmldbURI[] { node.getDocument().getURI() };
      return execute(docs, set, expression, null);
    }
  }
View Full Code Here

TOP

Related Classes of org.exist.dom.ExtArrayNodeSet$ExtDocIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.