1 package org.apache.lucene.search; 2 3 18 19 import java.io.IOException ; 20 import java.util.BitSet ; 21 22 import org.apache.lucene.store.Directory; 23 import org.apache.lucene.document.Document; 24 import org.apache.lucene.index.IndexReader; 25 import org.apache.lucene.index.Term; 26 27 35 public class TopFieldDocCollector extends TopDocCollector { 36 37 42 public TopFieldDocCollector(IndexReader reader, Sort sort, int numHits) 43 throws IOException { 44 super(numHits, new FieldSortedHitQueue(reader, sort.fields, numHits)); 45 } 46 47 public void collect(int doc, float score) { 49 if (score > 0.0f) { 50 totalHits++; 51 hq.insert(new FieldDoc(doc, score)); 52 } 53 } 54 55 public TopDocs topDocs() { 57 FieldSortedHitQueue fshq = (FieldSortedHitQueue)hq; 58 ScoreDoc[] scoreDocs = new ScoreDoc[fshq.size()]; 59 for (int i = fshq.size()-1; i >= 0; i--) scoreDocs[i] = fshq.fillFields ((FieldDoc) fshq.pop()); 61 62 return new TopFieldDocs(totalHits, scoreDocs, 63 fshq.getFields(), fshq.getMaxScore()); 64 } 65 } 66 | Popular Tags |