}
public void testIllegalIndexableField() throws Exception {
Directory dir = newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random(), dir);
FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
ft.setStoreTermVectors(true);
ft.setStoreTermVectorPayloads(true);
Document doc = new Document();
doc.add(new Field("field", "value", ft));
try {
w.addDocument(doc);
fail("did not hit exception");
} catch (IllegalArgumentException iae) {
// Expected
assertEquals("cannot index term vector payloads without term vector positions (field=\"field\")", iae.getMessage());
}
ft = new FieldType(TextField.TYPE_NOT_STORED);
ft.setStoreTermVectors(false);
ft.setStoreTermVectorOffsets(true);
doc = new Document();
doc.add(new Field("field", "value", ft));
try {
w.addDocument(doc);
fail("did not hit exception");
} catch (IllegalArgumentException iae) {
// Expected
assertEquals("cannot index term vector offsets when term vectors are not indexed (field=\"field\")", iae.getMessage());
}
ft = new FieldType(TextField.TYPE_NOT_STORED);
ft.setStoreTermVectors(false);
ft.setStoreTermVectorPositions(true);
doc = new Document();
doc.add(new Field("field", "value", ft));
try {
w.addDocument(doc);
fail("did not hit exception");
} catch (IllegalArgumentException iae) {
// Expected
assertEquals("cannot index term vector positions when term vectors are not indexed (field=\"field\")", iae.getMessage());
}
ft = new FieldType(TextField.TYPE_NOT_STORED);
ft.setStoreTermVectors(false);
ft.setStoreTermVectorPayloads(true);
doc = new Document();
doc.add(new Field("field", "value", ft));
try {
w.addDocument(doc);
fail("did not hit exception");