Java Code Examples for org.apache.lucene.index.IndexReader#incRef()

The following examples show how to use org.apache.lucene.index.IndexReader#incRef() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Apply the filter
 * 
 * @param id String
 * @param reader IndexReader
 * @param deleteNodesOnly boolean
 */
public FilterIndexReaderByStringId(String id, IndexReader reader, Set<String> deletions, Set<String> containerDeletions, boolean deleteNodesOnly)
{
    super(reader);
    reader.incRef();
    this.id = id;
    this.deletions = deletions;
    this.containerDeletions = containerDeletions;
    this.deleteNodesOnly = deleteNodesOnly;
    
    if (s_logger.isDebugEnabled())
    {
        s_logger.debug("Applying deletions FOR "+id +" (the index ito which these are applied is the previous one ...)");
    }

}
 
Example 2
public IndexSearcherCloseable getIndexSearcher(boolean security) throws IOException {
  final IndexReader indexReader;
  _indexRefreshReadLock.lock();
  try {
    indexReader = _indexReader.get();
    indexReader.incRef();
  } finally {
    _indexRefreshReadLock.unlock();
  }
  if (indexReader instanceof ExitableReader) {
    ((ExitableReader) indexReader).reset();
  }
  if (security) {
    return getSecureIndexSearcher(indexReader);
  } else {
    return getInsecureIndexSearcher(indexReader);
  }
}
 
Example 3
/**
 * Get the main reader for committed index data
 * 
 * @return IndexReader
 * @throws IOException
 */
public IndexReader getMainIndexReferenceCountingReadOnlyIndexReader() throws IOException
{
    getReadLock();
    try
    {
        // Check if we need to rebuild the main indexer as it is invalid.
        // (it is shared and quick version check fails)
        if (indexIsShared && !checkVersion())
        {
            releaseReadLock();
            getWriteLock();
            try
            {
                if (mainIndexReader != null)
                {
                    ((ReferenceCounting)mainIndexReader).setInvalidForReuse();
                }
                mainIndexReader = null;
            }
            finally
            {
                getReadLock();
                releaseWriteLock();
            }
        }

        // Build if required
        if (mainIndexReader == null)
        {
            releaseReadLock();
            getWriteLock();
            try
            {
                if (mainIndexReader == null)
                {
                    // Sync with disk image if required
                    doWithFileLock(new LockWork<Object>()
                    {
                        public Object doWork() throws Exception
                        {
                            return null;
                        }

                        public boolean canRetry()
                        {
                            return true;
                        }

                    });
                    mainIndexReader = createMainIndexReader();

                }

            }
            finally
            {
                getReadLock();
                releaseWriteLock();
            }
        }
        // Manage reference counting
        mainIndexReader.incRef();
        if (s_logger.isDebugEnabled())
        {
            s_logger.debug("Main index reader references = " + ((ReferenceCounting) mainIndexReader).getReferenceCount());
        }

        // ALF-10040: Wrap with a one-off CachingIndexReader (with cache disabled) so that LeafScorer behaves and passes through SingleFieldSelectors to the main index readers
        IndexReader reader = ReferenceCountingReadOnlyIndexReaderFactory.createReader(MAIN_READER + GUID.generate(), mainIndexReader, false, config);
        ReferenceCounting refCounting = (ReferenceCounting) reader;
        reader.incRef();
        refCounting.setInvalidForReuse();
        return reader;
    }
    catch (RuntimeException e)
    {
        e.printStackTrace();
        throw e;
    }
    finally
    {
        releaseReadLock();
    }
}