mirror of https://github.com/apache/lucene.git
rewrite broken test
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1591274 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2ce57608ee
commit
ce69d26f8d
|
@ -577,4 +577,87 @@ public class TestTermVectorsWriter extends LuceneTestCase {
|
|||
iw.shutdown();
|
||||
dir.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* In a single doc, for the same field, mix the term vectors up
|
||||
*/
|
||||
public void testInconsistentTermVectorOptions() throws IOException {
|
||||
FieldType a, b;
|
||||
|
||||
// no vectors + vectors
|
||||
a = new FieldType(TextField.TYPE_NOT_STORED);
|
||||
b = new FieldType(TextField.TYPE_NOT_STORED);
|
||||
b.setStoreTermVectors(true);
|
||||
doTestMixup(a, b);
|
||||
|
||||
// vectors + vectors with pos
|
||||
a = new FieldType(TextField.TYPE_NOT_STORED);
|
||||
a.setStoreTermVectors(true);
|
||||
b = new FieldType(TextField.TYPE_NOT_STORED);
|
||||
b.setStoreTermVectors(true);
|
||||
b.setStoreTermVectorPositions(true);
|
||||
doTestMixup(a, b);
|
||||
|
||||
// vectors + vectors with off
|
||||
a = new FieldType(TextField.TYPE_NOT_STORED);
|
||||
a.setStoreTermVectors(true);
|
||||
b = new FieldType(TextField.TYPE_NOT_STORED);
|
||||
b.setStoreTermVectors(true);
|
||||
b.setStoreTermVectorOffsets(true);
|
||||
doTestMixup(a, b);
|
||||
|
||||
// vectors with pos + vectors with pos + off
|
||||
a = new FieldType(TextField.TYPE_NOT_STORED);
|
||||
a.setStoreTermVectors(true);
|
||||
a.setStoreTermVectorPositions(true);
|
||||
b = new FieldType(TextField.TYPE_NOT_STORED);
|
||||
b.setStoreTermVectors(true);
|
||||
b.setStoreTermVectorPositions(true);
|
||||
b.setStoreTermVectorOffsets(true);
|
||||
doTestMixup(a, b);
|
||||
|
||||
// vectors with pos + vectors with pos + pay
|
||||
a = new FieldType(TextField.TYPE_NOT_STORED);
|
||||
a.setStoreTermVectors(true);
|
||||
a.setStoreTermVectorPositions(true);
|
||||
b = new FieldType(TextField.TYPE_NOT_STORED);
|
||||
b.setStoreTermVectors(true);
|
||||
b.setStoreTermVectorPositions(true);
|
||||
b.setStoreTermVectorPayloads(true);
|
||||
doTestMixup(a, b);
|
||||
}
|
||||
|
||||
private void doTestMixup(FieldType ft1, FieldType ft2) throws IOException {
|
||||
Directory dir = newDirectory();
|
||||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
|
||||
|
||||
// add 3 good docs
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Document doc = new Document();
|
||||
doc.add(new StringField("id", Integer.toString(i), Field.Store.NO));
|
||||
iw.addDocument(doc);
|
||||
}
|
||||
|
||||
// add broken doc
|
||||
Document doc = new Document();
|
||||
doc.add(new Field("field", "value1", ft1));
|
||||
doc.add(new Field("field", "value2", ft2));
|
||||
|
||||
// ensure broken doc hits exception
|
||||
try {
|
||||
iw.addDocument(doc);
|
||||
fail("didn't hit expected exception");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
assertNotNull(iae.getMessage());
|
||||
assertTrue(iae.getMessage().startsWith("all instances of a given field name must have the same term vectors settings"));
|
||||
}
|
||||
|
||||
// ensure good docs are still ok
|
||||
IndexReader ir = iw.getReader();
|
||||
assertEquals(3, ir.numDocs());
|
||||
|
||||
ir.close();
|
||||
iw.close();
|
||||
dir.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,45 +82,6 @@ public class TestTermVectors extends LuceneTestCase {
|
|||
directory = null;
|
||||
}
|
||||
|
||||
// In a single doc, for the same field, mix the term
|
||||
// vectors up
|
||||
public void testMixedVectrosVectors() throws IOException {
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random(), directory,
|
||||
newIndexWriterConfig(TEST_VERSION_CURRENT,
|
||||
new MockAnalyzer(random(), MockTokenizer.SIMPLE, true)).setOpenMode(OpenMode.CREATE));
|
||||
Document doc = new Document();
|
||||
|
||||
FieldType ft2 = new FieldType(TextField.TYPE_STORED);
|
||||
ft2.setStoreTermVectors(true);
|
||||
|
||||
FieldType ft3 = new FieldType(TextField.TYPE_STORED);
|
||||
ft3.setStoreTermVectors(true);
|
||||
ft3.setStoreTermVectorPositions(true);
|
||||
|
||||
FieldType ft4 = new FieldType(TextField.TYPE_STORED);
|
||||
ft4.setStoreTermVectors(true);
|
||||
ft4.setStoreTermVectorOffsets(true);
|
||||
|
||||
FieldType ft5 = new FieldType(TextField.TYPE_STORED);
|
||||
ft5.setStoreTermVectors(true);
|
||||
ft5.setStoreTermVectorOffsets(true);
|
||||
ft5.setStoreTermVectorPositions(true);
|
||||
|
||||
doc.add(newTextField("field", "one", Field.Store.YES));
|
||||
doc.add(newField("field", "one", ft2));
|
||||
doc.add(newField("field", "one", ft3));
|
||||
doc.add(newField("field", "one", ft4));
|
||||
doc.add(newField("field", "one", ft5));
|
||||
try {
|
||||
writer.addDocument(doc);
|
||||
fail("should have hit exception");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
assertEquals("all instances of a given field name must have the same term vectors settings (storeTermVectors changed for field=\"field\")",
|
||||
iae.getMessage());
|
||||
}
|
||||
writer.shutdown();
|
||||
}
|
||||
|
||||
private IndexWriter createWriter(Directory dir) throws IOException {
|
||||
return new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT,
|
||||
new MockAnalyzer(random())).setMaxBufferedDocs(2));
|
||||
|
|
Loading…
Reference in New Issue