Search in sources :

Example 1 with IOSupplier

use of org.apache.lucene.util.IOSupplier in project OpenSearch by opensearch-project.

the class FsRepositoryTests method deleteRandomDoc.

private void deleteRandomDoc(Directory directory) throws IOException {
    try (IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random(), new MockAnalyzer(random())).setCodec(TestUtil.getDefaultCodec()).setMergePolicy(new FilterMergePolicy(NoMergePolicy.INSTANCE) {

        @Override
        public boolean keepFullyDeletedSegment(IOSupplier<CodecReader> readerIOSupplier) {
            return true;
        }
    }))) {
        final int numDocs = writer.getDocStats().numDocs;
        writer.deleteDocuments(new Term("id", "" + randomIntBetween(0, writer.getDocStats().numDocs - 1)));
        writer.commit();
        assertEquals(writer.getDocStats().numDocs, numDocs - 1);
    }
}
Also used : FilterMergePolicy(org.apache.lucene.index.FilterMergePolicy) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) IndexWriter(org.apache.lucene.index.IndexWriter) IOSupplier(org.apache.lucene.util.IOSupplier) Term(org.apache.lucene.index.Term)

Aggregations

MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)1 FilterMergePolicy (org.apache.lucene.index.FilterMergePolicy)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 Term (org.apache.lucene.index.Term)1 IOSupplier (org.apache.lucene.util.IOSupplier)1