use of org.apache.lucene.document.NumericDocValuesField in project lucene-solr by apache.
the class TestDocValuesIndexing method testMixedTypesDifferentDocuments.
// Two documents with same field as different types:
public void testMixedTypesDifferentDocuments() throws Exception {
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
Document doc = new Document();
doc.add(new NumericDocValuesField("foo", 0));
w.addDocument(doc);
Document doc2 = new Document();
doc2.add(new SortedDocValuesField("foo", new BytesRef("hello")));
expectThrows(IllegalArgumentException.class, () -> {
w.addDocument(doc2);
});
IndexReader ir = w.getReader();
assertEquals(1, ir.numDocs());
ir.close();
w.close();
dir.close();
}
use of org.apache.lucene.document.NumericDocValuesField in project lucene-solr by apache.
the class TestDocValuesIndexing method testMultiValuedDocValuesField.
public void testMultiValuedDocValuesField() throws Exception {
Directory d = newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random(), d);
Document doc = new Document();
Field f = new NumericDocValuesField("field", 17);
doc.add(f);
// add the doc
w.addDocument(doc);
// Index doc values are single-valued so we should not
// be able to add same field more than once:
doc.add(f);
expectThrows(IllegalArgumentException.class, () -> {
w.addDocument(doc);
fail("didn't hit expected exception");
});
DirectoryReader r = w.getReader();
w.close();
NumericDocValues values = DocValues.getNumeric(getOnlyLeafReader(r), "field");
assertEquals(0, values.nextDoc());
assertEquals(17, values.longValue());
r.close();
d.close();
}
use of org.apache.lucene.document.NumericDocValuesField in project lucene-solr by apache.
the class TestDocValuesIndexing method testTypeChangeAfterOpenCreate.
public void testTypeChangeAfterOpenCreate() throws Exception {
Directory dir = newDirectory();
IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.add(new NumericDocValuesField("dv", 0L));
writer.addDocument(doc);
writer.close();
conf = newIndexWriterConfig(new MockAnalyzer(random()));
conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
writer = new IndexWriter(dir, conf);
doc = new Document();
doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
writer.addDocument(doc);
writer.close();
dir.close();
}
use of org.apache.lucene.document.NumericDocValuesField in project lucene-solr by apache.
the class TestDocValuesIndexing method testIllegalTypeChangeAcrossSegments.
public void testIllegalTypeChangeAcrossSegments() throws Exception {
Directory dir = newDirectory();
IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.add(new NumericDocValuesField("dv", 0L));
writer.addDocument(doc);
writer.close();
conf = newIndexWriterConfig(new MockAnalyzer(random()));
IndexWriter writer2 = new IndexWriter(dir, conf);
Document doc2 = new Document();
doc2.add(new SortedDocValuesField("dv", new BytesRef("foo")));
expectThrows(IllegalArgumentException.class, () -> {
writer2.addDocument(doc2);
});
writer2.close();
dir.close();
}
use of org.apache.lucene.document.NumericDocValuesField in project lucene-solr by apache.
the class TestDocValuesIndexing method testSameFieldNameForPostingAndDocValue.
public void testSameFieldNameForPostingAndDocValue() throws Exception {
// LUCENE-5192: FieldInfos.Builder neglected to update
// globalFieldNumbers.docValuesType map if the field existed, resulting in
// potentially adding the same field with different DV types.
Directory dir = newDirectory();
IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.add(new StringField("f", "mock-value", Store.NO));
doc.add(new NumericDocValuesField("f", 5));
writer.addDocument(doc);
writer.commit();
Document doc2 = new Document();
doc2.add(new BinaryDocValuesField("f", new BytesRef("mock")));
expectThrows(IllegalArgumentException.class, () -> {
writer.addDocument(doc2);
});
writer.rollback();
dir.close();
}
Aggregations