use of org.apache.lucene.document.SortedDocValuesField in project lucene-solr by apache.
the class TestDocValuesIndexing method testTypeChangeViaAddIndexesIR2.
public void testTypeChangeViaAddIndexesIR2() 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();
Directory dir2 = newDirectory();
conf = newIndexWriterConfig(new MockAnalyzer(random()));
IndexWriter writer2 = new IndexWriter(dir2, conf);
DirectoryReader reader = DirectoryReader.open(dir);
TestUtil.addIndexesSlowly(writer2, reader);
reader.close();
Document doc2 = new Document();
doc2.add(new SortedDocValuesField("dv", new BytesRef("foo")));
expectThrows(IllegalArgumentException.class, () -> {
writer2.addDocument(doc2);
});
writer2.close();
dir2.close();
dir.close();
}
use of org.apache.lucene.document.SortedDocValuesField in project lucene-solr by apache.
the class TestDocValuesIndexing method testMixedTypesDifferentSegments.
// Two documents across segments
public void testMixedTypesDifferentSegments() 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);
w.commit();
Document doc2 = new Document();
doc2.add(new SortedDocValuesField("foo", new BytesRef("hello")));
expectThrows(IllegalArgumentException.class, () -> {
w.addDocument(doc2);
});
w.close();
dir.close();
}
use of org.apache.lucene.document.SortedDocValuesField in project lucene-solr by apache.
the class TestDocValuesIndexing method testDifferentTypedDocValuesField2.
public void testDifferentTypedDocValuesField2() throws Exception {
Directory d = newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random(), d);
Document doc = new Document();
doc.add(new NumericDocValuesField("field", 17));
w.addDocument(doc);
// Index doc values are single-valued so we should not
// be able to add same field more than once:
doc.add(new SortedDocValuesField("field", new BytesRef("hello")));
expectThrows(IllegalArgumentException.class, () -> {
w.addDocument(doc);
});
DirectoryReader r = w.getReader();
NumericDocValues values = DocValues.getNumeric(getOnlyLeafReader(r), "field");
assertEquals(0, values.nextDoc());
assertEquals(17, values.longValue());
r.close();
w.close();
d.close();
}
use of org.apache.lucene.document.SortedDocValuesField in project lucene-solr by apache.
the class TestDocValuesIndexing method testIllegalTypeChange.
public void testIllegalTypeChange() 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);
Document doc2 = new Document();
doc2.add(new SortedDocValuesField("dv", new BytesRef("foo")));
expectThrows(IllegalArgumentException.class, () -> {
writer.addDocument(doc2);
});
IndexReader ir = writer.getReader();
assertEquals(1, ir.numDocs());
ir.close();
writer.close();
dir.close();
}
use of org.apache.lucene.document.SortedDocValuesField in project lucene-solr by apache.
the class TestDocValuesIndexing method testTypeChangeViaAddIndexes.
public void testTypeChangeViaAddIndexes() 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();
Directory dir2 = newDirectory();
conf = newIndexWriterConfig(new MockAnalyzer(random()));
IndexWriter writer2 = new IndexWriter(dir2, conf);
doc = new Document();
doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
writer2.addDocument(doc);
expectThrows(IllegalArgumentException.class, () -> {
writer2.addIndexes(dir);
});
writer2.close();
dir.close();
dir2.close();
}
Aggregations