01: package org.apache.lucene.benchmark.byTask.feeds;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: import org.apache.lucene.analysis.Analyzer;
21: import org.apache.lucene.index.Term;
22: import org.apache.lucene.queryParser.QueryParser;
23: import org.apache.lucene.search.BooleanClause.Occur;
24: import org.apache.lucene.search.BooleanQuery;
25: import org.apache.lucene.search.Query;
26: import org.apache.lucene.search.TermQuery;
27:
28: import java.util.ArrayList;
29:
30: /**
31: * A QueryMaker that makes queries for a collection created
32: * using {@link org.apache.lucene.benchmark.byTask.feeds.SimpleDocMaker}.
33: */
34: public class SimpleQueryMaker extends AbstractQueryMaker implements
35: QueryMaker {
36:
37: /**
38: * Prepare the queries for this test.
39: * Extending classes can overide this method for preparing different queries.
40: * @return prepared queries.
41: * @throws Exception if canot prepare the queries.
42: */
43: protected Query[] prepareQueries() throws Exception {
44: // analyzer (default is standard analyzer)
45: Analyzer anlzr = (Analyzer) Class
46: .forName(
47: config
48: .get("analyzer",
49: "org.apache.lucene.analysis.standard.StandardAnalyzer"))
50: .newInstance();
51:
52: QueryParser qp = new QueryParser(BasicDocMaker.BODY_FIELD,
53: anlzr);
54: ArrayList qq = new ArrayList();
55: Query q1 = new TermQuery(new Term(BasicDocMaker.ID_FIELD,
56: "doc2"));
57: qq.add(q1);
58: Query q2 = new TermQuery(new Term(BasicDocMaker.BODY_FIELD,
59: "simple"));
60: qq.add(q2);
61: BooleanQuery bq = new BooleanQuery();
62: bq.add(q1, Occur.MUST);
63: bq.add(q2, Occur.MUST);
64: qq.add(bq);
65: qq.add(qp.parse("synthetic body"));
66: qq.add(qp.parse("\"synthetic body\""));
67: qq.add(qp.parse("synthetic text"));
68: qq.add(qp.parse("\"synthetic text\""));
69: qq.add(qp.parse("\"synthetic text\"~3"));
70: qq.add(qp.parse("zoom*"));
71: qq.add(qp.parse("synth*"));
72: return (Query[]) qq.toArray(new Query[0]);
73: }
74:
75: }
|