use of org.apache.lucene.document.FieldType in project lucene-solr by apache.
the class TestTermVectors method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
directory = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), directory, newIndexWriterConfig(new MockAnalyzer(random(), MockTokenizer.SIMPLE, true)).setMergePolicy(newLogMergePolicy()));
//writer.infoStream = System.out;
for (int i = 0; i < 1000; i++) {
Document doc = new Document();
FieldType ft = new FieldType(TextField.TYPE_STORED);
int mod3 = i % 3;
int mod2 = i % 2;
if (mod2 == 0 && mod3 == 0) {
ft.setStoreTermVectors(true);
ft.setStoreTermVectorOffsets(true);
ft.setStoreTermVectorPositions(true);
} else if (mod2 == 0) {
ft.setStoreTermVectors(true);
ft.setStoreTermVectorPositions(true);
} else if (mod3 == 0) {
ft.setStoreTermVectors(true);
ft.setStoreTermVectorOffsets(true);
} else {
ft.setStoreTermVectors(true);
}
doc.add(new Field("field", English.intToEnglish(i), ft));
//test no term vectors too
doc.add(new TextField("noTV", English.intToEnglish(i), Field.Store.YES));
writer.addDocument(doc);
}
reader = writer.getReader();
writer.close();
}
use of org.apache.lucene.document.FieldType in project lucene-solr by apache.
the class TestTermVectorsReader method testIllegalVectorPayloadsWithoutVectors.
public void testIllegalVectorPayloadsWithoutVectors() throws Exception {
Directory dir = newDirectory();
MockAnalyzer a = new MockAnalyzer(random());
a.setEnableChecks(false);
RandomIndexWriter w = new RandomIndexWriter(random(), dir, a);
FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
ft.setStoreTermVectors(false);
ft.setStoreTermVectorPayloads(true);
Document doc = new Document();
doc.add(new Field("field", "value", ft));
IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
w.addDocument(doc);
});
assertEquals("cannot index term vector payloads when term vectors are not indexed (field=\"field\")", expected.getMessage());
w.close();
dir.close();
}
use of org.apache.lucene.document.FieldType in project lucene-solr by apache.
the class TestTermVectorsReader method testIllegalOffsetsWithoutVectors.
public void testIllegalOffsetsWithoutVectors() throws Exception {
Directory dir = newDirectory();
MockAnalyzer a = new MockAnalyzer(random());
a.setEnableChecks(false);
RandomIndexWriter w = new RandomIndexWriter(random(), dir, a);
FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
ft.setStoreTermVectors(false);
ft.setStoreTermVectorOffsets(true);
Document doc = new Document();
doc.add(new Field("field", "value", ft));
IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
w.addDocument(doc);
});
assertEquals("cannot index term vector offsets when term vectors are not indexed (field=\"field\")", expected.getMessage());
w.close();
dir.close();
}
use of org.apache.lucene.document.FieldType in project lucene-solr by apache.
the class TestTermVectorsReader method testIllegalVectorPayloadsWithoutIndexed.
public void testIllegalVectorPayloadsWithoutIndexed() throws Exception {
Directory dir = newDirectory();
MockAnalyzer a = new MockAnalyzer(random());
a.setEnableChecks(false);
RandomIndexWriter w = new RandomIndexWriter(random(), dir, a);
FieldType ft = new FieldType(StoredField.TYPE);
ft.setStoreTermVectorPayloads(true);
Document doc = new Document();
doc.add(new Field("field", "value", ft));
IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
w.addDocument(doc);
});
assertEquals("cannot store term vector payloads for a field that is not indexed (field=\"field\")", expected.getMessage());
w.close();
dir.close();
}
use of org.apache.lucene.document.FieldType in project lucene-solr by apache.
the class TestTermVectorsReader method testIllegalVectorOffsetsWithoutIndexed.
public void testIllegalVectorOffsetsWithoutIndexed() throws Exception {
Directory dir = newDirectory();
MockAnalyzer a = new MockAnalyzer(random());
a.setEnableChecks(false);
RandomIndexWriter w = new RandomIndexWriter(random(), dir, a);
FieldType ft = new FieldType(StoredField.TYPE);
ft.setStoreTermVectorOffsets(true);
Document doc = new Document();
doc.add(new Field("field", "value", ft));
IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
w.addDocument(doc);
});
assertEquals("cannot store term vector offsets for a field that is not indexed (field=\"field\")", expected.getMessage());
w.close();
dir.close();
}
Aggregations