mirror of https://github.com/apache/lucene.git
LUCENE-5978: don't write a norm of infinity when analyzer returns no tokens
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1628463 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
804bd36ad2
commit
04a5e3a408
|
@ -550,7 +550,9 @@ final class DefaultIndexingChain extends DocConsumer {
|
|||
fieldInfo.setNormValueType(FieldInfo.DocValuesType.NUMERIC);
|
||||
norms = new NormValuesWriter(fieldInfo, docState.docWriter.bytesUsed);
|
||||
}
|
||||
norms.addValue(docState.docID, similarity.computeNorm(invertState));
|
||||
if (invertState.length != 0) {
|
||||
norms.addValue(docState.docID, similarity.computeNorm(invertState));
|
||||
}
|
||||
}
|
||||
|
||||
termsHashPerField.finish();
|
||||
|
|
|
@ -33,6 +33,7 @@ import java.util.Set;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.analysis.CannedTokenStream;
|
||||
import org.apache.lucene.analysis.MockAnalyzer;
|
||||
import org.apache.lucene.analysis.MockTokenFilter;
|
||||
import org.apache.lucene.analysis.MockTokenizer;
|
||||
|
@ -2798,5 +2799,19 @@ public class TestIndexWriter extends LuceneTestCase {
|
|||
ids.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
public void testEmptyNorm() throws Exception {
|
||||
Directory d = newDirectory();
|
||||
IndexWriter w = new IndexWriter(d, newIndexWriterConfig(new MockAnalyzer(random())));
|
||||
Document doc = new Document();
|
||||
doc.add(new TextField("foo", new CannedTokenStream()));
|
||||
w.addDocument(doc);
|
||||
w.commit();
|
||||
w.close();
|
||||
DirectoryReader r = DirectoryReader.open(d);
|
||||
assertEquals(0, getOnlySegmentReader(r).getNormValues("foo").get(0));
|
||||
r.close();
|
||||
d.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue