FileDocCategorySizeDatePackage
SimpleQueryMaker.javaAPI DocApache Lucene 2.1.03853Wed Feb 14 10:46:16 GMT 2007org.apache.lucene.benchmark.byTask.feeds

SimpleQueryMaker

public class SimpleQueryMaker extends Object implements QueryMaker
A QueryMaker that makes queries for a collection created using {@link org.apache.lucene.benchmark.byTask.feeds.SimpleDocMaker}.

Fields Summary
private int
qnum
private Query[]
queries
private org.apache.lucene.benchmark.byTask.utils.Config
config
Constructors Summary
Methods Summary
public org.apache.lucene.search.QuerymakeQuery()

    return queries[nextQnum()];
  
public org.apache.lucene.search.QuerymakeQuery(int size)

    throw new Exception(this+".makeQuery(int size) is not supported!");
  
private synchronized intnextQnum()

    int res = qnum;
    qnum = (qnum+1) % queries.length;
    return res;
  
protected org.apache.lucene.search.Query[]prepareQueries()
Prepare the queries for this test. Extending classes can overide this method for preparing different queries.

return
prepared queries.
throws
Exception if canot prepare the queries.

  
                                
       
    // analyzer (default is standard analyzer)
    Analyzer anlzr= (Analyzer) Class.forName(config.get("analyzer",
        "org.apache.lucene.analysis.StandardAnalyzer")).newInstance(); 
    
    QueryParser qp = new QueryParser("body",anlzr);
    ArrayList qq = new ArrayList();
    Query q1 = new TermQuery(new Term("docid","doc2"));
    qq.add(q1);
    Query q2 = new TermQuery(new Term("body","simple"));
    qq.add(q2);
    BooleanQuery bq = new BooleanQuery();
    bq.add(q1,Occur.MUST);
    bq.add(q2,Occur.MUST);
    qq.add(bq);
    qq.add(qp.parse("synthetic body"));
    qq.add(qp.parse("\"synthetic body\""));
    qq.add(qp.parse("synthetic text"));
    qq.add(qp.parse("\"synthetic text\""));
    qq.add(qp.parse("\"synthetic text\"~3"));
    qq.add(qp.parse("zoom*"));
    qq.add(qp.parse("synth*"));
    return (Query []) qq.toArray(new Query[0]);
  
public java.lang.StringprintQueries()

    String newline = System.getProperty("line.separator");
    StringBuffer sb = new StringBuffer();
    if (queries != null) {
      for (int i = 0; i < queries.length; i++) {
        sb.append(i+". "+Format.simpleName(queries[i].getClass())+" - "+queries[i].toString());
        sb.append(newline);
      }
    }
    return sb.toString();
  
public voidresetInputs()

    qnum = 0;
  
public voidsetConfig(org.apache.lucene.benchmark.byTask.utils.Config config)

    this.config = config;
    queries = prepareQueries();