FileDocCategorySizeDatePackage
ReutersQueryMaker.javaAPI DocApache Lucene 2.2.04150Sat Jun 16 22:20:58 BST 2007org.apache.lucene.benchmark.byTask.feeds

ReutersQueryMaker

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

Fields Summary
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*")),
    };
  
protected org.apache.lucene.search.Query[]prepareQueries()

    // analyzer (default is standard analyzer)
    Analyzer anlzr= (Analyzer) Class.forName(config.get("analyzer",
    "org.apache.lucene.analysis.standard.StandardAnalyzer")).newInstance(); 
    
    List queryList = new ArrayList(20);
    queryList.addAll(Arrays.asList(STANDARD_QUERIES));
    queryList.addAll(Arrays.asList(getPrebuiltQueries("body")));
    return createQueries(queryList, anlzr);