Re: sorting on a field that can have null values

2004-12-29 Thread Praveen Peddi
Hi,
Sorry for the late response. I didn't cheak the reply till now.

I think sorting on a field that doesn't exist for every doc is throwing 
NullPointerException for me (if its of type string). FYI: I am using my own 
comparator for string (see below for the code). I am sure something is wrong in 
my comparator but having hard time figure out whats wrong. I get 
NullPointerException all the time if some of the fields are null. When I use 
default lucene's comparator for string, its fine. May be someone can put their 
eyes on the code below and figure out that problem is very obvious. I found 
that some of the comparables are null so NullPointerEception is occuring in 
SortComparator.java at line 36.

Thanks
Prvaeen

public class StringIgnoreCaseSortComparator extends SortComparator {
 private static StringIgnoreCaseSortComparator stringIgnoreCaseSortComparator;
 
 private StringIgnoreCaseSortComparator() {
  super();
 }
 
  protected Comparable getComparable(String termtext) {  
  return new StringIgnoreCaseComparable(termtext);
 }
 
 public static synchronized StringIgnoreCaseSortComparator getInstance() {
  if(stringIgnoreCaseSortComparator ==null) {
   stringIgnoreCaseSortComparator = new StringIgnoreCaseSortComparator();
  }
  
  return stringIgnoreCaseSortComparator;
 }
 
 class StringIgnoreCaseComparable implements Comparable {
  private String stringToCompare;
  
  public StringIgnoreCaseComparable(String stringToCompare) {
   this.stringToCompare = stringToCompare;
  }

  public int compareTo(Object o) {   
   int result = 0;
   if(stringToCompare==null) {//put it at the bottom (compatible with db 
sorting)
result = 1;
   } else if(o==null || ((StringIgnoreCaseComparable)o).getStringToCompare() == 
null) {
result = -1;
   } else {

stringToCompare.compareToIgnoreCase(((StringIgnoreCaseComparable)o).getStringToCompare());
   }
   return result;
  } 
  
 public boolean equals(Object obj) {
   if(stringToCompare==null || obj==null) {
return false;//if either of the objects are null, return false
   }
   return 
stringToCompare.equalsIgnoreCase(((StringIgnoreCaseComparable)obj).getStringToCompare());
  }
  
  public String getStringToCompare() {
   return stringToCompare;
  }
 }

}

- Original Message - 
From: "Chris Hostetter" <[EMAIL PROTECTED]>
To: "Lucene Users List" 
Sent: Thursday, December 23, 2004 4:43 AM
Subject: Re: sorting on a field that can have null values


> 
> : I thought of putting empty strings instead of null values but I think
> : empty strings are put first in the list while sorting which is the
> : reverse of what anyone would want.
> 
> instead of adding a field with a null value, or value of an epty string,
> why not just leave the field out for that/those doc(s)?
> 
> there's no requirement that every doc in your index has to have the exact
> same set of fields.
> 
> If i rememebr correctly (you'll have to test this) sorting on a field
> which doesn't exist for every doc does what you would want (docs with
> values are listed before docs without)
> 
> 
> 
> -Hoss
> 
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

Re: sorting on a field that can have null values

2004-12-23 Thread Chris Hostetter

: I thought of putting empty strings instead of null values but I think
: empty strings are put first in the list while sorting which is the
: reverse of what anyone would want.

instead of adding a field with a null value, or value of an epty string,
why not just leave the field out for that/those doc(s)?

there's no requirement that every doc in your index has to have the exact
same set of fields.

If i rememebr correctly (you'll have to test this) sorting on a field
which doesn't exist for every doc does what you would want (docs with
values are listed before docs without)



-Hoss


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



sorting on a field that can have null values (resend)

2004-12-21 Thread Praveen Peddi
I sent this mail yesterday but had no luck in receiving responses. Trying it 
again .

Hi all,
I am getting null pointer exception when I am sorting on a field that has null 
value for some documents. "Order by" in sql does work on such fields and I 
think it puts all results with null values at the end of the list. Shouldn't 
lucene also do the same thing instead of throwing null pointer exception. Is 
this an expected behaviour? Is lucene always expecting some value on the 
sortable fields?

