Search in sources :

Example 1 with TermDocs

use of org.apache.lucene.index.TermDocs in project zm-mailbox by Zimbra.

the class TermsFilter method getDocIdSet.

/** (non-Javadoc)
     * @see org.apache.lucene.search.Filter#getDocIdSet(org.apache.lucene.index.IndexReader)
     */
@Override
public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
    OpenBitSet result = new OpenBitSet(reader.maxDoc());
    TermDocs td = reader.termDocs();
    try {
        for (Iterator<Term> iter = terms.iterator(); iter.hasNext(); ) {
            Term term = iter.next();
            td.seek(term);
            while (td.next()) {
                result.set(td.doc());
            }
        }
    } finally {
        Closeables.closeQuietly(td);
    }
    return result;
}
Also used : OpenBitSet(org.apache.lucene.util.OpenBitSet) TermDocs(org.apache.lucene.index.TermDocs) Term(org.apache.lucene.index.Term)

Example 2 with TermDocs

use of org.apache.lucene.index.TermDocs in project jackrabbit by apache.

the class CachingIndexReader method termDocs.

/**
     * If the field of <code>term</code> is {@link FieldNames#UUID} this
     * <code>CachingIndexReader</code> returns a <code>TermDocs</code> instance
     * with a cached document id. If <code>term</code> has any other field
     * the call is delegated to the base <code>IndexReader</code>.<br/>
     * If <code>term</code> is for a {@link FieldNames#UUID} field and this
     * <code>CachingIndexReader</code> does not have such a document,
     * {@link EmptyTermDocs#INSTANCE} is returned.
     *
     * @param term the term to start the <code>TermDocs</code> enumeration.
     * @return a TermDocs instance.
     * @throws IOException if an error occurs while reading from the index.
     */
public TermDocs termDocs(Term term) throws IOException {
    if (term != null && term.field() == FieldNames.UUID) {
        // check cache if we have one
        if (cache != null) {
            DocNumberCache.Entry e = cache.get(term.text());
            if (e != null) {
                // newer index.
                if (e.creationTick == creationTick && !isDeleted(e.doc)) {
                    return new SingleTermDocs(e.doc);
                }
            }
            // not in cache or invalid
            TermDocs docs = in.termDocs(term);
            try {
                if (docs.next()) {
                    // put to cache
                    cache.put(term.text(), this, docs.doc());
                    // and return
                    return new SingleTermDocs(docs.doc());
                } else {
                    return EmptyTermDocs.INSTANCE;
                }
            } finally {
                docs.close();
            }
        }
    }
    return termDocsCache.termDocs(term);
}
Also used : TermDocs(org.apache.lucene.index.TermDocs)

Example 3 with TermDocs

use of org.apache.lucene.index.TermDocs in project jackrabbit by apache.

the class CachingIndexReader method initShareableNodes.

private BitSet initShareableNodes(IndexReader delegatee) throws IOException {
    BitSet shareableNodes = new BitSet();
    TermDocs tDocs = delegatee.termDocs(new Term(FieldNames.SHAREABLE_NODE, ""));
    try {
        while (tDocs.next()) {
            shareableNodes.set(tDocs.doc());
        }
    } finally {
        tDocs.close();
    }
    return shareableNodes;
}
Also used : TermDocs(org.apache.lucene.index.TermDocs) BitSet(java.util.BitSet) Term(org.apache.lucene.index.Term)

Example 4 with TermDocs

use of org.apache.lucene.index.TermDocs in project jackrabbit by apache.

the class CachingMultiIndexReader method createDocId.

/**
     * {@inheritDoc}
     */
public ForeignSegmentDocId createDocId(NodeId id) throws IOException {
    Term term = TermFactory.createUUIDTerm(id.toString());
    int doc;
    long tick;
    for (ReadOnlyIndexReader subReader : subReaders) {
        TermDocs docs = subReader.termDocs(term);
        try {
            if (docs.next()) {
                doc = docs.doc();
                tick = subReader.getCreationTick();
                return new ForeignSegmentDocId(doc, tick);
            }
        } finally {
            docs.close();
        }
    }
    return null;
}
Also used : TermDocs(org.apache.lucene.index.TermDocs) Term(org.apache.lucene.index.Term)

