Package org.exist.dom

Examples of org.exist.dom.NodeSet


    @Override
    public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
        if (contextItem != null)
      contextSequence = contextItem.toSequence();

        NodeSet result;
        if (preselectResult == null) {
            Sequence input = getArgument(0).eval(contextSequence, contextItem);
            if (input.isEmpty())
                result = NodeSet.EMPTY_SET;
            else {
                long start = System.currentTimeMillis();
                NodeSet inNodes = input.toNodeSet();
                DocumentSet docs = inNodes.getDocumentSet();
                NGramIndexWorker index = (NGramIndexWorker) context.getBroker().getIndexController()
                    .getWorkerByIndexId(NGramIndex.ID);
                //Alternate design
                // NGramIndexWorker index =
                // (NGramIndexWorker)context.getBroker().getBrokerPool().getIndexManager().getIndexById(NGramIndex.ID).getWorker();
View Full Code Here


    public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
     
        if (contextItem != null)
            contextSequence = contextItem.toSequence();

        NodeSet result;
        if (preselectResult == null) {
          long start = System.currentTimeMillis();
          String field = getArgument(0).eval(contextSequence).getStringValue();
         
          Item query = getKey(contextSequence, null);
         
          DocumentSet docs = null;
          if (contextSequence == null)
            docs = context.getStaticallyKnownDocuments();
          else
                docs = contextSequence.getDocumentSet();

          NodeSet contextSet = null;
          if (contextSequence != null)
            contextSet = contextSequence.toNodeSet();
         
          LuceneIndexWorker index = (LuceneIndexWorker)
            context.getBroker().getIndexController().getWorkerByIndexId(LuceneIndex.ID);
View Full Code Here

            parsedQuery = parseQuery(query);
              else
            parsedQuery = new FixedString(this, query);

        LOG.debug("Parsed Query: " + parsedQuery);
        NodeSet result = parsedQuery.eval(index, docs, qnames, nodeSet, axis, this
                .getExpressionId());

        if (getLocalName().startsWith("starts-with"))
            result = NodeSets.getNodesMatchingAtStart(result, getExpressionId());
        else if (getLocalName().startsWith("ends-with"))
View Full Code Here

        if (ngrams.length == 0)
            return new EmptyNodeSet();

        String firstNgramm = ngrams[0];
        LOG.trace("First NGRAM: " + firstNgramm);
        NodeSet result = index.search(getExpressionId(), docs, qnames, firstNgramm, firstNgramm, context, nodeSet, axis);

        for (int i = 1; i < ngrams.length; i++) {
            String ngram = ngrams[i];
            int len = ngram.codePointCount(0, ngram.length());
            int fillSize = index.getN() - len;
            String filledNgram = ngram;

            // if this ngram is shorter than n,
            // fill it up with characters from the previous ngram. too short
            // ngrams lead to a considerable performance loss.
            if (fillSize > 0) {
                String filler = ngrams[i - 1];
                StringBuilder buf = new StringBuilder();
                int pos = filler.offsetByCodePoints(0, len);
                for (int j = 0; j < fillSize; j++) {
                    int codepoint = filler.codePointAt(pos);
                    pos += Character.charCount(codepoint);
                    buf.appendCodePoint(codepoint);
                }
                buf.append(ngram);
                filledNgram = buf.toString();
                LOG.debug("Filled: " + filledNgram);
            }

            NodeSet nodes = index.search(getExpressionId(), docs, qnames, filledNgram, ngram, context, nodeSet, axis);

            final NodeSet nodesContainingFirstINgrams = result;

            result = NodeSets.fmapNodes(nodes, new F<NodeProxy, NodeProxy>() {

                @Override
                public NodeProxy f(NodeProxy a) {
                    NodeProxy before = nodesContainingFirstINgrams.get(a);
                    if (before != null) {
                        return getContinuousMatches(before, a);
                    } else {
                        return null;
                    }
View Full Code Here

                Geometry EPSG4326_geometry = indexWorker.transformGeometry(currentGeometry, "osgb:BNG", "EPSG:4326");
                assertNotNull(EPSG4326_geometry);
               
                System.out.println(EPSG4326_geometry);
               
                NodeSet ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.EQUALS);
                assertTrue(ns.getLength() > 0);
                ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.DISJOINT);
                assertTrue(ns.getLength() > 0);
                ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.INTERSECTS);
                assertTrue(ns.getLength() > 0);
                ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.TOUCHES);
                //assertTrue(ns.getLength() > 0);
                ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.CROSSES);
                //assertTrue(ns.getLength() > 0);
                ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.WITHIN);
                assertTrue(ns.getLength() > 0);
                ns = indexWorker.search(broker, null, EPSG4326_geometry, SpatialOperator.CONTAINS);
                assertTrue(ns.getLength() > 0);
                //ns = ((GMLIndexWorker)index.getWorker()).search(broker, EPSG4326_geometry, SpatialOperator.OVERLAPS);
                //assertTrue(ns.getLength() > 0);
            }
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

    public NodeSet search(int contextId, DocumentSet docs, List<QName> qnames, String query, String ngram, XQueryContext context, NodeSet contextSet, int axis)
