// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: IndexWriter.java
package org.apache.lucene.index;
import java.io.*;
import java.util.*;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Similarity;
import org.apache.lucene.store.*;
import org.apache.lucene.util.BitVector;
import org.apache.lucene.util.Constants;
// Referenced classes of package org.apache.lucene.index:
// LogMergePolicy, SegmentInfos, LogByteSizeMergePolicy, ConcurrentMergeScheduler,
// DocumentsWriter, IndexFileDeleter, KeepOnlyLastCommitDeletionPolicy, LogDocMergePolicy,
// CompoundFileWriter, SegmentMerger, SegmentInfo, CorruptIndexException,
// IndexReader, MergePolicy, MergeScheduler, SegmentReader,
// IndexDeletionPolicy, Term
public class IndexWriter
{
public static final class MaxFieldLength
{
private int limit;
private String name;
public static final MaxFieldLength UNLIMITED = new MaxFieldLength("UNLIMITED", 0x7fffffff);
public static final MaxFieldLength LIMITED = new MaxFieldLength("LIMITED", 10000);
public int getLimit()
{
return limit;
}
public String toString()
{
return name + ":" + limit;
}
private MaxFieldLength(String name, int limit)
{
this.name = name;
this.limit = limit;
}
public MaxFieldLength(int limit)
{
this("User-specified", limit);
}
}
public static long WRITE_LOCK_TIMEOUT = 1000L;
private long writeLockTimeout;
public static final String WRITE_LOCK_NAME = "write.lock";
/**
* @deprecated Field DEFAULT_MERGE_FACTOR is deprecated
*/
public static final int DEFAULT_MERGE_FACTOR = 10;
public static final int DISABLE_AUTO_FLUSH = -1;
public static final int DEFAULT_MAX_BUFFERED_DOCS = -1;
public static final double DEFAULT_RAM_BUFFER_SIZE_MB = 16D;
public static final int DEFAULT_MAX_BUFFERED_DELETE_TERMS = -1;
/**
* @deprecated Field DEFAULT_MAX_MERGE_DOCS is deprecated
*/
public static final int DEFAULT_MAX_MERGE_DOCS = 0x7fffffff;
public static final int DEFAULT_MAX_FIELD_LENGTH = 10000;
public static final int DEFAULT_TERM_INDEX_INTERVAL = 128;
public static final int MAX_TERM_LENGTH = 16383;
public static final double DEFAULT_MAX_SYNC_PAUSE_SECONDS;
private static final int MERGE_READ_BUFFER_SIZE = 4096;
private static Object MESSAGE_ID_LOCK = new Object();
private static int MESSAGE_ID = 0;
private int messageID;
private volatile boolean hitOOM;
private Directory directory;
private Analyzer analyzer;
private Similarity similarity;
private volatile long changeCount;
private long lastCommitChangeCount;
private SegmentInfos rollbackSegmentInfos;
private HashMap rollbackSegments;
volatile SegmentInfos pendingCommit;
volatile long pendingCommitChangeCount;
private SegmentInfos localRollbackSegmentInfos;
private boolean localAutoCommit;
private int localFlushedDocCount;
private boolean autoCommit;
private SegmentInfos segmentInfos;
private DocumentsWriter docWriter;
private IndexFileDeleter deleter;
private Set segmentsToOptimize;
private Lock writeLock;
private int termIndexInterval;
private boolean closeDir;
private boolean closed;
private boolean closing;
private HashSet mergingSegments;
private MergePolicy mergePolicy;
private MergeScheduler mergeScheduler;
private LinkedList pendingMerges;
private Set runningMerges;
private List mergeExceptions;
private long mergeGen;
private boolean stopMerges;
private int flushCount;
private int flushDeletesCount;
private double maxSyncPauseSeconds;
private int readCount;
private Thread writeThread;
private int maxFieldLength;
private PrintStream infoStream;
private static PrintStream defaultInfoStream = null;
private boolean committing;
private HashSet synced;
private HashSet syncing;
static final boolean $assertionsDisabled; /* synthetic field */
synchronized void acquireWrite()
{
while (writeThread != null || readCount > 0)
doWait();
ensureOpen();
writeThread = Thread.currentThread();
}
synchronized void releaseWrite()
{
if (!$assertionsDisabled && Thread.currentThread() != writeThread)
{
throw new AssertionError();
} else
{
writeThread = null;
notifyAll();
return;
}
}
synchronized void acquireRead()
{
for (Thread current = Thread.currentThread(); writeThread != null && writeThread != current;)
doWait();
readCount++;
}
synchronized void releaseRead()
{
readCount--;
if (!$assertionsDisabled && readCount < 0)
throw new AssertionError();
if (0 == readCount)
notifyAll();
}
protected final synchronized void ensureOpen(boolean includePendingClose)
throws AlreadyClosedException
{
if (closed || includePendingClose && closing)
throw new AlreadyClosedException("this IndexWriter is closed");
else
return;
}
protected final synchronized void ensureOpen()
throws AlreadyClosedException
{
ensureOpen(true);
}
public void message(String message)
{
if (infoStream != null)
infoStream.println("IW " + messageID + " [" + Thread.currentThread().getName() + "]: " + message);
}
private synchronized void setMessageID(PrintStream infoStream)
{
if (infoStream != null && messageID == -1)
synchronized (MESSAGE_ID_LOCK)
{
messageID = MESSAGE_ID++;
}
this.infoStream = infoStream;
}
private LogMergePolicy getLogMergePolicy()
{
if (mergePolicy instanceof LogMergePolicy)
return (LogMergePolicy)mergePolicy;
else
throw new IllegalArgumentException("this method can only be called when the merge policy is the default LogMergePolicy");
}
public boolean getUseCompoundFile()
{
return getLogMergePolicy().getUseCompoundFile();
}
public void setUseCompoundFile(boolean value)
{
getLogMergePolicy().setUseCompoundFile(value);
getLogMergePolicy().setUseCompoundDocStore(value);
}
public void setSimilarity(Similarity similarity)
{
ensureOpen();
this.similarity = similarity;
docWriter.setSimilarity(similarity);
}
public Similarity getSimilarity()
{
ensureOpen();
return similarity;
}
public void setTermIndexInterval(int interval)
{
ensureOpen();
termIndexInterval = interval;
}
public int getTermIndexInterval()
{
ensureOpen(false);
return termIndexInterval;
}
public IndexWriter(String path, Analyzer a, boolean create, MaxFieldLength mfl)
throws CorruptIndexException, LockObtainFailedException, IOException
{
writeLockTimeout = WRITE_LOCK_TIMEOUT;
messageID = -1;
similarity = Similarity.getDefault();
autoCommit = true;
segmentInfos = new SegmentInfos();
segmentsToOptimize = new HashSet();
termIndexInterval = 128;
mergingSegments = new HashSet();
mergePolicy = new LogByteSizeMergePolicy();
mergeScheduler = new ConcurrentMergeScheduler();
pendingMerges = new LinkedList();
runningMerges = new HashSet();
mergeExceptions = new ArrayList();
maxSyncPauseSeconds = DEFAULT_MAX_SYNC_PAUSE_SECONDS;
infoStream = null;
synced = new HashSet();
syncing = new HashSet();
init(FSDirectory.getDirectory(path), a, create, true, null, false, mfl.getLimit());
}
/**
* @deprecated Method IndexWriter is deprecated
*/
public IndexWriter(String path, Analyzer a, boolean create)
throws CorruptIndexException, LockObtainFailedException, IOException
{
writeLockTimeout = WRITE_LOCK_TIMEOUT;
messageID = -1;
similarity = Similarity.getDefault();
autoCommit = true;
segmentInfos = new SegmentInfos();
segmentsToOptimize = new HashSet();
termIndexInterval = 128;
mergingSegments = new HashSet();