1 package org.apache.lucene.benchmark.byTask.tasks;
3 * Licensed to the Apache Software Foundation (ASF) under one or more
4 * contributor license agreements. See the NOTICE file distributed with
5 * this work for additional information regarding copyright ownership.
6 * The ASF licenses this file to You under the Apache License, Version 2.0
7 * (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 import org.apache.lucene.benchmark.byTask.PerfRunData;
20 import org.apache.lucene.benchmark.byTask.feeds.QueryMaker;
21 import org.apache.lucene.search.Sort;
22 import org.apache.lucene.search.SortField;
25 * Does sort search on specified field.
28 public class SearchWithSortTask extends ReadTask {
30 private boolean doScore = true;
31 private boolean doMaxScore = true;
34 public SearchWithSortTask(PerfRunData runData) {
39 * SortFields: field:type,field:type[,noscore][,nomaxscore]
41 * If noscore is present, then we turn off score tracking
42 * in {@link org.apache.lucene.search.TopFieldCollector}.
43 * If nomaxscore is present, then we turn off maxScore tracking
44 * in {@link org.apache.lucene.search.TopFieldCollector}.
46 * name:string,page:int,subject:string
50 public void setParams(String sortField) {
51 super.setParams(sortField);
52 String[] fields = sortField.split(",");
53 SortField[] sortFields = new SortField[fields.length];
55 for (int i = 0; i < fields.length; i++) {
56 String field = fields[i];
58 if (field.equals("doc")) {
59 sortField0 = SortField.FIELD_DOC;
60 } else if (field.equals("score")) {
61 sortField0 = SortField.FIELD_SCORE;
62 } else if (field.equals("noscore")) {
65 } else if (field.equals("nomaxscore")) {
69 int index = field.lastIndexOf(":");
73 fieldName = field.substring(0, index);
74 typeString = field.substring(1+index, field.length());
76 throw new RuntimeException("You must specify the sort type ie page:int,subject:string");
78 int type = getType(typeString);
79 sortField0 = new SortField(fieldName, type);
81 sortFields[upto++] = sortField0;
84 if (upto < sortFields.length) {
85 SortField[] newSortFields = new SortField[upto];
86 System.arraycopy(sortFields, 0, newSortFields, 0, upto);
87 sortFields = newSortFields;
89 this.sort = new Sort(sortFields);
92 private int getType(String typeString) {
94 if (typeString.equals("float")) {
95 type = SortField.FLOAT;
96 } else if (typeString.equals("double")) {
97 type = SortField.DOUBLE;
98 } else if (typeString.equals("byte")) {
99 type = SortField.BYTE;
100 } else if (typeString.equals("short")) {
101 type = SortField.SHORT;
102 } else if (typeString.equals("int")) {
103 type = SortField.INT;
104 } else if (typeString.equals("long")) {
105 type = SortField.LONG;
106 } else if (typeString.equals("string")) {
107 type = SortField.STRING;
108 } else if (typeString.equals("string_val")) {
109 type = SortField.STRING_VAL;
111 throw new RuntimeException("Unrecognized sort field type " + typeString);
117 public boolean supportsParams() {
122 public QueryMaker getQueryMaker() {
123 return getRunData().getQueryMaker(this);
127 public boolean withRetrieve() {
132 public boolean withSearch() {
137 public boolean withTraverse() {
142 public boolean withWarm() {
147 public boolean withScore() {
152 public boolean withMaxScore() {
157 public Sort getSort() {
159 throw new IllegalStateException("No sort field was set");