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;
}
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);
}
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;
}
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;
}
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);
}
Aggregations