I thought of putting empty strings instead of null values but I think empty 
strings are put first in the list while sorting which is the reverse of what 
anyone would want. 

Following is the exception I saw in the error log:

java.lang.NullPointerException
 at 
org.apache.lucene.search.SortComparator$1.compare(Lorg.apache.lucene.search.ScoreDoc;Lorg.apache.lucene.search.ScoreDoc;)I(SortComparator.java:36)
 at 
org.apache.lucene.search.FieldSortedHitQueue.lessThan(Ljava.lang.Object;Ljava.lang.Object;)Z(FieldSortedHitQueue.java:95)
 at org.apache.lucene.util.PriorityQueue.upHeap()V(PriorityQueue.java:120)
 at 
org.apache.lucene.util.PriorityQueue.put(Ljava.lang.Object;)V(PriorityQueue.java:47)
 at 
org.apache.lucene.util.PriorityQueue.insert(Ljava.lang.Object;)Z(PriorityQueue.java:58)
 at 
org.apache.lucene.search.IndexSearcher$2.collect(IF)V(IndexSearcher.java:130)
 at 
org.apache.lucene.search.Scorer.score(Lorg.apache.lucene.search.HitCollector;)V(Scorer.java:38)
 at 
org.apache.lucene.search.IndexSearcher.search(Lorg.apache.lucene.search.Query;Lorg.apache.lucene.search.Filter;ILorg.apache.lucene.search.Sort;)Lorg.apache.lucene.search.TopFieldDocs;(IndexSearcher.java:125)
 at org.apache.lucene.search.Hits.getMoreDocs(I)V(Hits.java:64)
 at 
org.apache.lucene.search.Hits.(Lorg.apache.lucene.search.Searcher;Lorg.apache.lucene.search.Query;Lorg.apache.lucene.search.Filter;Lorg.apache.lucene.search.Sort;)V(Hits.java:51)
 at 
org.apache.lucene.search.Searcher.search(Lorg.apache.lucene.search.Query;Lorg.apache.lucene.search.Sort;)Lorg.apache.lucene.search.Hits;(Searcher.java:41)

If its a bug in lucene, Will it be fixed in next release? Any suggestions would 
be appreciated.

Praveen

** 
Praveen Peddi
Sr Software Engg, Context Media, Inc. 
email:[EMAIL PROTECTED] 
Tel:  401.854.3475 
Fax:  401.861.3596 
web: http://www.contextmedia.com 
** 
Context Media- "The Leader in Enterprise Content Integration" 


sorting on a field that can have null values

2004-12-20 Thread Praveen Peddi
Hi all,
I am getting null pointer exception when I am sorting on a field that has null 
value for some documents. "Order by" in sql does work on such fields and I 
think it puts all results with null values at the end of the list. Shouldn't 
lucene also do the same thing instead of throwing null pointer exception. Is 
this an expected behaviour? Is lucene always expecting some value on the 
sortable fields?

I thought of putting empty strings instead of null values but I think empty 
strings are put first in the list while sorting which is the reverse of what 
anyone would want. 

Following is the exception I saw in the error log:

java.lang.NullPointerException
 at 
org.apache.lucene.search.SortComparator$1.compare(Lorg.apache.lucene.search.ScoreDoc;Lorg.apache.lucene.search.ScoreDoc;)I(SortComparator.java:36)
 at 
org.apache.lucene.search.FieldSortedHitQueue.lessThan(Ljava.lang.Object;Ljava.lang.Object;)Z(FieldSortedHitQueue.java:95)
 at org.apache.lucene.util.PriorityQueue.upHeap()V(PriorityQueue.java:120)
 at 
org.apache.lucene.util.PriorityQueue.put(Ljava.lang.Object;)V(PriorityQueue.java:47)
 at 
org.apache.lucene.util.PriorityQueue.insert(Ljava.lang.Object;)Z(PriorityQueue.java:58)
 at 
org.apache.lucene.search.IndexSearcher$2.collect(IF)V(IndexSearcher.java:130)
 at 
org.apache.lucene.search.Scorer.score(Lorg.apache.lucene.search.HitCollector;)V(Scorer.java:38)
 at 
