Package org.exist.dom

Examples of org.exist.dom.NodeSet


        final long start = System.currentTimeMillis();
        if (contextItem != null)
            {contextSequence = contextItem.toSequence();}
        if (preselectResult == null && !checkForQNameIndex(contextSequence))
            {contextQName = null;}
        NodeSet result;
        //If the expression does not depend on the current context item,
        //we can evaluate it in one single step
        if (path == null || !Dependency.dependsOn(path, Dependency.CONTEXT_ITEM)) {
            final boolean canCache =
                !Dependency.dependsOn(searchTerm, Dependency.CONTEXT_ITEM) &&
                !Dependency.dependsOnVar(searchTerm);
            if (canCache && cached != null && cached.isValid(contextSequence, contextItem)) {
                return cached.getResult();
            }
            //Do we optimize this expression?
            if (contextStep == null || preselectResult == null) {
                //No optimization: process the whole expression
                final NodeSet nodes = path == null ?
                    contextSequence.toNodeSet() : path.eval(contextSequence).toNodeSet();
                final String arg = searchTerm.eval(contextSequence).getStringValue();
                result = evalQuery(arg, nodes).toNodeSet();
                if (context.getProfiler().traceFunctions())
                    {context.getProfiler().traceIndexUsage(context, FTIndex.ID, this,
                        PerformanceStats.BASIC_INDEX, System.currentTimeMillis() - start);}
            } else {
                contextStep.setPreloadedData(contextSequence.getDocumentSet(), preselectResult);
                result = path.eval(contextSequence).toNodeSet();
            }
            if(canCache && contextSequence != null && contextSequence.isCacheable())
                {cached = new CachedResult(contextSequence, contextItem, result);}
        //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();
                arg = searchTerm.eval(current.toSequence()).getStringValue();
View Full Code Here


        try {
            terms = getSearchTerms(searchArg);
        } catch (final EXistException e) {
            throw new XPathException(e.getMessage());
        }
        final NodeSet hits = processQuery(terms, nodes);
        if (hits == null)
            {return NodeSet.EMPTY_SET;}
        return hits;
    }
View Full Code Here

        }
        if (terms.length == 0)
            {return NodeSet.EMPTY_SET;}
        final NodeSet[] hits = getMatches(contextSet.getDocumentSet(), contextSet,
            NodeSet.ANCESTOR, contextQName, terms);
        NodeSet result = hits[0];
        if (result != null) {
            for(int k = 1; k < hits.length; k++) {
                if (hits[k] != null) {
                    result = type == Constants.FULLTEXT_AND ?
                        result.deepIntersection(hits[k]) : result.union(hits[k]);
                }
            }
            return result;
        } else {
            return NodeSet.EMPTY_SET;
View Full Code Here

        }
    }

    protected NodeSet[] getMatches(DocumentSet docs, NodeSet contextSet,
            int axis, QName qname, String[] terms) throws XPathException {
        final NodeSet hits[] = new NodeSet[terms.length];
        for (int k = 0; k < terms.length; k++) {
            hits[k] = context.getBroker().getTextEngine().getNodesContaining(
                context, docs, contextSet, axis, qname, terms[k], DBBroker.MATCH_EXACT);
        }
        return hits;
View Full Code Here

            }
          }

          // evaluate argument expression
          final Sequence argSeq = arg.eval(result);
          NodeSet argSet;
          if (contextId != Expression.NO_CONTEXT_ID) {
            argSet = argSeq.toNodeSet().getContextNodes(contextId);
          } else {
            argSet = argSeq.toNodeSet().getContextNodes(getExpressionId());
          }
