diff --git a/CHANGES.txt b/CHANGES.txt index 5062d6a0495..996868f427d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -73,6 +73,10 @@ Bug fixes without checking if the scorer is already at the right position. scorer.skipTo(scorer.doc()) is not a NOOP, it behaves as scorer.next(). (Eks Dev, Michael Busch) + + 5. LUCENE-1179: Fixed assert statement that was incorrectly + preventing Fields with empty-string field name from working. + (Sergey Kabashnyuk via Mike McCandless) New features diff --git a/src/java/org/apache/lucene/index/TermInfosWriter.java b/src/java/org/apache/lucene/index/TermInfosWriter.java index 90ed929146f..a54f50b1f40 100644 --- a/src/java/org/apache/lucene/index/TermInfosWriter.java +++ b/src/java/org/apache/lucene/index/TermInfosWriter.java @@ -111,8 +111,15 @@ final class TermInfosWriter { private int compareToLastTerm(int fieldNumber, char[] termText, int start, int length) { int pos = 0; - if (lastFieldNumber != fieldNumber) - return fieldInfos.fieldName(lastFieldNumber).compareTo(fieldInfos.fieldName(fieldNumber)); + if (lastFieldNumber != fieldNumber) { + final int cmp = fieldInfos.fieldName(lastFieldNumber).compareTo(fieldInfos.fieldName(fieldNumber)); + // If there is a field named "" (empty string) then we + // will get 0 on this comparison, yet, it's "OK". But + // it's not OK if two different field numbers map to + // the same name. + if (cmp != 0 || lastFieldNumber != -1) + return cmp; + } while(pos < length && pos < lastTermTextLength) { final char c1 = lastTermText[pos]; diff --git a/src/test/org/apache/lucene/index/TestIndexWriter.java b/src/test/org/apache/lucene/index/TestIndexWriter.java index 2174c72b06f..9c8b3d80221 100644 --- a/src/test/org/apache/lucene/index/TestIndexWriter.java +++ b/src/test/org/apache/lucene/index/TestIndexWriter.java @@ -3113,4 +3113,14 @@ public class TestIndexWriter extends LuceneTestCase ir.close(); dir.close(); } + + // LUCENE-1179 + public void testEmptyFieldName() throws IOException { + MockRAMDirectory dir = new MockRAMDirectory(); + IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer()); + Document doc = new Document(); + doc.add(new Field("", "a b c", Field.Store.NO, Field.Index.TOKENIZED)); + writer.addDocument(doc); + writer.close(); + } }