org.apache.lucene.search.IndexSearcher.search(Lorg.apache.lucene.search.Query;Lorg.apache.lucene.search.Filter;ILorg.apache.lucene.search.Sort;)Lorg.apache.lucene.search.TopFieldDocs;(IndexSearcher.java:125)
 at org.apache.lucene.search.Hits.getMoreDocs(I)V(Hits.java:64)
 at 
org.apache.lucene.search.Hits.(Lorg.apache.lucene.search.Searcher;Lorg.apache.lucene.search.Query;Lorg.apache.lucene.search.Filter;Lorg.apache.lucene.search.Sort;)V(Hits.java:51)
 at 
org.apache.lucene.search.Searcher.search(Lorg.apache.lucene.search.Query;Lorg.apache.lucene.search.Sort;)Lorg.apache.lucene.search.Hits;(Searcher.java:41)

If its a bug in lucene, Will it be fixed in next release? Any suggestions would 
be appreciated.

Praveen

** 
Praveen Peddi
Sr Software Engg, Context Media, Inc. 
email:[EMAIL PROTECTED] 
Tel:  401.854.3475 
Fax:  401.861.3596 
web: http://www.contextmedia.com 
** 
Context Media- "The Leader in Enterprise Content Integration" 


sorting on a field that can have null values

2004-12-20 Thread Praveen Peddi
Hi all,
I am getting null pointer exception when I am sorting on a field that has null 
value for some documents. "Order by" in sql does work on such fields and I 
think it puts all results with null values at the end of the list. Shouldn't 
lucene also do the same thing instead of throwing null pointer exception. Is 
this an expected behaviour? Is lucene always expecting some value on the 
sortable fields?

I thought of putting empty strings instead of null values but I think empty 
strings are put first in the list while sorting which is the reverse of what 
anyone would want. 

Following is the exception I saw in the error log:

java.lang.NullPointerException
 at 
org.apache.lucene.search.SortComparator$1.compare(Lorg.apache.lucene.search.ScoreDoc;Lorg.apache.lucene.search.ScoreDoc;)I(SortComparator.java:36)
 at 
org.apache.lucene.search.FieldSortedHitQueue.lessThan(Ljava.lang.Object;Ljava.lang.Object;)Z(FieldSortedHitQueue.java:95)
 at org.apache.lucene.util.PriorityQueue.upHeap()V(PriorityQueue.java:120)
 at 
org.apache.lucene.util.PriorityQueue.put(Ljava.lang.Object;)V(PriorityQueue.java:47)
 at 
org.apache.lucene.util.PriorityQueue.insert(Ljava.lang.Object;)Z(PriorityQueue.java:58)
 at 
org.apache.lucene.search.IndexSearcher$2.collect(IF)V(IndexSearcher.java:130)
 at 
org.apache.lucene.search.Scorer.score(Lorg.apache.lucene.search.HitCollector;)V(Scorer.java:38)
 at 
org.apache.lucene.search.IndexSearcher.search(Lorg.apache.lucene.search.Query;Lorg.apache.lucene.search.Filter;ILorg.apache.lucene.search.Sort;)Lorg.apache.lucene.search.TopFieldDocs;(IndexSearcher.java:125)
 at org.apache.lucene.search.Hits.getMoreDocs(I)V(Hits.java:64)
 at 
org.apache.lucene.search.Hits.(Lorg.apache.lucene.search.Searcher;Lorg.apache.lucene.search.Query;Lorg.apache.lucene.search.Filter;Lorg.apache.lucene.search.Sort;)V(Hits.java:51)
 at 
org.apache.lucene.search.Searcher.search(Lorg.apache.lucene.search.Query;Lorg.apache.lucene.search.Sort;)Lorg.apache.lucene.search.Hits;(Searcher.java:41)

If its a bug in lucene, Will it be fixed in next release? Any suggestions would 
be appreciated.

Praveen

** 
Praveen Peddi
Sr Software Engg, Context Media, Inc. 
email:[EMAIL PROTECTED] 
Tel:  401.854.3475 
Fax:  401.861.3596 
web: http://www.contextmedia.com 
** 
Context Media- "The Leader in Enterprise Content Integration"