Example 5 with TermDocs

use of org.apache.lucene.index.TermDocs in project jackrabbit by apache.

the class SearchIndex method retrieveAggregateRoot.

/**
     * Retrieves the root of the indexing aggregate for <code>removedIds</code>
     * and puts it into <code>map</code>.
     *
     * @param removedIds the ids of removed nodes.
     * @param aggregates aggregate roots are collected in this map
     */
protected void retrieveAggregateRoot(Set<NodeId> removedIds, Map<NodeId, NodeState> aggregates) {
    if (removedIds.isEmpty() || indexingConfig == null) {
        return;
    }
    AggregateRule[] aggregateRules = indexingConfig.getAggregateRules();
    if (aggregateRules == null) {
        return;
    }
    int found = 0;
    long time = System.currentTimeMillis();
    try {
        CachingMultiIndexReader reader = index.getIndexReader();
        try {
            Term aggregateIds = new Term(FieldNames.AGGREGATED_NODE_UUID, "");
            TermDocs tDocs = reader.termDocs();
            try {
                ItemStateManager ism = getContext().getItemStateManager();
                for (NodeId id : removedIds) {
                    aggregateIds = aggregateIds.createTerm(id.toString());
                    tDocs.seek(aggregateIds);
                    while (tDocs.next()) {
                        Document doc = reader.document(tDocs.doc(), FieldSelectors.UUID);
                        NodeId nId = new NodeId(doc.get(FieldNames.UUID));
                        NodeState nodeState = (NodeState) ism.getItemState(nId);
                        aggregates.put(nId, nodeState);
                        found++;
                        // JCR-2989 Support for embedded index aggregates
                        int sizeBefore = aggregates.size();
                        retrieveAggregateRoot(nodeState, aggregates);
                        found += aggregates.size() - sizeBefore;
                    }
                }
            } finally {
                tDocs.close();
            }
        } finally {
            reader.release();
        }
    } catch (NoSuchItemStateException e) {
        log.info("Exception while retrieving aggregate roots. Node is not available {}.", e.getMessage());
    } catch (Exception e) {
        log.warn("Exception while retrieving aggregate roots", e);
    }
    time = System.currentTimeMillis() - time;
    log.debug("Retrieved {} aggregate roots in {} ms.", found, time);
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) TermDocs(org.apache.lucene.index.TermDocs) Term(org.apache.lucene.index.Term) Document(org.apache.lucene.document.Document) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) SAXException(org.xml.sax.SAXException) JournalException(org.apache.jackrabbit.core.journal.JournalException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) RepositoryException(javax.jcr.RepositoryException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) InvalidQueryException(javax.jcr.query.InvalidQueryException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NodeId(org.apache.jackrabbit.core.id.NodeId) ItemStateManager(org.apache.jackrabbit.core.state.ItemStateManager)

Aggregations

TermDocs (org.apache.lucene.index.TermDocs)17 Term (org.apache.lucene.index.Term)13 TermEnum (org.apache.lucene.index.TermEnum)5 Document (org.apache.lucene.document.Document)4 BitSet (java.util.BitSet)3 RepositoryException (javax.jcr.RepositoryException)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 NodeId (org.apache.jackrabbit.core.id.NodeId)2 IndexReader (org.apache.lucene.index.IndexReader)2 FixedBitSet (org.apache.lucene.util.FixedBitSet)2 MalformedURLException (java.net.MalformedURLException)1 LinkedHashMap (java.util.LinkedHashMap)1 WeakHashMap (java.util.WeakHashMap)1 Node (javax.jcr.Node)1 Session (javax.jcr.Session)1 InvalidQueryException (javax.jcr.query.InvalidQueryException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)1