Index: CHANGES.txt
===================================================================
--- CHANGES.txt	(revision 520244)
+++ CHANGES.txt	(working copy)
@@ -4,6 +4,12 @@
 
 $Id:$
 
+3/19/07
+
+1. Introduced an AbstractQueryMaker to hold common QueryMaker code. (GSI)
+2. Added traversalSize parameter to SearchTravRetTask and SearchTravTask.  Changed SearchTravRetTask to extend SearchTravTask. (GSI)
+3. Added FileBasedQueryMaker to run queries from a File or resource. (GSI)
+
 01/09/07
 
 1. Committed Doron Cohen's benchmarking contribution, which provides an easily expandable task based approach to benchmarking.  See the javadocs for information. (Doron Cohen via Grant Ingersoll)
Index: src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetTask.java
===================================================================
--- src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetTask.java	(revision 520244)
+++ src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetTask.java	(working copy)
@@ -18,7 +18,6 @@
  */
 
 import org.apache.lucene.benchmark.byTask.PerfRunData;
-import org.apache.lucene.benchmark.byTask.feeds.QueryMaker;
 
 /**
  * Search and Travrese and Retrieve docs task.
@@ -26,7 +25,7 @@
  * <p>Note: This task reuses the reader if it is already open. 
  * Otherwise a reader is opened at start and closed at the end.
  */
