01: package org.compass.core.lucene.engine.indexdeletionpolicy;
02:
03: import java.util.List;
04:
05: import org.apache.lucene.index.IndexCommitPoint;
06: import org.apache.lucene.index.IndexDeletionPolicy;
07: import org.compass.core.CompassException;
08: import org.compass.core.config.CompassConfigurable;
09: import org.compass.core.config.CompassSettings;
10: import org.compass.core.lucene.LuceneEnvironment;
11:
12: /**
13: * An index deletion policy that keepds the last "N" commits. Configured using
14: * {@link org.compass.core.lucene.LuceneEnvironment.IndexDeletionPolicy.KeepLastN} settings with
15: * the number of last commits to save. Defaults to <code>10</code>.
16: *
17: * @author kimchy
18: * @see org.compass.core.lucene.engine.indexdeletionpolicy.IndexDeletionPolicyFactory
19: */
20: public class KeepLastNDeletionPolicy implements IndexDeletionPolicy,
21: CompassConfigurable {
22:
23: private int numToKeep;
24:
25: public void configure(CompassSettings settings)
26: throws CompassException {
27: numToKeep = settings
28: .getSettingAsInt(
29: LuceneEnvironment.IndexDeletionPolicy.KeepLastN.NUM_TO_KEEP,
30: 10);
31: }
32:
33: public void onInit(List commits) {
34: onCommit(commits);
35: }
36:
37: public void onCommit(List commits) {
38: int size = commits.size();
39: for (int i = 0; i < size - numToKeep; i++) {
40: ((IndexCommitPoint) commits.get(i)).delete();
41: }
42: }
43: }
|