Example usage for org.apache.lucene.index LeafReader getTermVectors

List of usage examples for org.apache.lucene.index LeafReader getTermVectors

Introduction

In this page you can find the example usage for org.apache.lucene.index LeafReader getTermVectors.

Prototype

public abstract Fields getTermVectors(int docID) throws IOException;

Source Link

Document

Retrieve term vectors for this document, or null if term vectors were not indexed.

Usage

From source file:org.elasticsearch.xpack.core.security.authz.accesscontrol.FieldSubsetReaderTests.java

License:Open Source License

/**
 * test filtering an index with no fields
 *//*from  w  ww . j  av  a2s. c om*/
public void testEmpty() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(null);
    IndexWriter iw = new IndexWriter(dir, iwc);
    iw.addDocument(new Document());

    // open reader
    DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw),
            new CharacterRunAutomaton(Automata.makeString("fieldA")));

    // see no fields
    LeafReader segmentReader = ir.leaves().get(0).reader();
    Set<String> seenFields = new HashSet<>();
    for (FieldInfo info : segmentReader.getFieldInfos()) {
        seenFields.add(info.name);
    }
    assertEquals(0, seenFields.size());
    assertNull(segmentReader.terms("foo"));

    // see no vectors
    assertNull(segmentReader.getTermVectors(0));

    // see no stored fields
    Document document = segmentReader.document(0);
    assertEquals(0, document.getFields().size());

    TestUtil.checkReader(ir);
    IOUtils.close(ir, iw, dir);
}