Mailing List Archive

cvs commit: jakarta-lucene-sandbox/contributions/searchbean/src/java/org/apache/lucene/beans HitsIterator.java
carlson 2002/09/06 18:00:47

Modified: contributions/searchbean/src/java/org/apache/lucene/beans
HitsIterator.java
Log:
Now if there are no hits, I return a HitsIterator that will return 0 for all appropriate fields instead of returning null I put the string "relevance" into a static variable.

Revision Changes Path
1.2 +21 -13 jakarta-lucene-sandbox/contributions/searchbean/src/java/org/apache/lucene/beans/HitsIterator.java

Index: HitsIterator.java
===================================================================
RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/searchbean/src/java/org/apache/lucene/beans/HitsIterator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HitsIterator.java 23 May 2002 00:44:57 -0000 1.1
+++ HitsIterator.java 7 Sep 2002 01:00:47 -0000 1.2
@@ -42,7 +42,7 @@
private int totalPages = -1; // set by constructor

private int endPagePosition = 0; // position currentPage ends
-
+
/** Creates new HitsIterator */
private HitsIterator() {
}
@@ -54,7 +54,7 @@
public HitsIterator(Hits hits, String sortFlag) throws IOException{
this.hitsCollection = hits;
if (sortFlag != null){
- if ((sortFlag != "") && (sortFlag !="relevance")){
+ if ((sortFlag != "") && (sortFlag.equals(SearchBean.SORT_FIELD_RELEVANCE))){
//logger.debug("Sorting hits by field "+sortFlag);
sortByField(sortFlag);
//logger.debug("Completed sorting by field "+sortFlag);
@@ -80,7 +80,9 @@
if (sf !=null){
c = (Comparator) new CompareDocumentsByField();
} else {
- //logger.error("Sort field not found");
+ //logger.error("Sort field not found");
+ // use default sort of Lucene -- Relevance
+ // Should I throw an exception here?
arrayOfIndividualHits = null;
return;
}
@@ -100,14 +102,17 @@


private void setPageCount() {
-
- totalPages = totalHits / pageSize;
-
- //account for remainder if not exaxtly divisable
- if (totalHits % pageSize != 0)
- { totalPages++;}
-
- setCurrentPage(1); // reset currentPage to make sure not over the limit
+ if (totalHits == 0){
+ totalPages = 0;
+ setCurrentPage(0);
+ } else {
+ totalPages = totalHits / pageSize;
+
+ //account for remainder if not exaxtly divisable
+ if (totalHits % pageSize != 0)
+ { totalPages++;}
+ setCurrentPage(1); // reset currentPage to make sure not over the limit
+ }
}

public int getPageCount() {
@@ -151,6 +156,7 @@
}

public org.apache.lucene.document.Document getDoc() throws IOException {
+ // Determine if using relevnace or sorting by another field
if (arrayOfIndividualHits == null)
return hitsCollection.doc(currentPosition - 1);
else {
@@ -160,6 +166,7 @@
}

public int getScore() throws Exception{
+ // Determine if using relevnace or sorting by another field
if (arrayOfIndividualHits == null)
return (int) (hitsCollection.score(currentPosition - 1)*100.0f);
else
@@ -184,8 +191,9 @@
}

public void setCurrentPage(int currentPage) throws IndexOutOfBoundsException{
- if (currentPage > totalPages){
- throw new IndexOutOfBoundsException("currentPage greater than total pages");
+ if (currentPage > totalPages){
+ currentPage = totalPages; // don't allow to go over max
+ //throw new IndexOutOfBoundsException("currentPage greater than total pages");
}

this.currentPage = currentPage;




--
To unsubscribe, e-mail: <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>