throws XPathException {
        if (qnames == null || qnames.isEmpty())
            qnames = getDefinedIndexes(context.getBroker(), docs);
        final NodeSet result = new ExtArrayNodeSet(docs.getDocumentCount(), 250);
        for (Iterator<org.exist.collections.Collection> iter = docs.getCollectionIterator(); iter.hasNext();) {
            final int collectionId = iter.next().getId();
            for (int i = 0; i < qnames.size(); i++) {
                QName qname = qnames.get(i);
                NGramQNameKey key = new NGramQNameKey(collectionId, qname, index.getBrokerPool().getSymbols(), query);
                final Lock lock = index.db.getLock();
                try {
                    lock.acquire(Lock.READ_LOCK);
                    SearchCallback cb = new SearchCallback(contextId, query, ngram, docs, contextSet, context, result, axis == NodeSet.ANCESTOR);
                    int op = query.codePointCount(0, query.length()) < getN() ? IndexQuery.TRUNC_RIGHT : IndexQuery.EQ;
                    index.db.query(new IndexQuery(op, key), cb);
                } catch (LockException e) {
                    LOG.warn("Failed to acquire lock for '" + index.db.getFile().getName() + "'", e);
                } catch (IOException e) {
                    LOG.error(e.getMessage() + " in '" + index.db.getFile().getName() + "'", e);
                } catch (BTreeException e) {
                    LOG.error(e.getMessage() + " in '" + index.db.getFile().getName() + "'", e);
                } finally {
                    lock.release(Lock.READ_LOCK);
                }
            }
        }

        result.iterate(); // ensure result is ready to use

        return result;
    }
View Full Code Here

             * If yes, scan the ancestor to get the offset of the first character
             * in the current node. For example, if the indexed node is &lt;a>abc&lt;b>de&lt;/b></a>
             * and we query for //a[text:ngram-contains(., 'de')]/b, proxy will be a &lt;b> node, but
             * the offsets of the matches are relative to the start of &lt;a>.
             */
            NodeSet ancestors = null;
            Match nextMatch = this.match;
            while (nextMatch != null) {
                if (proxy.getNodeId().isDescendantOf(nextMatch.getNodeId())) {
                    if (ancestors == null)
                        ancestors = new ExtArrayNodeSet();
                    ancestors.add(new NodeProxy(proxy.getDocument(), nextMatch.getNodeId()));
                }
                nextMatch = nextMatch.getNextMatch();
            }
            if (ancestors != null && !ancestors.isEmpty()) {
                for (NodeProxy p : ancestors) {
                    int startOffset = 0;
                    try {
                        XMLStreamReader reader = broker.getXMLStreamReader(p, false);
                        while (reader.hasNext()) {
View Full Code Here

        * If yes, scan the ancestor to get the offset of the first character
        * in the current node. For example, if the indexed node is &lt;a>abc&lt;b>de&lt;/b></a>
        * and we query for //a[text:ngram-contains(., 'de')]/b, proxy will be a &lt;b> node, but
        * the offsets of the matches are relative to the start of &lt;a>.
        */
        NodeSet ancestors = null;
        Match nextMatch = this.match;
        while (nextMatch != null) {
            if (proxy.getNodeId().isDescendantOf(nextMatch.getNodeId())) {
                if (ancestors == null)
                    {ancestors = new ExtArrayNodeSet();}
                ancestors.add(new NodeProxy(proxy.getDocument(), nextMatch.getNodeId()));
            }
            nextMatch = nextMatch.getNextMatch();
        }
        if (ancestors != null && !ancestors.isEmpty()) {
            for (final Iterator<NodeProxy> i = ancestors.iterator(); i.hasNext();) {
                final NodeProxy p = i.next();
                int startOffset = 0;
                try {
                    final XMLStreamReader reader = broker.getXMLStreamReader(p, false);
                    while (reader.hasNext()) {
View Full Code Here

     * @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" +
View Full Code Here

        return result;  
       
  }

  private void getIdRef(NodeSet result, DocumentSet docs, String id) throws XPathException {
    final NodeSet attribs = context.getBroker().getValueIndex().find(context.getWatchDog(), Constants.EQ, docs, null, -1, null, new StringValue(id, Type.IDREF));

    for (final NodeProxy n : attribs) {
            n.setNodeType(Node.ATTRIBUTE_NODE);
            result.add(n);
    }
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.