01: package org.apache.lucene.benchmark.byTask.tasks;
02:
03: /**
04: * Copyright 2005 The Apache Software Foundation
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import org.apache.lucene.benchmark.byTask.PerfRunData;
20: import org.apache.lucene.document.FieldSelector;
21: import org.apache.lucene.document.SetBasedFieldSelector;
22: import org.apache.lucene.index.IndexReader;
23:
24: import java.util.StringTokenizer;
25: import java.util.Set;
26: import java.util.HashSet;
27: import java.util.Collections;
28: import java.io.IOException;
29:
30: /**
31: * Search and Traverse and Retrieve docs task using a SetBasedFieldSelector.
32: *
33: * <p>Note: This task reuses the reader if it is already open.
34: * Otherwise a reader is opened at start and closed at the end.
35: *
36: * <p>Takes optional param: comma separated list of Fields to load.</p>
37: *
38: * <p>Other side effects: counts additional 1 (record) for each traversed hit,
39: * and 1 more for each retrieved (non null) document.</p>
40: */
41: public class SearchTravRetLoadFieldSelectorTask extends SearchTravTask {
42:
43: protected FieldSelector fieldSelector;
44:
45: public SearchTravRetLoadFieldSelectorTask(PerfRunData runData) {
46: super (runData);
47:
48: }
49:
50: public boolean withRetrieve() {
51: return true;
52: }
53:
54: protected int retrieveDoc(IndexReader ir, int id)
55: throws IOException {
56: return (ir.document(id, fieldSelector) == null ? 0 : 1);
57: }
58:
59: public void setParams(String params) {
60: this .params = params; // cannot just call super.setParams(), b/c it's params differ.
61: Set fieldsToLoad = new HashSet();
62: for (StringTokenizer tokenizer = new StringTokenizer(params,
63: ","); tokenizer.hasMoreTokens();) {
64: String s = tokenizer.nextToken();
65: fieldsToLoad.add(s);
66: }
67: fieldSelector = new SetBasedFieldSelector(fieldsToLoad,
68: Collections.EMPTY_SET);
69: }
70:
71: /* (non-Javadoc)
72: * @see org.apache.lucene.benchmark.byTask.tasks.PerfTask#supportsParams()
73: */
74: public boolean supportsParams() {
75: return true;
76: }
77: }
|