From cc64e6fdde9990d781e45df796374d21537937c8 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Fri, 15 Feb 2008 15:04:16 +0000 Subject: [PATCH] LUCENE-1179: allow Fields with empty string field names git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@628080 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 4 ++++ src/java/org/apache/lucene/index/TermInfosWriter.java | 11 +++++++++-- src/test/org/apache/lucene/index/TestIndexWriter.java | 10 ++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) 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(); + } }