diff src/goodjava/lucene/api/LuceneIndexWriter.java @ 1476:7d145095cc0b

lucene.logging check
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 19 Apr 2020 20:42:26 -0600
parents 5e3870618377
children f848d40b3b07
line wrap: on
line diff
--- a/src/goodjava/lucene/api/LuceneIndexWriter.java	Sat Apr 18 11:02:18 2020 -0600
+++ b/src/goodjava/lucene/api/LuceneIndexWriter.java	Sun Apr 19 20:42:26 2020 -0600
@@ -19,13 +19,17 @@
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.CheckIndex;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.Version;
+import goodjava.logging.Logger;
+import goodjava.logging.LoggerFactory;
 
 
 public final class LuceneIndexWriter implements GoodIndexWriter {
+	private static final Logger logger = LoggerFactory.getLogger(LuceneIndexWriter.class);
 	private final FieldAnalyzer fieldAnalyzer = new FieldAnalyzer();
 	public final Version luceneVersion;
 	public final IndexWriterConfig luceneConfig;
@@ -180,4 +184,10 @@
 	public IndexReader openReader() throws IOException {
 		return DirectoryReader.open(luceneWriter.getDirectory());
 	}
+
+	public void check() throws IOException {
+		CheckIndex.Status status = new CheckIndex(luceneWriter.getDirectory()).checkIndex();
+		if( !status.clean )
+			logger.error("index not clean");
+	}
 }