01: package org.apache.lucene.benchmark.byTask.tasks;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * 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.analysis.Analyzer;
21: import org.apache.lucene.benchmark.byTask.PerfRunData;
22: import org.apache.lucene.benchmark.byTask.utils.Config;
23: import org.apache.lucene.index.IndexWriter;
24: import org.apache.lucene.store.Directory;
25:
26: import java.io.IOException;
27:
28: /**
29: * Create an index.
30: * <br>Other side effects: index writer object in perfRunData is set.
31: * <br>Relevant properties: <code>merge.factor, max.buffered,
32: * max.field.length, ram.flush.mb [default 0], autocommit
33: * [default true]</code>.
34: */
35: public class CreateIndexTask extends PerfTask {
36:
37: public CreateIndexTask(PerfRunData runData) {
38: super (runData);
39: }
40:
41: public int doLogic() throws IOException {
42: Directory dir = getRunData().getDirectory();
43: Analyzer analyzer = getRunData().getAnalyzer();
44:
45: Config config = getRunData().getConfig();
46:
47: boolean cmpnd = config.get("compound", true);
48: int mrgf = config.get("merge.factor",
49: OpenIndexTask.DEFAULT_MERGE_PFACTOR);
50: int mxbf = config.get("max.buffered",
51: OpenIndexTask.DEFAULT_MAX_BUFFERED);
52: int mxfl = config.get("max.field.length",
53: OpenIndexTask.DEFAULT_MAX_FIELD_LENGTH);
54: double flushAtRAMUsage = config.get("ram.flush.mb",
55: OpenIndexTask.DEFAULT_RAM_FLUSH_MB);
56: boolean autoCommit = config.get("autocommit",
57: OpenIndexTask.DEFAULT_AUTO_COMMIT);
58:
59: IndexWriter iw = new IndexWriter(dir, autoCommit, analyzer,
60: true);
61:
62: iw.setUseCompoundFile(cmpnd);
63: iw.setMergeFactor(mrgf);
64: iw.setMaxFieldLength(mxfl);
65: iw.setRAMBufferSizeMB(flushAtRAMUsage);
66: iw.setMaxBufferedDocs(mxbf);
67: getRunData().setIndexWriter(iw);
68: return 1;
69: }
70:
71: }
|