01: package org.apache.lucene.benchmark.stats;
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 java.util.Vector;
20:
21: import org.apache.lucene.search.Query;
22: import org.apache.lucene.benchmark.Constants;
23:
24: /**
25: * This class holds parameters for a query benchmark.
26: *
27: * @author Andrzej Bialecki <ab@getopt.org>
28: */
29: public class QueryData {
30: /** Benchmark id */
31: public String id;
32: /** Lucene query */
33: public Query q;
34: /** If true, re-open index reader before benchmark. */
35: public boolean reopen;
36: /** If true, warm-up the index reader before searching by sequentially
37: * retrieving all documents from index.
38: */
39: public boolean warmup;
40: /**
41: * If true, actually retrieve documents returned in Hits.
42: */
43: public boolean retrieve;
44:
45: /**
46: * Prepare a list of benchmark data, using all possible combinations of
47: * benchmark parameters.
48: * @param queries source Lucene queries
49: * @return The QueryData
50: */
51: public static QueryData[] getAll(Query[] queries) {
52: Vector vqd = new Vector();
53: for (int i = 0; i < queries.length; i++) {
54: for (int r = 1; r >= 0; r--) {
55: for (int w = 1; w >= 0; w--) {
56: for (int t = 0; t < 2; t++) {
57: QueryData qd = new QueryData();
58: qd.id = "qd-" + i + r + w + t;
59: qd.reopen = Constants.BOOLEANS[r]
60: .booleanValue();
61: qd.warmup = Constants.BOOLEANS[w]
62: .booleanValue();
63: qd.retrieve = Constants.BOOLEANS[t]
64: .booleanValue();
65: qd.q = queries[i];
66: vqd.add(qd);
67: }
68: }
69: }
70: }
71: return (QueryData[]) vqd.toArray(new QueryData[0]);
72: }
73:
74: /** Short legend for interpreting toString() output. */
75: public static String getLabels() {
76: return "# Query data: R-reopen, W-warmup, T-retrieve, N-no";
77: }
78:
79: public String toString() {
80: return id + " " + (reopen ? "R" : "NR") + " "
81: + (warmup ? "W" : "NW") + " " + (retrieve ? "T" : "NT")
82: + " [" + q.toString() + "]";
83: }
84: }
|