1 5 package org.exoplatform.services.indexing; 6 7 import java.util.ArrayList ; 8 import java.util.List ; 9 import org.apache.lucene.search.Hits; 10 import org.apache.lucene.document.Document; 11 import org.exoplatform.commons.utils.PageList; 12 17 public class HitPageList extends PageList { 18 19 private Hits hits_ ; 20 private Searcher searcher_ ; 21 private float[] scores_ ; 22 23 public HitPageList(Searcher searcher, int pageSize) throws Exception { 24 super(pageSize) ; 25 scores_ = new float[pageSize] ; 26 searcher_ = searcher ; 27 hits_ = searcher.getLastSearchResult() ; 28 setAvailablePage(hits_.length()) ; 29 } 30 31 public HitPageList(Searcher searcher) throws Exception { 32 this(searcher, 15) ; 33 } 34 35 public void setPageSize(int pageSize) { 36 scores_ = new float[pageSize] ; 37 super.setPageSize(pageSize) ; 38 } 39 40 protected void populateCurrentPage(int page) throws Exception { 41 int from = getFrom() ; 42 int to = getTo() ; 43 currentListPage_ = new ArrayList (to - from) ; 44 for(int i = from ; i < to ; i++ ) { 45 currentListPage_.add(hits_.doc(i)) ; 46 scores_[i - from] = hits_.score(i) ; 47 } 48 } 49 50 public List getAll() throws Exception { 51 int available = getAvailable() ; 52 List list = new ArrayList (available) ; 53 for(int i = 0; i < available ; i++ ) { 54 list.add(hits_.doc(i)) ; 55 } 56 return list ; 57 } 58 59 public Document getDocumentInPage(int idx) { 60 return (Document)currentListPage_.get(idx) ; 61 } 62 63 public float getScoreOfDocumentInPage(int idx) { return scores_[idx] ; } 64 65 public Document getDocument(int idx) throws Exception { 66 return hits_.doc(idx) ; 67 } 68 69 public Searcher getSearcher() { return searcher_ ; } 70 } | Popular Tags |