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

ReutersQueryMaker

public class ReutersQueryMaker extends Object implements QueryMaker
A QueryMaker that makes queries devised manually (by Grant Ingersoll) for searching in the Reuters collection.

Fields Summary
private int
qnum
private Query[]
queries
private org.apache.lucene.benchmark.byTask.utils.Config
config
private static String[]
STANDARD_QUERIES
Constructors Summary
Methods Summary
private static org.apache.lucene.search.Query[]createQueries(java.util.List qs, org.apache.lucene.analysis.Analyzer a)
Parse the strings containing Lucene queries.

param
qs array of strings containing query expressions
param
a analyzer to use when parsing queries
return
array of Lucene queries

    QueryParser qp = new QueryParser("body", a);
    List queries = new ArrayList();
    for (int i = 0; i < qs.size(); i++)  {
      try {
        
        Object query = qs.get(i);
        Query q = null;
        if (query instanceof String) {
          q = qp.parse((String) query);
          
        } else if (query instanceof Query) {
          q = (Query) query;
          
        } else {
          System.err.println("Unsupported Query Type: " + query);
        }
        
        if (q != null) {
          queries.add(q);
        }
        
      } catch (Exception e)  {
        e.printStackTrace();
      }
    }
    
    return (Query[]) queries.toArray(new Query[0]);
  
private static org.apache.lucene.search.Query[]getPrebuiltQueries(java.lang.String field)

  
       
    //  be wary of unanalyzed text
    return new Query[] {
        new SpanFirstQuery(new SpanTermQuery(new Term(field, "ford")), 5),
        new SpanNearQuery(new SpanQuery[]{new SpanTermQuery(new Term(field, "night")), new SpanTermQuery(new Term(field, "trading"))}, 4, false),
        new SpanNearQuery(new SpanQuery[]{new SpanFirstQuery(new SpanTermQuery(new Term(field, "ford")), 10), new SpanTermQuery(new Term(field, "credit"))}, 10, false),
        new WildcardQuery(new Term(field, "fo*")),
    };
  
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;
  
private voidprepareQueries()

    // analyzer (default is standard analyzer)
    Analyzer anlzr= (Analyzer) Class.forName(config.get("analyzer",
    "org.apache.lucene.analysis.StandardAnalyzer")).newInstance(); 
    
    List queryList = new ArrayList(20);
    queryList.addAll(Arrays.asList(STANDARD_QUERIES));
    queryList.addAll(Arrays.asList(getPrebuiltQueries("body")));
    queries = createQueries(queryList, anlzr);
  
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;
    prepareQueries();