From 9763d03f48005cf476de27c991da769fe8735273 Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Sun, 20 Aug 2006 21:17:59 +0000 Subject: [PATCH] LUCENE-650: Fixed NPE in Locale specific String Sort when Document has no value git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@433049 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 4 ++++ .../lucene/search/FieldSortedHitQueue.java | 16 +++++++++++++--- src/test/org/apache/lucene/search/TestSort.java | 6 ++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 35be977c4d5..70044e31662 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -110,6 +110,10 @@ Bug fixes 13. LUCENE-659: Make PerFieldAnalyzerWrapper delegate getPositionIncrementGap() to the correct analyzer for the field. (Chuck Williams via Yonik Seeley) +14. LUCENE-650: Fixed NPE in Locale specific String Sort when Document + has no value. + (Oliver Hutchison via Chris Hostetter) + Optimizations 1. LUCENE-586: TermDocs.skipTo() is now more efficient for multi-segment diff --git a/src/java/org/apache/lucene/search/FieldSortedHitQueue.java b/src/java/org/apache/lucene/search/FieldSortedHitQueue.java index 67c4aafab0d..3e3d9e1d622 100644 --- a/src/java/org/apache/lucene/search/FieldSortedHitQueue.java +++ b/src/java/org/apache/lucene/search/FieldSortedHitQueue.java @@ -316,9 +316,19 @@ extends PriorityQueue { final String[] index = FieldCache.DEFAULT.getStrings (reader, field); return new ScoreDocComparator() { - public final int compare (final ScoreDoc i, final ScoreDoc j) { - return collator.compare (index[i.doc], index[j.doc]); - } + public final int compare(final ScoreDoc i, final ScoreDoc j) { + String is = index[i.doc]; + String js = index[j.doc]; + if (is == js) { + return 0; + } else if (is == null) { + return -1; + } else if (js == null) { + return 1; + } else { + return collator.compare(is, js); + } + } public Comparable sortValue (final ScoreDoc i) { return index[i.doc]; diff --git a/src/test/org/apache/lucene/search/TestSort.java b/src/test/org/apache/lucene/search/TestSort.java index 46135efe017..9e31d8d4fc4 100644 --- a/src/test/org/apache/lucene/search/TestSort.java +++ b/src/test/org/apache/lucene/search/TestSort.java @@ -261,6 +261,12 @@ implements Serializable { sort.setSort ("string", true); assertMatches (full, queryF, sort, "IJZ"); + + sort.setSort (new SortField ("i18n", Locale.ENGLISH)); + assertMatches (full, queryF, sort, "ZJI"); + + sort.setSort (new SortField ("i18n", Locale.ENGLISH, true)); + assertMatches (full, queryF, sort, "IJZ"); sort.setSort ("int"); assertMatches (full, queryF, sort, "IZJ");