1 package org.apache.lucene.benchmark.byTask.tasks;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import org.apache.lucene.benchmark.byTask.PerfRunData;
21 import org.apache.lucene.index.IndexReader;
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>.
27 public class DeleteDocTask extends PerfTask {
30 * Gap between ids of deleted docs, applies when no docid param is provided.
32 public static final int DEFAULT_DOC_DELETE_STEP = 8;
34 public DeleteDocTask(PerfRunData runData) {
38 private int deleteStep = -1;
39 private static int lastDeleted = -1;
41 private int docid = -1;
42 private boolean byStep = true;
45 public int doLogic() throws Exception {
46 IndexReader r = getRunData().getIndexReader();
47 r.deleteDocument(docid);
50 return 1; // one work item done here
54 * @see org.apache.lucene.benchmark.byTask.tasks.PerfTask#setup()
57 public void setup() throws Exception {
60 deleteStep = getRunData().getConfig().get("doc.delete.step",DEFAULT_DOC_DELETE_STEP);
62 // set the docid to be deleted
63 docid = (byStep ? lastDeleted + deleteStep : docid);
67 protected String getLogMessage(int recsCount) {
68 return "deleted " + recsCount + " docs, last deleted: " + lastDeleted;
72 * Set the params (docid only)
73 * @param params docid to delete, or -1 for deleting by delete gap settings.
76 public void setParams(String params) {
77 super.setParams(params);
78 docid = (int) Float.parseFloat(params);
83 * @see org.apache.lucene.benchmark.byTask.tasks.PerfTask#supportsParams()
86 public boolean supportsParams() {