1 package org.apache.lucene.benchmark.byTask.feeds;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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 import org.apache.lucene.benchmark.byTask.tasks.NewAnalyzerTask;
28 import org.apache.lucene.util.Version;
30 import java.util.ArrayList;
33 * A QueryMaker that makes queries for a collection created
34 * using {@link org.apache.lucene.benchmark.byTask.feeds.SingleDocSource}.
36 public class SimpleQueryMaker extends AbstractQueryMaker {
39 * Prepare the queries for this test.
40 * Extending classes can override this method for preparing different queries.
41 * @return prepared queries.
42 * @throws Exception if cannot prepare the queries.
45 protected Query[] prepareQueries() throws Exception {
46 // analyzer (default is standard analyzer)
47 Analyzer anlzr= NewAnalyzerTask.createAnalyzer(config.get("analyzer",
48 "org.apache.lucene.analysis.standard.StandardAnalyzer"));
50 QueryParser qp = new QueryParser(Version.LUCENE_CURRENT, DocMaker.BODY_FIELD,anlzr);
51 ArrayList<Query> qq = new ArrayList<Query>();
52 Query q1 = new TermQuery(new Term(DocMaker.ID_FIELD,"doc2"));
54 Query q2 = new TermQuery(new Term(DocMaker.BODY_FIELD,"simple"));
56 BooleanQuery bq = new BooleanQuery();
57 bq.add(q1,Occur.MUST);
58 bq.add(q2,Occur.MUST);
60 qq.add(qp.parse("synthetic body"));
61 qq.add(qp.parse("\"synthetic body\""));
62 qq.add(qp.parse("synthetic text"));
63 qq.add(qp.parse("\"synthetic text\""));
64 qq.add(qp.parse("\"synthetic text\"~3"));
65 qq.add(qp.parse("zoom*"));
66 qq.add(qp.parse("synth*"));
67 return qq.toArray(new Query[0]);