Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-5611: simplify the default indexing chain

Michael McCandlessf5de5d01e810
diff --cc lucene/CHANGES.txt
index 9f97dd2d5ef,9f97dd2d5ef..0faf7cfec66
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@@ -77,6 -77,6 +77,13 @@@ Othe
======================= Lucene 4.9.0 =======================
++Changes in Runtime Behavior
++
++* LUCENE-5611: Changing the term vector options for multiple field
++ instances by the same name in one document is not longer accepted;
++ IndexWriter will now throw IllegalArgumentException. (Robert Muir,
++ Mike McCandless)
++
New Features
* LUCENE-5610: Add Terms.getMin and Terms.getMax to get the lowest and
@@@ -93,6 -93,6 +100,13 @@@ API Change
* LUCENE-5621: Deprecate IndexOutput.flush: this is not used by Lucene.
(Robert Muir)
++* LUCENE-5611: Simplified Lucene's default indexing chain / APIs.
++ AttributeSource/TokenStream.getAttribute now returns null if the
++ attribute is not present (previously it threw
++ IllegalArgumentException). StoredFieldsWriter.startDocument no
++ longer receives the number of fields that will be added (Robert
++ Muir, Mike McCandless)
++
Optimizations
* LUCENE-5603: hunspell stemmer more efficiently strips prefixes
diff --cc lucene/core/src/java/org/apache/lucene/document/Field.java
index b1576913e2f,4b71384b607..7c06e284690
--- a/lucene/core/src/java/org/apache/lucene/document/Field.java
+++ b/lucene/core/src/java/org/apache/lucene/document/Field.java
@@@ -244,11 -244,25 +244,6 @@@ public class Field implements Indexable
throw new IllegalArgumentException("it doesn't make sense to have a field that "
+ "is neither indexed nor stored");
}
- if (!type.indexed() && (type.storeTermVectors())) {
- throw new IllegalArgumentException("cannot store term vector information "
- + "for a field that is not indexed");
- if (!type.indexed()) {
- if (type.storeTermVectors()) {
- throw new IllegalArgumentException("cannot store term vectors "
- + "for a field that is not indexed (field=\"" + name + "\")");
- }
- if (type.storeTermVectorPositions()) {
- throw new IllegalArgumentException("cannot store term vector positions "
- + "for a field that is not indexed (field=\"" + name + "\")");
- }
- if (type.storeTermVectorOffsets()) {
- throw new IllegalArgumentException("cannot store term vector offsets "
- + "for a field that is not indexed (field=\"" + name + "\")");
- }
- if (type.storeTermVectorPayloads()) {
- throw new IllegalArgumentException("cannot store term vector payloads "
- + "for a field that is not indexed (field=\"" + name + "\")");
- }
-- }
--
this.type = type;
this.name = name;
this.fieldsData = value;
diff --cc lucene/core/src/test/org/apache/lucene/document/TestDocument.java
index 80474b8da14,80474b8da14..dd6876ee033
--- a/lucene/core/src/test/org/apache/lucene/document/TestDocument.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestDocument.java
@@@ -131,7 -131,7 +131,7 @@@ public class TestDocument extends Lucen
assertEquals(0, doc.getFields().size());
}
-- public void testConstructorExceptions() {
++ public void testConstructorExceptions() throws Exception {
FieldType ft = new FieldType();
ft.setStored(true);
new Field("name", "value", ft); // okay
@@@ -142,16 -142,16 +142,23 @@@
} catch (IllegalArgumentException e) {
// expected exception
}
++
++ Directory dir = newDirectory();
++ RandomIndexWriter w = new RandomIndexWriter(random(), dir);
new Field("name", "value", ft); // okay
++ Document doc = new Document();
++ FieldType ft2 = new FieldType();
++ ft2.setStored(true);
++ ft2.setStoreTermVectors(true);
++ doc.add(new Field("name", "value", ft2));
try {
-- FieldType ft2 = new FieldType();
-- ft2.setStored(true);
-- ft2.setStoreTermVectors(true);
-- new Field("name", "value", ft2);
++ w.addDocument(doc);
fail();
} catch (IllegalArgumentException e) {
// expected exception
}
++ w.close();
++ dir.close();
}
public void testClearDocument() {
diff --cc lucene/core/src/test/org/apache/lucene/index/TestTermVectorsReader.java
index 291a9517928,f18793f2951..944b15e9dd8
--- a/lucene/core/src/test/org/apache/lucene/index/TestTermVectorsReader.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestTermVectorsReader.java
@@@ -386,6 -390,59 +390,67 @@@ public class TestTermVectorsReader exte
assertEquals("cannot index term vector payloads when term vectors are not indexed (field=\"field\")", iae.getMessage());
}
+ ft = new FieldType(TextField.TYPE_NOT_STORED);
+ ft.setStoreTermVectors(true);
+ 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 without term vector positions (field=\"field\")", iae.getMessage());
+ }
+
+ ft = new FieldType(StoredField.TYPE);
+ ft.setStoreTermVectors(true);
++ doc = new Document();
++ doc.add(new Field("field", "value", ft));
+ try {
- new Field("field", "value", ft);
++ w.addDocument(doc);
+ fail("did not hit exception");
+ } catch (IllegalArgumentException iae) {
+ // Expected
+ assertEquals("cannot store term vectors for a field that is not indexed (field=\"field\")", iae.getMessage());
+ }
+
+ ft = new FieldType(StoredField.TYPE);
+ ft.setStoreTermVectorPositions(true);
++ doc = new Document();
++ doc.add(new Field("field", "value", ft));
+ try {
- new Field("field", "value", ft);
++ w.addDocument(doc);
+ fail("did not hit exception");
+ } catch (IllegalArgumentException iae) {
+ // Expected
+ assertEquals("cannot store term vector positions for a field that is not indexed (field=\"field\")", iae.getMessage());
+ }
+
+ ft = new FieldType(StoredField.TYPE);
+ ft.setStoreTermVectorOffsets(true);
++ doc = new Document();
++ doc.add(new Field("field", "value", ft));
+ try {
- new Field("field", "value", ft);
++ w.addDocument(doc);
+ fail("did not hit exception");
+ } catch (IllegalArgumentException iae) {
+ // Expected
+ assertEquals("cannot store term vector offsets for a field that is not indexed (field=\"field\")", iae.getMessage());
+ }
+
+ ft = new FieldType(StoredField.TYPE);
+ ft.setStoreTermVectorPayloads(true);
++ doc = new Document();
++ doc.add(new Field("field", "value", ft));
+ try {
- new Field("field", "value", ft);
++ w.addDocument(doc);
+ fail("did not hit exception");
+ } catch (IllegalArgumentException iae) {
+ // Expected
+ assertEquals("cannot store term vector payloads for a field that is not indexed (field=\"field\")", iae.getMessage());
+ }
+
w.shutdown();
dir.close();
diff --cc lucene/test-framework/src/java/org/apache/lucene/analysis/ValidatingTokenFilter.java
index bd406430246,88218fb1ca0..6c7c725e9f7
--- a/lucene/test-framework/src/java/org/apache/lucene/analysis/ValidatingTokenFilter.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/analysis/ValidatingTokenFilter.java
@@@ -25,7 -25,7 +25,6 @@@ import org.apache.lucene.analysis.token
import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
import org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute;
--import org.apache.lucene.util.Attribute;
// TODO: rename to OffsetsXXXTF? ie we only validate
// offsets (now anyway...)