add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / benchmark / src / java / org / apache / lucene / benchmark / byTask / tasks / OpenIndexTask.java
1 package org.apache.lucene.benchmark.byTask.tasks;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * the License.  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 import org.apache.lucene.benchmark.byTask.PerfRunData;
21 import org.apache.lucene.benchmark.byTask.utils.Config;
22 import org.apache.lucene.index.IndexWriter;
23 import org.apache.lucene.index.IndexCommit;
24 import org.apache.lucene.index.IndexWriterConfig;
25 import org.apache.lucene.index.LogMergePolicy;
26 import org.apache.lucene.index.IndexWriter.MaxFieldLength;
27 import org.apache.lucene.index.IndexWriterConfig.OpenMode;
28 import java.io.IOException;
29
30
31 /**
32  * Open an index writer.
33  * <br>Other side effects: index writer object in perfRunData is set.
34  * <br>Relevant properties: <code>merge.factor, max.buffered,
35  * max.field.length, ram.flush.mb [default 0]</code>.
36  *
37  * <p> Accepts a param specifying the commit point as
38  * previously saved with CommitIndexTask.  If you specify
39  * this, it rolls the index back to that commit on opening
40  * the IndexWriter.
41  */
42 public class OpenIndexTask extends PerfTask {
43
44   public static final int DEFAULT_MAX_BUFFERED = IndexWriterConfig.DEFAULT_MAX_BUFFERED_DOCS;
45   public static final int DEFAULT_MAX_FIELD_LENGTH = MaxFieldLength.UNLIMITED.getLimit();
46   public static final int DEFAULT_MERGE_PFACTOR = LogMergePolicy.DEFAULT_MERGE_FACTOR;
47   public static final double DEFAULT_RAM_FLUSH_MB = (int) IndexWriterConfig.DEFAULT_RAM_BUFFER_SIZE_MB;
48   private String commitUserData;
49
50   public OpenIndexTask(PerfRunData runData) {
51     super(runData);
52   }
53
54   @Override
55   public int doLogic() throws IOException {
56     PerfRunData runData = getRunData();
57     Config config = runData.getConfig();
58     final IndexCommit ic;
59     if (commitUserData != null) {
60       ic = OpenReaderTask.findIndexCommit(runData.getDirectory(), commitUserData);
61     } else {
62       ic = null;
63     }
64     
65     final IndexWriter writer = CreateIndexTask.configureWriter(config, runData, OpenMode.APPEND, ic);
66     runData.setIndexWriter(writer);
67     return 1;
68   }
69
70   @Override
71   public void setParams(String params) {
72     super.setParams(params);
73     if (params != null) {
74       // specifies which commit point to open
75       commitUserData = params;
76     }
77   }
78
79   @Override
80   public boolean supportsParams() {
81     return true;
82   }
83 }