fix exc messages

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1510617 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2013-08-05 17:35:04 +00:00
parent e021a1a7b3
commit acaa4eab02
2 changed files with 68 additions and 8 deletions

View File

@ -76,31 +76,31 @@ final class TermVectorsConsumerPerField extends TermsHashConsumerPerField {
doVectorPayloads |= field.fieldType().storeTermVectorPayloads();
} else if (field.fieldType().storeTermVectorPayloads()) {
// TODO: move this check somewhere else, and impl the other missing ones
throw new IllegalArgumentException("cannot index term vector payloads for field: " + field + " without term vector positions");
throw new IllegalArgumentException("cannot index term vector payloads without term vector positions (field=\"" + field.name() + "\")");
}
} else {
if (field.fieldType().storeTermVectorOffsets()) {
throw new IllegalArgumentException("cannot index term vector offsets when term vectors are not indexed (field=\"" + field.name());
throw new IllegalArgumentException("cannot index term vector offsets when term vectors are not indexed (field=\"" + field.name() + "\")");
}
if (field.fieldType().storeTermVectorPositions()) {
throw new IllegalArgumentException("cannot index term vector positions when term vectors are not indexed (field=\"" + field.name());
throw new IllegalArgumentException("cannot index term vector positions when term vectors are not indexed (field=\"" + field.name() + "\")");
}
if (field.fieldType().storeTermVectorPayloads()) {
throw new IllegalArgumentException("cannot index term vector payloads when term vectors are not indexed (field=\"" + field.name());
throw new IllegalArgumentException("cannot index term vector payloads when term vectors are not indexed (field=\"" + field.name() + "\")");
}
}
} else {
if (field.fieldType().storeTermVectors()) {
throw new IllegalArgumentException("cannot index term vectors when field is not indexed (field=\"" + field.name());
throw new IllegalArgumentException("cannot index term vectors when field is not indexed (field=\"" + field.name() + "\")");
}
if (field.fieldType().storeTermVectorOffsets()) {
throw new IllegalArgumentException("cannot index term vector offsets when field is not indexed (field=\"" + field.name());
throw new IllegalArgumentException("cannot index term vector offsets when field is not indexed (field=\"" + field.name() + "\")");
}
if (field.fieldType().storeTermVectorPositions()) {
throw new IllegalArgumentException("cannot index term vector positions when field is not indexed (field=\"" + field.name());
throw new IllegalArgumentException("cannot index term vector positions when field is not indexed (field=\"" + field.name() + "\")");
}
if (field.fieldType().storeTermVectorPayloads()) {
throw new IllegalArgumentException("cannot index term vector payloads when field is not indexed (field=\"" + field.name());
throw new IllegalArgumentException("cannot index term vector payloads when field is not indexed (field=\"" + field.name() + "\")");
}
}
}

View File

@ -331,4 +331,64 @@ public class TestTermVectorsReader extends LuceneTestCase {
}
reader.close();
}
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");
} catch (IllegalArgumentException iae) {
// Expected
assertEquals("cannot index term vector payloads when term vectors are not indexed (field=\"field\")", iae.getMessage());
}
w.close();
dir.close();
}
}