From 45e5118e57397b9cca693745ae76c9b9e3409d04 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Thu, 13 Sep 2012 15:46:26 +0000 Subject: [PATCH] add test mixing up pos/no pos git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1384379 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/index/TestOmitPositions.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lucene/core/src/test/org/apache/lucene/index/TestOmitPositions.java b/lucene/core/src/test/org/apache/lucene/index/TestOmitPositions.java index 7050b17ee43..3c47770c04b 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestOmitPositions.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestOmitPositions.java @@ -225,4 +225,41 @@ public class TestOmitPositions extends LuceneTestCase { assertNoPrx(ram); ram.close(); } + + /** make sure we downgrade positions and payloads correctly */ + public void testMixing() throws Exception { + // no positions + FieldType ft = new FieldType(TextField.TYPE_NOT_STORED); + ft.setIndexOptions(IndexOptions.DOCS_AND_FREQS); + + Directory dir = newDirectory(); + RandomIndexWriter iw = new RandomIndexWriter(random(), dir); + + for (int i = 0; i < 20; i++) { + Document doc = new Document(); + if (i < 19 && random().nextBoolean()) { + for (int j = 0; j < 50; j++) { + doc.add(new TextField("foo", "i have positions", Field.Store.NO)); + } + } else { + for (int j = 0; j < 50; j++) { + doc.add(new Field("foo", "i have no positions", ft)); + } + } + iw.addDocument(doc); + iw.commit(); + } + + if (random().nextBoolean()) { + iw.forceMerge(1); + } + + DirectoryReader ir = iw.getReader(); + FieldInfos fis = MultiFields.getMergedFieldInfos(ir); + assertEquals(IndexOptions.DOCS_AND_FREQS, fis.fieldInfo("foo").getIndexOptions()); + assertFalse(fis.fieldInfo("foo").hasPayloads()); + iw.close(); + ir.close(); + dir.close(); // checkindex + } }