KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > indexing > HitPageList


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.indexing;
6
7 import java.util.ArrayList JavaDoc;
8 import java.util.List JavaDoc;
9 import org.apache.lucene.search.Hits;
10 import org.apache.lucene.document.Document;
11 import org.exoplatform.commons.utils.PageList;
12 /**
13  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
14  * @since Oct 21, 2004
15  * @version $Id: HitPageList.java,v 1.4 2004/11/01 21:06:50 tuan08 Exp $
16  */

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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
41     int from = getFrom() ;
42     int to = getTo() ;
43     currentListPage_ = new ArrayList JavaDoc(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 JavaDoc getAll() throws Exception JavaDoc {
51     int available = getAvailable() ;
52     List JavaDoc list = new ArrayList JavaDoc(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 JavaDoc {
66     return hits_.doc(idx) ;
67   }
68   
69   public Searcher getSearcher() { return searcher_ ; }
70 }
Popular Tags