1
package org.apache.lucene.benchmark.byTask.tasks;
3
* Copyright 2005 The Apache Software Foundation
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
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.document.Document;
23
import org.apache.lucene.index.IndexReader;
25
import java.util.StringTokenizer;
27
import java.util.HashSet;
28
import java.util.Collections;
29
import java.io.IOException;
32
* Search and Traverse and Retrieve docs task using a SetBasedFieldSelector.
34
* <p>Note: This task reuses the reader if it is already open.
35
* Otherwise a reader is opened at start and closed at the end.
37
* <p>Takes optional param: comma separated list of Fields to load.</p>
39
* <p>Other side effects: counts additional 1 (record) for each traversed hit,
40
* and 1 more for each retrieved (non null) document.</p>
42
public class SearchTravRetLoadFieldSelectorTask extends SearchTravTask {
44
protected FieldSelector fieldSelector;
45
public SearchTravRetLoadFieldSelectorTask(PerfRunData runData) {
51
public boolean withRetrieve() {
57
protected Document retrieveDoc(IndexReader ir, int id) throws IOException {
58
return ir.document(id, fieldSelector);
62
public void setParams(String params) {
63
this.params = params; // cannot just call super.setParams(), b/c it's params differ.
64
Set<String> fieldsToLoad = new HashSet<String>();
65
for (StringTokenizer tokenizer = new StringTokenizer(params, ","); tokenizer.hasMoreTokens();) {
66
String s = tokenizer.nextToken();
69
fieldSelector = new SetBasedFieldSelector(fieldsToLoad, Collections.<String> emptySet());
74
* @see org.apache.lucene.benchmark.byTask.tasks.PerfTask#supportsParams()
77
public boolean supportsParams() {