Package org.exist.dom

Examples of org.exist.dom.NodeSet


       
      Sequence result;
      if (args[0].isEmpty())
            {result = Sequence.EMPTY_SEQUENCE;}
      else {
          final NodeSet nodes = args[0].toNodeSet();
          final DocumentSet docs = nodes.getDocumentSet();
         
          if (this.getArgumentCount() == 3){
            final IndexWorker indexWorker = context.getBroker().getIndexController().getWorkerByIndexName(args[2].itemAt(0).getStringValue());
            //Alternate design
            //IndexWorker indexWorker = context.getBroker().getBrokerPool().getIndexManager().getIndexByName(args[2].itemAt(0).getStringValue()).getWorker();
View Full Code Here


      pattern = getArgument(1).eval(contextSequence, contextItem).getStringValue();
    } else {
      pattern = translateRegexp(getArgument(1).eval(contextSequence, contextItem).getStringValue());
    }
   
        final NodeSet nodes = input.toNodeSet();
        // get the type of a possible index
    final int indexType = nodes.getIndexType();
    if (LOG.isTraceEnabled())
        {LOG.trace("found an index of type: " + Type.getTypeName(indexType));}
    if(Type.subTypeOf(indexType, Type.STRING)) {
            boolean indexScan = false;
            if (contextSequence != null) {
                final GeneralComparison.IndexFlags iflags = GeneralComparison.checkForQNameIndex(idxflags, context, contextSequence, contextQName);
                boolean indexFound = false;
                if (!iflags.indexOnQName()) {
                    // if contextQName != null and no index is defined on
                    // contextQName, we don't need to scan other QName indexes
                    // and can just use the generic range index
                    indexFound = contextQName != null;
                    // set contextQName to null so the index lookup below is not
                    // restricted to that QName
                    contextQName = null;
                }
                if (!indexFound && contextQName == null) {
                    // if there are some indexes defined on a qname,
                    // we need to check them all
                    if (iflags.hasIndexOnQNames())
                        {indexScan = true;}
                    // else use range index defined on path by default
                }
            } else
                {result = evalFallback(nodes, pattern, flags, indexType);}

            if (result == null) {
                final DocumentSet docs = nodes.getDocumentSet();
                try {
                    final NativeValueIndex index = context.getBroker().getValueIndex();
                    hasUsedIndex = true;
                    //TODO : check index' case compatibility with flags' one ? -pb
                    if (context.isProfilingEnabled())
View Full Code Here

       
      Sequence result;
      if (args[0].isEmpty())
            {result = Sequence.EMPTY_SEQUENCE;}
      else {
          final NodeSet nodes = args[0].toNodeSet();
          final DocumentSet docs = nodes.getDocumentSet();         
          if (this.getArgumentCount() == 3) {
            final IndexWorker indexWorker = context.getBroker().getIndexController().getWorkerByIndexName(args[2].itemAt(0).getStringValue());
            //Alternate design
            //IndexWorker indexWorker = context.getBroker().getBrokerPool().getIndexManager().getIndexByName(args[2].itemAt(0).getStringValue()).getWorker();           
            if (indexWorker == null)
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;}
        boolean hasWildcards = false;
        for (int i = 0; i < terms.length; i++) {
            hasWildcards |=  NativeTextEngine.containsWildcards(terms[i]);
View Full Code Here

     * @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

        Sequence result;

      if (args[0].isEmpty())
            {result = Sequence.EMPTY_SEQUENCE;}
      else {
          final NodeSet nodes = args[0].toNodeSet();
          //Remember it is the default value when no index is defined
          if (nodes.getIndexType() == Type.ANY_TYPE)
            {result = Sequence.EMPTY_SEQUENCE;}
          else
            {result = new StringValue(Type.getTypeName(nodes.getIndexType()));
      }
      //TODO : consider modularized indexes. We should thus return a * sequence...
     
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
View Full Code Here

      if(!thresOpt.hasOne())
        {throw new XPathException(this, "third argument to " + getName() +
            "should be a single double value");}
      threshold = ((DoubleValue) thresOpt.convertTo(Type.DOUBLE)).getDouble();
    }
    final NodeSet hits[] = new NodeSet[terms.size()];
    String term;
    TermMatcher matcher;
    for (int k = 0; k < terms.size(); k++) {
        term = terms.get(k);
      if(term.length() == 0)
View Full Code Here

  }

  public abstract Sequence evalQuery(NodeSet nodes, List<String> terms) throws XPathException;
 
  public NodeSet mergeResults(NodeSet[] hits) {
    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

     * @see org.exist.xquery.Expression#eval(org.exist.dom.DocumentSet, org.exist.xquery.value.Sequence, org.exist.xquery.value.Item)
     */
    public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

        // Get nodes
        final NodeSet nodes = args[0].toNodeSet();
        final DocumentSet docs = nodes.getDocumentSet();

        try {
            if (args.length > 1) {
                // Use supplied parameter
                final int splitCount = ((IntegerValue)args[1].itemAt(0)).getInt();
View Full Code Here

     * @return The result of the node set evaluation of the predicate.
     * @throws XPathException
     */
    private Sequence selectByNodeSet(Sequence contextSequence) throws XPathException {
        final NewArrayNodeSet result = new NewArrayNodeSet();
        final NodeSet contextSet = contextSequence.toNodeSet();
        final boolean contextIsVirtual = contextSet instanceof VirtualNodeSet;
        contextSet.setTrackMatches(false);
        final NodeSet nodes = super.eval(contextSet, null).toNodeSet();
        /*
         * if the predicate expression returns results from the cache we can
         * also return the cached result.
         */
        if (cached != null && cached.isValid(contextSequence, null) && nodes.isCached()) {
            if (context.getProfiler().isEnabled())
                {context.getProfiler().message(this, Profiler.OPTIMIZATIONS,
                        "Using cached results", result);}
            return cached.getResult();
        }
        DocumentImpl lastDoc = null;
        for (final Iterator<NodeProxy> i = nodes.iterator(); i.hasNext();) {
            final NodeProxy currentNode = i.next();
            int sizeHint = Constants.NO_SIZE_HINT;
            if (lastDoc == null || currentNode.getDocument() != lastDoc) {
                lastDoc = currentNode.getDocument();
                sizeHint = nodes.getSizeHint(lastDoc);
            }
            ContextItem contextItem = currentNode.getContext();
            if (contextItem == null) {
                throw new XPathException(this,
                    "Internal evaluation error: context is missing for node " +
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.