Add IndexReader.undeleteAll().

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150111 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Doug Cutting 2003-10-21 18:24:23 +00:00
parent f0d57d81a3
commit ede163802d
5 changed files with 29 additions and 0 deletions

View File

@ -52,6 +52,9 @@ $Id$
stop most OutOfMemoryExceptions by prefix, wildcard and fuzzy
queries which run amok. (cutting)
13. Add new method: IndexReader.undeleteAll(). This undeletes all
deleted documents which still remain in the index. (cutting)
1.3 RC1

View File

@ -124,6 +124,7 @@ public class FilterIndexReader extends IndexReader {
public boolean isDeleted(int n) { return in.isDeleted(n); }
public boolean hasDeletions() { return in.hasDeletions(); }
public void undeleteAll() throws IOException { in.undeleteAll(); }
public byte[] norms(String f) throws IOException { return in.norms(f); }

View File

@ -318,6 +318,9 @@ public abstract class IndexReader {
return n;
}
/** Undeletes all documents currently marked as deleted in this index.*/
public abstract void undeleteAll() throws IOException;
/**
* Closes files associated with this index.
* Also saves any new deletions to disk.

View File

@ -185,6 +185,23 @@ final class SegmentReader extends IndexReader {
deletedDocs.set(docNum);
}
public void undeleteAll() throws IOException {
synchronized (directory()) { // in- & inter-process sync
new Lock.With(directory().makeLock(IndexWriter.COMMIT_LOCK_NAME),
IndexWriter.COMMIT_LOCK_TIMEOUT) {
public Object doBody() throws IOException {
if (directory().fileExists(segment + ".del")) {
directory().deleteFile(segment + ".del");
}
return null;
}
};
deletedDocs = null;
deletedDocsDirty = false;
}
}
final Vector files() throws IOException {
Vector files = new Vector(16);
final String ext[] = new String[] {

View File

@ -125,6 +125,11 @@ final class SegmentsReader extends IndexReader
hasDeletions = true;
}
public void undeleteAll() throws IOException {
for (int i = 0; i < readers.length; i++)
readers[i].undeleteAll();
}
private final int readerIndex(int n) { // find reader for doc n:
int lo = 0; // search starts array
int hi = readers.length - 1; // for first element less