01: package org.compass.core.lucene.engine.indexdeletionpolicy;
02:
03: import java.io.IOException;
04: import java.util.Iterator;
05: import java.util.List;
06:
07: import org.apache.lucene.index.IndexCommitPoint;
08: import org.apache.lucene.index.IndexDeletionPolicy;
09:
10: /**
11: * An index deletion policy that deletes all commits when initialized.
12: *
13: * @author kimchy
14: * @see org.compass.core.lucene.engine.indexdeletionpolicy.IndexDeletionPolicyFactory
15: */
16: public class KeepNoneOnInitDeletionPolicy implements
17: IndexDeletionPolicy {
18:
19: public void onInit(List commits) throws IOException {
20: Iterator it = commits.iterator();
21: while (it.hasNext()) {
22: ((IndexCommitPoint) it.next()).delete();
23: }
24: }
25:
26: public void onCommit(List commits) throws IOException {
27: int size = commits.size();
28: // Delete all but last one:
29: for (int i = 0; i < size - 1; i++) {
30: ((IndexCommitPoint) commits.get(i)).delete();
31: }
32: }
33: }
|