throw IllegalArgumentException if you try to index term vector offsets/positions when term vectors are not indexed, or if you try to index term vectors when field is not index

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1372025 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2012-08-11 20:51:34 +00:00
parent 1397cbd2de
commit 6bc248b017
5 changed files with 40 additions and 16 deletions

View File

@ -206,6 +206,7 @@ public class TestPerfTasksLogic extends BenchmarkTestCase {
// 1. alg definition (required in every "logic" test) // 1. alg definition (required in every "logic" test)
String algLines[] = { String algLines[] = {
"doc.stored=true",//doc storage is required in order to have text to highlight "doc.stored=true",//doc storage is required in order to have text to highlight
"doc.term.vector=true",
"doc.term.vector.offsets=true", "doc.term.vector.offsets=true",
"content.source=org.apache.lucene.benchmark.byTask.feeds.LineDocSource", "content.source=org.apache.lucene.benchmark.byTask.feeds.LineDocSource",
"docs.file=" + getReuters20LinesFile(), "docs.file=" + getReuters20LinesFile(),

View File

@ -67,15 +67,40 @@ final class TermVectorsConsumerPerField extends TermsHashConsumerPerField {
for(int i=0;i<count;i++) { for(int i=0;i<count;i++) {
IndexableField field = fields[i]; IndexableField field = fields[i];
if (field.fieldType().indexed() && field.fieldType().storeTermVectors()) { if (field.fieldType().indexed()) {
doVectors = true; if (field.fieldType().storeTermVectors()) {
doVectorPositions |= field.fieldType().storeTermVectorPositions(); doVectors = true;
doVectorOffsets |= field.fieldType().storeTermVectorOffsets(); doVectorPositions |= field.fieldType().storeTermVectorPositions();
if (doVectorPositions) { doVectorOffsets |= field.fieldType().storeTermVectorOffsets();
doVectorPayloads |= field.fieldType().storeTermVectorPayloads(); if (doVectorPositions) {
} else if (field.fieldType().storeTermVectorPayloads()) { doVectorPayloads |= field.fieldType().storeTermVectorPayloads();
// TODO: move this check somewhere else, and impl the other missing ones } else if (field.fieldType().storeTermVectorPayloads()) {
throw new IllegalArgumentException("cannot index term vector payloads for field: " + field + " without term vector positions"); // 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");
}
} else {
if (field.fieldType().storeTermVectorOffsets()) {
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());
}
if (field.fieldType().storeTermVectorPayloads()) {
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());
}
if (field.fieldType().storeTermVectorOffsets()) {
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());
}
if (field.fieldType().storeTermVectorPayloads()) {
throw new IllegalArgumentException("cannot index term vector payloads when field is not indexed (field=\"" + field.name());
} }
} }
} }

View File

@ -526,8 +526,6 @@ public class TestIndexWriterOnDiskFull extends LuceneTestCase {
dir.setMaxSizeInBytes(Math.max(1, dir.getRecomputedActualSizeInBytes())); dir.setMaxSizeInBytes(Math.max(1, dir.getRecomputedActualSizeInBytes()));
final Document doc = new Document(); final Document doc = new Document();
FieldType customType = new FieldType(TextField.TYPE_STORED); FieldType customType = new FieldType(TextField.TYPE_STORED);
customType.setStoreTermVectorPositions(true);
customType.setStoreTermVectorOffsets(true);
doc.add(newField("field", "aaa bbb ccc ddd eee fff ggg hhh iii jjj", customType)); doc.add(newField("field", "aaa bbb ccc ddd eee fff ggg hhh iii jjj", customType));
try { try {
writer.addDocument(doc); writer.addDocument(doc);

View File

@ -60,22 +60,22 @@ public class TestIndexableField extends LuceneTestCase {
@Override @Override
public boolean storeTermVectors() { public boolean storeTermVectors() {
return counter % 2 == 1 && counter % 10 != 9; return indexed() && counter % 2 == 1 && counter % 10 != 9;
} }
@Override @Override
public boolean storeTermVectorOffsets() { public boolean storeTermVectorOffsets() {
return counter % 2 == 1 && counter % 10 != 9; return storeTermVectors() && counter % 10 != 9;
} }
@Override @Override
public boolean storeTermVectorPositions() { public boolean storeTermVectorPositions() {
return counter % 2 == 1 && counter % 10 != 9; return storeTermVectors() && counter % 10 != 9;
} }
@Override @Override
public boolean storeTermVectorPayloads() { public boolean storeTermVectorPayloads() {
return counter % 2 == 1 && counter % 10 != 9; return storeTermVectors() && counter % 10 != 9;
} }
@Override @Override

View File

@ -559,7 +559,7 @@
<field name="inStock" type="boolean" indexed="true" stored="true" /> <field name="inStock" type="boolean" indexed="true" stored="true" />
<field name="subword" type="subword" indexed="true" stored="true"/> <field name="subword" type="subword" indexed="true" stored="true"/>
<field name="subword_offsets" type="subword" indexed="true" stored="true" termOffsets="true"/> <field name="subword_offsets" type="subword" indexed="true" stored="true" termVectors="true" termOffsets="true"/>
<field name="numericsubword" type="numericsubword" indexed="true" stored="true"/> <field name="numericsubword" type="numericsubword" indexed="true" stored="true"/>
<field name="protectedsubword" type="protectedsubword" indexed="true" stored="true"/> <field name="protectedsubword" type="protectedsubword" indexed="true" stored="true"/>