View Full Code Here

        } catch(final PermissionDeniedException pde) {
            throw new XPathException("FODC0002: can not access collection '" + pde.getMessage() + "'");
           
        }
        // iterate through all docs and create the node set
        final NodeSet result = new NewArrayNodeSet(docs.getDocumentCount(), 1);
        Lock dlock;
        DocumentImpl doc;
        for (final Iterator<DocumentImpl> i = docs.getDocumentIterator(); i.hasNext();) {
            doc = i.next();
            dlock = doc.getUpdateLock();
            boolean lockAcquired = false;
            try {
                if (!context.inProtectedMode() && !dlock.hasLock()) {
                    dlock.acquire(Lock.READ_LOCK);
                    lockAcquired = true;
                }
                result.add(new NodeProxy(doc)); // , -1, Node.DOCUMENT_NODE));
            } catch (final LockException e) {
                throw new XPathException(e.getMessage());
            } finally {
                if (lockAcquired)
                    {dlock.release(Lock.READ_LOCK);}
View Full Code Here

        try {
            terms = getSearchTerms(searchArg);
        } catch (final EXistException e) {
            throw new XPathException(e.getMessage());
        }
        final NodeSet hits = processQuery(terms, nodes);
        if (hits == null)
            {return Sequence.EMPTY_SEQUENCE;}
        if (terms.length == 1)
            {return hits;}
        boolean hasWildcards = false;
View Full Code Here

        return hasWildcards ? patternMatch(context, terms, hits) : exactMatch(context, terms, hits);
    }

    private Sequence exactMatch(XQueryContext context, String[] terms, NodeSet result) {
        //Walk through hits and calculate term-distances
        final NodeSet r = new ExtArrayNodeSet();
        final Tokenizer tok = context.getBroker().getTextEngine().getTokenizer();
        String term;
        for (final NodeProxy current : result) {
            final String value = current.getNodeValueSeparated();
            tok.setText(value);
            int j = 0;
            if (j < terms.length) {
                term = terms[j];
            } else {
                break;
            }
            int current_distance = -1;
            TextToken token;
            while ((token = tok.nextToken()) != null) {
                final String word = token.getText().toLowerCase();
                if (current_distance > max_distance) {
                    // reset
                    j = 0;
                    term = terms[j];
                    current_distance = -1;
                } //That else would cause some words to be ignored in the matching
                if (word.equalsIgnoreCase(term)) {
                    final boolean withIn = current_distance >= min_distance;
                    current_distance = 0;
                    j++;
                    if (j == terms.length) {
                        //All terms found
                        if (withIn) {
                            r.add(current);
                        }
                        break;
                    } else {
                        term = terms[j];
                    }
View Full Code Here

       
        if (preselectResult == null && !checkForQNameIndex(contextSequence))
            {contextQName = null;}

        final Expression path = getArgument(0);
        NodeSet result;
    // if the expression does not depend on the current context item,
    // we can evaluate it in one single step
    if (path == null || !Dependency.dependsOn(path, Dependency.CONTEXT_ITEM)) {
      final boolean canCache =
                (getTermDependencies() & Dependency.CONTEXT_ITEM) == Dependency.NO_DEPENDENCY;
            ifcanCache && cached != null && cached.isValid(contextSequence, contextItem)) {
        return cached.getResult();
      }
            // do we optimize this expression?
            if (contextStep == null || preselectResult == null) {
                // no optimization: process the whole expression
                final NodeSet nodes =
                    path == null
                        ? contextSequence.toNodeSet()
                        : path.eval(contextSequence).toNodeSet();
                final List<String> terms = getSearchTerms(contextSequence);
                result = evalQuery(nodes, terms).toNodeSet();
            } else {
                contextStep.setPreloadedData(contextSequence.getDocumentSet(), preselectResult);
                result = path.eval(contextSequence).toNodeSet();
            }
            if(canCache && contextSequence.isCacheable())
        {cached = new CachedResult(contextSequence, contextItem, result);}

    // otherwise we have to walk through each item in the context
    } else {
      Item current;
      final @SuppressWarnings("unused")
      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(contextSequence);
View Full Code Here

    List<String> terms)
    throws XPathException {
    if(terms == null || terms.size() == 0)
      {return Sequence.EMPTY_SEQUENCE;// no search terms
        final NodeSet[] hits = getMatches(nodes.getDocumentSet(), nodes, NodeSet.ANCESTOR, contextQName, terms);
    NodeSet result = hits[0];
    if(result != null) {
      for(int k = 1; k < hits.length; k++) {
        if(hits[k] != null)
          {result = (type == Constants.FULLTEXT_AND ?
              result.deepIntersection(hits[k]) : result.union(hits[k]));}
      }
      return result;
    } else
      {return NodeSet.EMPTY_SET;}
  }
View Full Code Here

TOP

Related Classes of org.exist.dom.NodeSet

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.