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
This commit is contained in:
Michael McCandless 2008-02-15 15:04:16 +00:00
parent 9f2e3cf7bc
commit cc64e6fdde
3 changed files with 23 additions and 2 deletions

View File

@ -74,6 +74,10 @@ Bug fixes
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
1. LUCENE-1137: Added Token.set/getFlags() accessors for passing more information about a Token through the analysis

View File

@ -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];

View File

@ -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();
}
}