add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / benchmark / src / java / org / apache / lucene / benchmark / byTask / feeds / SimpleQueryMaker.java
1 package org.apache.lucene.benchmark.byTask.feeds;
2
3 /**
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
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 import org.apache.lucene.benchmark.byTask.tasks.NewAnalyzerTask;
28 import org.apache.lucene.util.Version;
29
30 import java.util.ArrayList;
31
32 /**
33  * A QueryMaker that makes queries for a collection created 
34  * using {@link org.apache.lucene.benchmark.byTask.feeds.SingleDocSource}.
35  */
36 public class SimpleQueryMaker extends AbstractQueryMaker implements QueryMaker {
37
38
39   /**
40    * Prepare the queries for this test.
41    * Extending classes can override this method for preparing different queries. 
42    * @return prepared queries.
43    * @throws Exception if cannot prepare the queries.
44    */
45   @Override
46   protected Query[] prepareQueries() throws Exception {
47     // analyzer (default is standard analyzer)
48     Analyzer anlzr= NewAnalyzerTask.createAnalyzer(config.get("analyzer",
49         "org.apache.lucene.analysis.standard.StandardAnalyzer")); 
50     
51     QueryParser qp = new QueryParser(Version.LUCENE_CURRENT, DocMaker.BODY_FIELD,anlzr);
52     ArrayList<Query> qq = new ArrayList<Query>();
53     Query q1 = new TermQuery(new Term(DocMaker.ID_FIELD,"doc2"));
54     qq.add(q1);
55     Query q2 = new TermQuery(new Term(DocMaker.BODY_FIELD,"simple"));
56     qq.add(q2);
57     BooleanQuery bq = new BooleanQuery();
58     bq.add(q1,Occur.MUST);
59     bq.add(q2,Occur.MUST);
60     qq.add(bq);
61     qq.add(qp.parse("synthetic body"));
62     qq.add(qp.parse("\"synthetic body\""));
63     qq.add(qp.parse("synthetic text"));
64     qq.add(qp.parse("\"synthetic text\""));
65     qq.add(qp.parse("\"synthetic text\"~3"));
66     qq.add(qp.parse("zoom*"));
67     qq.add(qp.parse("synth*"));
68     return  qq.toArray(new Query[0]);
69   }
70
71 }