use of org.apache.lucene.document.SortedDocValuesField in project lucene-solr by apache.
the class TestDocValues method testSortedField.
/**
* field with sorted docvalues
*/
public void testSortedField() throws Exception {
Directory dir = newDirectory();
IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(null));
Document doc = new Document();
doc.add(new SortedDocValuesField("foo", new BytesRef("bar")));
iw.addDocument(doc);
DirectoryReader dr = DirectoryReader.open(iw);
LeafReader r = getOnlyLeafReader(dr);
// ok
assertNotNull(DocValues.getBinary(r, "foo"));
assertNotNull(DocValues.getSorted(r, "foo"));
assertNotNull(DocValues.getSortedSet(r, "foo"));
// errors
expectThrows(IllegalStateException.class, () -> {
DocValues.getNumeric(r, "foo");
});
expectThrows(IllegalStateException.class, () -> {
DocValues.getSortedNumeric(r, "foo");
});
dr.close();
iw.close();
dir.close();
}
use of org.apache.lucene.document.SortedDocValuesField in project lucene-solr by apache.
the class TestDocValuesIndexing method testTypeChangeAfterCommitAndDeleteAll.
public void testTypeChangeAfterCommitAndDeleteAll() 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.commit();
writer.deleteAll();
doc = new Document();
doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
writer.addDocument(doc);
writer.close();
dir.close();
}
use of org.apache.lucene.document.SortedDocValuesField 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.SortedDocValuesField 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.SortedDocValuesField 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();
}
Aggregations