package org.getopt.luke;

import org.apache.lucene.search.TopDocCollector;
import org.apache.lucene.search.TopDocs;

public class AccessibleTopHitCollector extends AccessibleHitCollector {
  private TopDocCollector tdc;
  private TopDocs topDocs = null;
  
  public AccessibleTopHitCollector(int size) {
    tdc = new TopDocCollector(size);
  }

  @Override
  public int getDocId(int pos) {
    if (topDocs == null) {
      topDocs = tdc.topDocs();
    }
    return topDocs.scoreDocs[pos].doc;
  }

  @Override
  public float getScore(int pos) {
    if (topDocs == null) {
      topDocs = tdc.topDocs();
    }
    return topDocs.scoreDocs[pos].score;
  }

  @Override
  public int getTotalHits() {
    return tdc.getTotalHits();
  }

  @Override
  public void collect(int doc, float score) {
    tdc.collect(doc, score);
  }

}
