Index: CHANGES.txt =================================================================== --- CHANGES.txt (revision 727043) +++ CHANGES.txt (working copy) @@ -3,6 +3,9 @@ The Benchmark contrib package contains code for benchmarking Lucene in a variety of ways. $Id:$ +12/16/08 + LUCENE-1493: Stop using deprecated Hits API for searching; add new + param search.num.hits to set top N docs to collect. 12/16/08 LUCENE-1492: Added optional readOnly param (default true) to OpenReader task. Index: src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java =================================================================== --- src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java (revision 727043) +++ src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java (working copy) @@ -31,7 +31,8 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Fieldable; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.search.Hits; +import org.apache.lucene.search.TopDocs; +import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.Sort; @@ -50,7 +51,9 @@ *
*Note: All ReadTasks reuse the reader if it is already open. * Otherwise a reader is opened at start and closed at the end. - *
+ *
+ * The search.num.hits config parameter sets
+ * the top number of hits to collect during searching.
*
Other side effects: none.
*/
public abstract class ReadTask extends PerfTask {
@@ -89,40 +92,44 @@
QueryMaker queryMaker = getQueryMaker();
Query q = queryMaker.makeQuery();
Sort sort = getSort();
- Hits hits;
- if(sort != null) {
- hits = searcher.search(q, sort);
- } else {
- hits = searcher.search(q);
- }
- //System.out.println("searched: "+q);
+ TopDocs hits;
+ final int numHits = numHits();
+ if (numHits > 0) {
+ if (sort != null) {
+ hits = searcher.search(q, null, numHits, sort);
+ } else {
+ hits = searcher.search(q, numHits);
+ }
- if (withTraverse() && hits != null) {
- int traversalSize = Math.min(hits.length(), traversalSize());
- if (traversalSize > 0) {
- boolean retrieve = withRetrieve();
- int numHighlight = Math.min(numToHighlight(), hits.length());
- Analyzer analyzer = getRunData().getAnalyzer();
- Highlighter highlighter = null;
- int maxFrags = 1;
- if (numHighlight > 0) {
- highlighter = getHighlighter(q);
- maxFrags = maxNumFragments();
- }
- boolean merge = isMergeContiguousFragments();
- for (int m = 0; m < traversalSize; m++) {
- int id = hits.id(m);
- res++;
- if (retrieve) {
- Document document = retrieveDoc(ir, id);
- res += document != null ? 1 : 0;
- if (numHighlight > 0 && m < numHighlight) {
- Collection/*