-public class SearchTravRetTask extends ReadTask {
+public class SearchTravRetTask extends SearchTravTask {
 
   public SearchTravRetTask(PerfRunData runData) {
     super(runData);
@@ -36,21 +35,4 @@
     return true;
   }
 
-  public boolean withSearch() {
-    return true;
-  }
-
-  public boolean withTraverse() {
-    return true;
-  }
-
-  public boolean withWarm() {
-    return false;
-  }
-
-  public QueryMaker getQueryMaker() {
-    return getRunData().getSearchTravQueryMaker();
-  }
-
-
 }
Index: src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravTask.java
===================================================================
--- src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravTask.java	(revision 520244)
+++ src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravTask.java	(working copy)
@@ -25,8 +25,11 @@
  * 
  * <p>Note: This task reuses the reader if it is already open. 
  * Otherwise a reader is opened at start and closed at the end.
+ * <p/>
+ * traversalSize can be set with a command parameter
  */
 public class SearchTravTask extends ReadTask {
+  protected int traversalSize = Integer.MAX_VALUE;
 
   public SearchTravTask(PerfRunData runData) {
     super(runData);
@@ -48,8 +51,18 @@
     return false;
   }
 
+  
+
   public QueryMaker getQueryMaker() {
     return getRunData().getSearchTravRetQueryMaker();
   }
 
+  public int traversalSize() {
+    return traversalSize;
+  }
+
+  public void setParams(String params) {
+    super.setParams(params);
+    traversalSize = (int)Float.parseFloat(params);
+  }
 }
Index: src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java
===================================================================
--- src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java	(revision 520244)
+++ src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java	(working copy)
@@ -78,7 +78,8 @@
       
       if (withTraverse()) {
         Document doc = null;
-        if (hits != null && hits.length() > 0) {
+        int traversalSize = Math.min(hits.length(), traversalSize());
+        if (hits != null && traversalSize > 0) {
           for (int m = 0; m < hits.length(); m++) {
             int id = hits.id(m);
             res++;
@@ -121,6 +122,18 @@
   public abstract boolean withTraverse ();
 
   /**
+   * Specify the number of hits to traverse.  Tasks should override this if they want to restrict the number
+   * of hits that are traversed when {@link #withTraverse()} is true. Must be greater than 0.
+   *
+   * Read task calculates the traversal as: Math.min(hits.length(), traversalSize())
+   * @return Integer.MAX_VALUE
+   */
+  public int traversalSize()
+  {
+    return Integer.MAX_VALUE;
+  }
+
+  /**
    * Return true if, with search & results traversing, docs should be retrieved.
    */
   public abstract boolean withRetrieve ();
Index: src/java/org/apache/lucene/benchmark/byTask/feeds/ReutersQueryMaker.java
===================================================================
--- src/java/org/apache/lucene/benchmark/byTask/feeds/ReutersQueryMaker.java	(revision 520244)
+++ src/java/org/apache/lucene/benchmark/byTask/feeds/ReutersQueryMaker.java	(working copy)
@@ -17,10 +17,6 @@
  * limitations under the License.
  */
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.queryParser.QueryParser;
@@ -30,20 +26,18 @@
 import org.apache.lucene.search.spans.SpanNearQuery;
 import org.apache.lucene.search.spans.SpanQuery;
 import org.apache.lucene.search.spans.SpanTermQuery;
-import org.apache.lucene.benchmark.byTask.utils.Config;
-import org.apache.lucene.benchmark.byTask.utils.Format;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
+
 /**
  * A QueryMaker that makes queries devised manually (by Grant Ingersoll) for
  * searching in the Reuters collection.
  */
-public class ReutersQueryMaker implements QueryMaker {
-  
-  private int qnum = 0;
-  private Query queries[];
-  private Config config;
-  
+public class ReutersQueryMaker extends AbstractQueryMaker implements QueryMaker {
+
   private static String [] STANDARD_QUERIES = {
     //Start with some short queries
     "Salomon", "Comex", "night trading", "Japan Sony",
@@ -106,7 +100,7 @@
     return (Query[]) queries.toArray(new Query[0]);
   }
   
-  private void prepareQueries() throws Exception {
+  protected Query[] prepareQueries() throws Exception {
     // analyzer (default is standard analyzer)
     Analyzer anlzr= (Analyzer) Class.forName(config.get("analyzer",
     "org.apache.lucene.analysis.standard.StandardAnalyzer")).newInstance(); 
@@ -114,47 +108,10 @@
     List queryList = new ArrayList(20);
     queryList.addAll(Arrays.asList(STANDARD_QUERIES));
     queryList.addAll(Arrays.asList(getPrebuiltQueries("body")));
-    queries = createQueries(queryList, anlzr);
+    return createQueries(queryList, anlzr);
   }
+
+
   
-  public Query makeQuery() throws Exception {
-    return queries[nextQnum()];
-  }
-  
-  public void setConfig(Config config) throws Exception {
-    this.config = config;
-    prepareQueries();
-  }
-  
-  public void resetInputs() {
-    qnum = 0;
-  }
-  
-  // return next qnum
-  private synchronized int nextQnum() {
-    int res = qnum;
-    qnum = (qnum+1) % queries.length;
-    return res;
-  }
-  
-  public String printQueries() {
-    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();
-  }
-  
-  /*
-   *  (non-Javadoc)
-   * @see org.apache.lucene.benchmark.byTask.feeds.QueryMaker#makeQuery(int)
-   */
-  public Query makeQuery(int size) throws Exception {
-    throw new Exception(this+".makeQuery(int size) is not supported!");
-  }
 
 }
Index: src/java/org/apache/lucene/benchmark/byTask/feeds/SimpleQueryMaker.java
===================================================================
--- src/java/org/apache/lucene/benchmark/byTask/feeds/SimpleQueryMaker.java	(revision 520244)
+++ src/java/org/apache/lucene/benchmark/byTask/feeds/SimpleQueryMaker.java	(working copy)
@@ -17,28 +17,23 @@
  * limitations under the License.
  */
 
-import java.util.ArrayList;
-
 import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.benchmark.byTask.utils.Config;
-import org.apache.lucene.benchmark.byTask.utils.Format;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.BooleanClause.Occur;
 
+import java.util.ArrayList;
+
 /**
  * A QueryMaker that makes queries for a collection created 
  * using {@link org.apache.lucene.benchmark.byTask.feeds.SimpleDocMaker}.
  */
-public class SimpleQueryMaker implements QueryMaker {
+public class SimpleQueryMaker extends AbstractQueryMaker implements QueryMaker {
 
-  private int qnum = 0;
-  private Query queries[];
-  private Config config;
-  
+
   /**
    * Prepare the queries for this test.
    * Extending classes can overide this method for preparing different queries. 
@@ -70,44 +65,4 @@
     return (Query []) qq.toArray(new Query[0]);
   }
 
-  public Query makeQuery() throws Exception {
-    return queries[nextQnum()];
-  }
-
-  public void setConfig(Config config) throws Exception {
-    this.config = config;
-    queries = prepareQueries();
-  }
-
-  public void resetInputs() {
-    qnum = 0;
-  }
-
-  // return next qnum
-  private synchronized int nextQnum() {
-    int res = qnum;
-    qnum = (qnum+1) % queries.length;
-    return res;
-  }
-
-  public String printQueries() {
-    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();
-  }
-
-  /*
-   *  (non-Javadoc)
-   * @see org.apache.lucene.benchmark.byTask.feeds.QueryMaker#makeQuery(int)
-   */
-  public Query makeQuery(int size) throws Exception {
-    throw new Exception(this+".makeQuery(int size) is not supported!");
-  }
-
 }
Index: src/java/org/apache/lucene/benchmark/byTask/feeds/FileBasedQueryMaker.java
===================================================================
--- src/java/org/apache/lucene/benchmark/byTask/feeds/FileBasedQueryMaker.java	(revision 0)
+++ src/java/org/apache/lucene/benchmark/byTask/feeds/FileBasedQueryMaker.java	(revision 0)
@@ -0,0 +1,93 @@
+package org.apache.lucene.benchmark.byTask.feeds;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.search.Query;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Copyright 2004 The Apache Software Foundation
+ * <p/>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * 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 anbsolute, relative or resource.
+ * Two properties can be set:
+ * file.query.maker.file=&lt;Full path to file containing queries&gt;
+ * <br/>
+ * file.query.maker.default.field=&lt;Name of default field - Default value is "body"&gt;
+ *
+ * Example:
+ * file.query.maker.file=c:/myqueries.txt
+ * file.query.maker.default.field=body
+ */
+public class FileBasedQueryMaker extends AbstractQueryMaker implements QueryMaker{
+
+
+  protected Query[] prepareQueries() throws Exception {
+
+    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)
+        {
+          if (line.equals("") == false && line.equals("#") == false)
+          {
+            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;
+  }
+}

Property changes on: src/java/org/apache/lucene/benchmark/byTask/feeds/FileBasedQueryMaker.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: src/java/org/apache/lucene/benchmark/byTask/feeds/AbstractQueryMaker.java
===================================================================
--- src/java/org/apache/lucene/benchmark/byTask/feeds/AbstractQueryMaker.java	(revision 0)
+++ src/java/org/apache/lucene/benchmark/byTask/feeds/AbstractQueryMaker.java	(revision 0)
@@ -0,0 +1,71 @@
+package org.apache.lucene.benchmark.byTask.feeds;
+/**
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.search.Query;
+import org.apache.lucene.benchmark.byTask.utils.Config;
+import org.apache.lucene.benchmark.byTask.utils.Format;
+
+/**
+ *
+ *
+ **/
+public abstract class AbstractQueryMaker implements QueryMaker {
+
+  protected int qnum = 0;
+  protected Query[] queries;
+  protected Config config;
+
+  public void resetInputs() {
+    qnum = 0;
+  }
+
+  protected abstract Query[] prepareQueries() throws Exception;
+
+  public void setConfig(Config config) throws Exception {
+    this.config = config;
+    queries = prepareQueries();
+  }
+
+  public String printQueries() {
+    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 Query makeQuery() throws Exception {
+    return queries[nextQnum()];
+  }// return next qnum
+  protected synchronized int nextQnum() {
+    int res = qnum;
+    qnum = (qnum+1) % queries.length;
+    return res;
+  }
+
+  /*
+  *  (non-Javadoc)
+  * @see org.apache.lucene.benchmark.byTask.feeds.QueryMaker#makeQuery(int)
+  */
+  public Query makeQuery(int size) throws Exception {
+    throw new Exception(this+".makeQuery(int size) is not supported!");
+  }
+}

Property changes on: src/java/org/apache/lucene/benchmark/byTask/feeds/AbstractQueryMaker.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: src/java/org/apache/lucene/benchmark/byTask/package.html
===================================================================
--- src/java/org/apache/lucene/benchmark/byTask/package.html	(revision 520244)
+++ src/java/org/apache/lucene/benchmark/byTask/package.html	(working copy)
@@ -183,8 +183,7 @@
  <b>Command parameter</b>: a command can take a single parameter.
  If the certain command does not support a parameter, or if the parameter is of the wrong type,
  reading the algorithm will fail with an exception and the test would not start.
- Currently only AddDoc supports a (numeric) parameter, which indicates the required size of added document.
- If the DocMaker implementation used in the test does not support makeDoc(size), an exception would be thrown and the test would fail.
+  If the DocMaker implementation used in the test does not support makeDoc(size), an exception would be thrown and the test would fail.
  <br>Example - <font color="#FF0066">AddDoc(2000)</font> - would add a document of size 2000 (~bytes).
  <br>See conf/task-sample.alg for how this can be used, for instance, to check which is faster, adding
  many smaller documents, or few larger documents.
