01: package org.apache.lucene.benchmark.byTask.feeds;
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.search.Query;
20: import org.apache.lucene.benchmark.byTask.utils.Config;
21: import org.apache.lucene.benchmark.byTask.utils.Format;
22:
23: /**
24: * Abstract base query maker.
25: * Each query maker should just implement the {@link #prepareQueries()} method.
26: **/
27: public abstract class AbstractQueryMaker implements QueryMaker {
28:
29: protected int qnum = 0;
30: protected Query[] queries;
31: protected Config config;
32:
33: public void resetInputs() {
34: qnum = 0;
35: }
36:
37: protected abstract Query[] prepareQueries() throws Exception;
38:
39: public void setConfig(Config config) throws Exception {
40: this .config = config;
41: queries = prepareQueries();
42: }
43:
44: public String printQueries() {
45: String newline = System.getProperty("line.separator");
46: StringBuffer sb = new StringBuffer();
47: if (queries != null) {
48: for (int i = 0; i < queries.length; i++) {
49: sb.append(i + ". "
50: + Format.simpleName(queries[i].getClass())
51: + " - " + queries[i].toString());
52: sb.append(newline);
53: }
54: }
55: return sb.toString();
56: }
57:
58: public Query makeQuery() throws Exception {
59: return queries[nextQnum()];
60: }
61:
62: // return next qnum
63: protected synchronized int nextQnum() {
64: int res = qnum;
65: qnum = (qnum + 1) % queries.length;
66: return res;
67: }
68:
69: /*
70: * (non-Javadoc)
71: * @see org.apache.lucene.benchmark.byTask.feeds.QueryMaker#makeQuery(int)
72: */
73: public Query makeQuery(int size) throws Exception {
74: throw new Exception(this
75: + ".makeQuery(int size) is not supported!");
76: }
77: }
|