Hello,
I am using a custom SortComparator implementation where I need to override a
method in order to handle Null values:
@Override
public ScoreDocComparator newComparator (final IndexReader reader,
final
String fieldname)
throws IOException {
final String field = fieldname.intern();
final Comparable[] cachedValues
= FieldCache.DEFAULT.getCustom (reader, field,
CollatorBasedComparator.this);
return new ScoreDocComparator() {
public int compare (ScoreDoc i, ScoreDoc j) {
Comparable ci= cachedValues[i.doc];
Comparable cj= cachedValues[j.doc];
int returnValue =0;
if (ci == null)
returnValue = (cj==null) ? 0 : 1;
else
if (cj == null) returnValue = -1; //
else
returnValue= ci.compareTo(cj);
return returnValue;
}
public Comparable sortValue (ScoreDoc i) {
return cachedValues[i.doc];
}
public int sortType(){
return org.apache.lucene.search.SortField.CUSTOM;
}
};
}
Is there anything wrong about the code? Because I get the exception:
java.lang.NullPointerException
at
org.apache.lucene.search.FieldDocSortedHitQueue.lessThan(FieldDocSortedHitQueue.java:164)
at
org.apache.lucene.util.PriorityQueue.upHeap(PriorityQueue.java:139)
at org.apache.lucene.util.PriorityQueue.put(PriorityQueue.java:53)
at
org.apache.lucene.util.PriorityQueue.insertWithOverflow(PriorityQueue.java:78)
at
org.apache.lucene.util.PriorityQueue.insert(PriorityQueue.java:63)
at
org.apache.lucene.search.MultiSearcher.search(MultiSearcher.java:241)
at org.apache.lucene.search.Hits.getMoreDocs(Hits.java:100)
at org.apache.lucene.search.Hits.hitDoc(Hits.java:206)
at org.apache.lucene.search.Hits.doc(Hits.java:155)
I am using lucene 2.3.1.
Please help me.
Thank you in advance,
Nina
--
View this message in context:
http://www.nabble.com/NullPointerException-in-FieldDocSortedHitQueue.lessThan-with-custom-SortComparator-tp21702845p21702845.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]