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

FileBasedQueryMaker

public class FileBasedQueryMaker extends AbstractQueryMaker implements QueryMaker
Create queries from a FileReader. One per line, pass them through the QueryParser. Lines beginning with # are treated as comments File can be specified as a absolute, relative or resource. Two properties can be set: file.query.maker.file=<Full path to file containing queries>
file.query.maker.default.field=<Name of default field - Default value is "body"> Example: file.query.maker.file=c:/myqueries.txt file.query.maker.default.field=body

Fields Summary
Constructors Summary
Methods Summary
protected org.apache.lucene.search.Query[]prepareQueries()


    Analyzer anlzr = (Analyzer) Class.forName(config.get("analyzer",
            "org.apache.lucene.analysis.standard.StandardAnalyzer")).newInstance();
    String defaultField = config.get("file.query.maker.default.field", "body");
    QueryParser qp = new QueryParser(defaultField, anlzr);

    List qq = new ArrayList();
    String fileName = config.get("file.query.maker.file", null);
    if (fileName != null)
    {
      File file = new File(fileName);
      Reader reader = null;
      if (file != null && file.exists())
      {
        reader = new FileReader(file);
      } else {
        //see if we can find it as a resource
        InputStream asStream = FileBasedQueryMaker.class.getClassLoader().getResourceAsStream(fileName);
        if (asStream != null) {
          reader = new InputStreamReader(asStream);
        }
      }
      if (reader != null) {
        BufferedReader buffered = new BufferedReader(reader);
        String line = null;
        int lineNum = 0;
        while ((line = buffered.readLine()) != null)
        {
          line = line.trim();
          if (!line.equals("") && !line.startsWith("#"))
          {
            Query query = null;
            try {
              query = qp.parse(line);
            } catch (ParseException e) {
              System.err.println("Exception: " + e.getMessage() + " occurred while parsing line: " + lineNum + " Text: " + line);
            }
            qq.add(query);
          }
          lineNum++;
        }
      } else {
        System.err.println("No Reader available for: " + fileName);
      }
    }
    Query [] result = (Query[]) qq.toArray(new Query[qq.size()]) ;
    return result;