add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / benchmark / src / java / org / apache / lucene / benchmark / byTask / tasks / DeleteDocTask.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.index.IndexReader;
22
23 /**
24  * Delete a document by docid. If no docid param is supplied, deletes doc with
25  * <code>id = last-deleted-doc + doc.delete.step</code>.
26  */
27 public class DeleteDocTask extends PerfTask {
28
29   /**
30    * Gap between ids of deleted docs, applies when no docid param is provided.
31    */
32   public static final int DEFAULT_DOC_DELETE_STEP = 8;
33   
34   public DeleteDocTask(PerfRunData runData) {
35     super(runData);
36   }
37
38   private int deleteStep = -1;
39   private static int lastDeleted = -1;
40
41   private int docid = -1;
42   private boolean byStep = true;
43   
44   @Override
45   public int doLogic() throws Exception {
46     IndexReader r = getRunData().getIndexReader();
47     r.deleteDocument(docid);
48     lastDeleted = docid;
49     r.decRef();
50     return 1; // one work item done here
51   }
52
53   /* (non-Javadoc)
54    * @see org.apache.lucene.benchmark.byTask.tasks.PerfTask#setup()
55    */
56   @Override
57   public void setup() throws Exception {
58     super.setup();
59     if (deleteStep<0) {
60       deleteStep = getRunData().getConfig().get("doc.delete.step",DEFAULT_DOC_DELETE_STEP);
61     }
62     // set the docid to be deleted
63     docid = (byStep ? lastDeleted + deleteStep : docid);
64   }
65
66   @Override
67   protected String getLogMessage(int recsCount) {
68     return "deleted " + recsCount + " docs, last deleted: " + lastDeleted;
69   }
70   
71   /**
72    * Set the params (docid only)
73    * @param params docid to delete, or -1 for deleting by delete gap settings.
74    */
75   @Override
76   public void setParams(String params) {
77     super.setParams(params);
78     docid = (int) Float.parseFloat(params);
79     byStep = (docid < 0);
80   }
81   
82   /* (non-Javadoc)
83    * @see org.apache.lucene.benchmark.byTask.tasks.PerfTask#supportsParams()
84    */
85   @Override
86   public boolean supportsParams() {
87     return true;
88   }
89
90 }