Example usage for org.apache.lucene.index IndexWriter deleteAll

List of usage examples for org.apache.lucene.index IndexWriter deleteAll

Introduction

In this page you can find the example usage for org.apache.lucene.index IndexWriter deleteAll.

Prototype

@SuppressWarnings("try")
public long deleteAll() throws IOException 

Source Link

Document

Delete all documents in the index.

Usage

From source file:uk.gov.nationalarchives.discovery.taxonomy.common.service.impl.TrainingSetServiceImpl.java

License:Mozilla Public License

@Override
public void indexTrainingSet() {
    logger.info("index training set");
    IndexWriter writer = null;
    try {//ww  w. j a v a 2 s  .  c  o  m
        writer = new IndexWriter(trainingSetDirectory, new IndexWriterConfig(trainingSetAnalyser));

        writer.deleteAll();

        Iterator<TrainingDocument> trainingDocumentIterator = trainingDocumentRepository.findAll().iterator();

        while (trainingDocumentIterator.hasNext()) {
            TrainingDocument trainingDocument = trainingDocumentIterator.next();
            trainingSetRepository.indexTrainingSetDocument(trainingDocument, writer);

        }
        writer.commit();
    } catch (IOException e) {
        throw new TaxonomyException(TaxonomyErrorType.LUCENE_IO_EXCEPTION, e);
    } finally {
        LuceneHelperTools.closeCloseableObjectQuietly(writer);
    }
    logger.info("index training set ended");

}